X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/98ab3c1ffb6cbc851ec73c73a4310cbbbca2a6ce..refs/pull/2791/head:/app/Http/Controllers/BookshelfController.php diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index c882ca7c3..b4795db09 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -1,8 +1,10 @@ bookshelfRepo = $bookshelfRepo; $this->entityContextManager = $entityContextManager; $this->imageRepo = $imageRepo; - parent::__construct(); } /** @@ -35,7 +33,7 @@ class BookshelfController extends Controller */ public function index() { - $view = setting()->getForCurrentUser('bookshelves_view_type', config('app.views.bookshelves', 'grid')); + $view = setting()->getForCurrentUser('bookshelves_view_type'); $sort = setting()->getForCurrentUser('bookshelves_sort', 'name'); $order = setting()->getForCurrentUser('bookshelves_sort_order', 'asc'); $sortOptions = [ @@ -85,14 +83,13 @@ class BookshelfController extends Controller $this->validate($request, [ 'name' => 'required|string|max:255', 'description' => 'string|max:1000', - 'image' => $this->getImageValidationRules(), + 'image' => 'nullable|' . $this->getImageValidationRules(), ]); $bookIds = explode(',', $request->get('books', '')); $shelf = $this->bookshelfRepo->create($request->all(), $bookIds); $this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null)); - Activity::add($shelf, 'bookshelf_create'); return redirect($shelf->getUrl()); } @@ -105,13 +102,26 @@ class BookshelfController extends Controller $shelf = $this->bookshelfRepo->getBySlug($slug); $this->checkOwnablePermission('book-view', $shelf); - Views::add($shelf); + $sort = setting()->getForCurrentUser('shelf_books_sort', 'default'); + $order = setting()->getForCurrentUser('shelf_books_sort_order', 'asc'); + + $sortedVisibleShelfBooks = $shelf->visibleBooks()->get() + ->sortBy($sort === 'default' ? 'pivot.order' : $sort, SORT_REGULAR, $order === 'desc') + ->values() + ->all(); + + View::incrementFor($shelf); $this->entityContextManager->setShelfContext($shelf->id); + $view = setting()->getForCurrentUser('bookshelf_view_type'); $this->setPageTitle($shelf->getShortName()); return view('shelves.show', [ 'shelf' => $shelf, - 'activity' => Activity::entityActivity($shelf, 20, 1) + 'sortedVisibleShelfBooks' => $sortedVisibleShelfBooks, + 'view' => $view, + 'activity' => Activity::entityActivity($shelf, 20, 1), + 'order' => $order, + 'sort' => $sort ]); } @@ -146,7 +156,7 @@ class BookshelfController extends Controller $this->validate($request, [ 'name' => 'required|string|max:255', 'description' => 'string|max:1000', - 'image' => $this->imageRepo->getImageValidationRules(), + 'image' => 'nullable|' . $this->getImageValidationRules(), ]); @@ -154,7 +164,6 @@ class BookshelfController extends Controller $shelf = $this->bookshelfRepo->update($shelf, $request->all(), $bookIds); $resetCover = $request->has('image_reset'); $this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null), $resetCover); - Activity::add($shelf, 'bookshelf_update'); return redirect($shelf->getUrl()); } @@ -180,7 +189,6 @@ class BookshelfController extends Controller $shelf = $this->bookshelfRepo->getBySlug($slug); $this->checkOwnablePermission('bookshelf-delete', $shelf); - Activity::addMessage('bookshelf_delete', $shelf->name); $this->bookshelfRepo->destroy($shelf); return redirect('/shelves'); @@ -202,14 +210,12 @@ class BookshelfController extends Controller /** * Set the permissions for this bookshelf. */ - public function permissions(Request $request, string $slug) + public function permissions(Request $request, PermissionsUpdater $permissionsUpdater, string $slug) { $shelf = $this->bookshelfRepo->getBySlug($slug); $this->checkOwnablePermission('restrictions-manage', $shelf); - $restricted = $request->get('restricted') === 'true'; - $permissions = $request->filled('restrictions') ? collect($request->get('restrictions')) : null; - $this->bookshelfRepo->updatePermissions($shelf, $restricted, $permissions); + $permissionsUpdater->updateFromPermissionsForm($shelf, $request); $this->showSuccessNotification(trans('entities.shelves_permissions_updated')); return redirect($shelf->getUrl());