Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function index()
'books' => $books,
'recents' => $recents,
'popular' => $popular,
'new' => $new,
'new' => $new,
'booksViewType' => $booksViewType
]);
}
Expand Down
23 changes: 23 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,27 @@ public function showProfilePage($id)
'assetCounts' => $assetCounts
]);
}

public function switchBookView($id, Request $request) {
$this->checkPermissionOr('users-manage', function () use ($id) {
return $this->currentUser->id == $id;
});
$viewType = $request->get('book_view_type');

if (!in_array($viewType, ['grid', 'list'])) {
$viewType = 'list';
}

$user = $this->user->findOrFail($id);
setting()->putUser($user, 'books_view_type', $viewType);

$previousUrl = url()->previous();
if (empty($previousUrl)) {
// if no previous URL, redirect to settings
return redirect("/settings/users/$id");
} else {
// redirect to the previous page.
return redirect($previousUrl);
}
}
}
1 change: 1 addition & 0 deletions resources/lang/en/entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
'books_sort_named' => 'Sort Book :bookName',
'books_sort_show_other' => 'Show Other Books',
'books_sort_save' => 'Save New Order',
'books_toggle_view' => 'Toggle Book View',

/**
* Chapters
Expand Down
7 changes: 6 additions & 1 deletion resources/views/books/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<div class="col-xs-1"></div>
<div class="col-xs-11 faded">
<div class="action-buttons">
<form action="{{ baseUrl("/settings/users/{$currentUser->id}/switch-book-view") }}" method="POST" class="inline">
{!! csrf_field() !!}
<input type="hidden" value="{{ $booksViewType === 'list'? 'grid' : 'list' }}" name="book_view_type">
<button type="submit" class="text-pos text-button"><i class="zmdi zmdi-wrap-text"></i>{{ trans('entities.books_toggle_view') }}</button>
</form>
@if($currentUser->can('book-create-all'))
<a href="{{ baseUrl("/books/create") }}" class="text-pos text-button"><i class="zmdi zmdi-plus"></i>{{ trans('entities.books_create') }}</a>
@endif
Expand Down Expand Up @@ -52,7 +57,7 @@
<hr>
@endforeach
{!! $books->render() !!}
@else
@else
<div class="row auto-clear">
@foreach($books as $key => $book)
@include('books/grid-item', ['book' => $book])
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
Route::get('/users', 'UserController@index');
Route::get('/users/create', 'UserController@create');
Route::get('/users/{id}/delete', 'UserController@delete');
Route::post('/users/{id}/switch-book-view', 'UserController@switchBookView');
Route::post('/users/create', 'UserController@store');
Route::get('/users/{id}', 'UserController@edit');
Route::put('/users/{id}', 'UserController@update');
Expand Down
23 changes: 22 additions & 1 deletion tests/Entity/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ public function test_book_sort_item_returns_book_content()
->see($firstChapter->name);
}

public function test_toggle_book_view()
{
$editor = $this->getEditor();
setting()->putUser($editor, 'books_view_type', 'grid');

$this->actingAs($editor)
->visit('/books')
->pageHasElement('.featured-image-container')
->submitForm('Toggle Book View')
// Check redirection.
->seePageIs('/books')
->pageNotHasElement('.featured-image-container');

$this->actingAs($editor)
->visit('/books')
->submitForm('Toggle Book View')
->seePageIs('/books')
->pageHasElement('.featured-image-container');

}

public function pageCreation($chapter)
{
$page = factory(Page::class)->make([
Expand Down Expand Up @@ -155,7 +176,7 @@ public function bookCreation()
->type($book->name, '#name')
->type($book->description, '#description')
->press('Save Book');

$expectedPattern = '/\/books\/my-first-book-[0-9a-zA-Z]{3}/';
$this->assertRegExp($expectedPattern, $this->currentUri, "Did not land on expected page [$expectedPattern].\n");

Expand Down
2 changes: 1 addition & 1 deletion tests/UserProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function test_books_view_is_list()
$this->actingAs($editor)
->visit('/books')
->pageNotHasElement('.featured-image-container')
->pageHasElement('.entity-list-item');
->pageHasElement('.content .entity-list-item');

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just made the test a little more specific.

}

public function test_books_view_is_grid()
Expand Down