]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'feature/sort-shelf-books' of git://github.com/guillaumehanotel/BookStac...
authorDan Brown <redacted>
Sun, 21 Mar 2021 21:52:39 +0000 (21:52 +0000)
committerDan Brown <redacted>
Sun, 21 Mar 2021 21:52:39 +0000 (21:52 +0000)
app/Http/Controllers/BookshelfController.php
app/Http/Controllers/UserController.php
resources/views/shelves/show.blade.php

index 8574c1b48589970039ccf36aee51a4c85b0d3aaa..14bc9d94efc61e8704f8691b368b7d56799d1f50 100644 (file)
@@ -101,6 +101,15 @@ class BookshelfController extends Controller
         $shelf = $this->bookshelfRepo->getBySlug($slug);
         $this->checkOwnablePermission('book-view', $shelf);
 
+        $sort = setting()->getForCurrentUser('shelf_books_sort', 'name');
+        $order = setting()->getForCurrentUser('shelf_books_sort_order', 'asc');
+
+        $visibleShelfBooks = $shelf->visibleBooks()->get();
+        $sortedVisibleShelfBooks = $visibleShelfBooks
+            ->sortBy($sort, SORT_REGULAR, $order === 'desc')
+            ->values()
+            ->all();
+
         Views::add($shelf);
         $this->entityContextManager->setShelfContext($shelf->id);
         $view = setting()->getForCurrentUser('bookshelf_view_type');
@@ -108,8 +117,11 @@ class BookshelfController extends Controller
         $this->setPageTitle($shelf->getShortName());
         return view('shelves.show', [
             'shelf' => $shelf,
+            'sortedVisibleShelfBooks' => $sortedVisibleShelfBooks,
             'view' => $view,
-            'activity' => Activity::entityActivity($shelf, 20, 1)
+            'activity' => Activity::entityActivity($shelf, 20, 1),
+            'order' => $order,
+            'sort' => $sort
         ]);
     }
 
index d797552f12d9442d978c502c9402c8c4c371a768..59c6d6edfc90485c30cd1d97717b4cb39af6c9d9 100644 (file)
@@ -300,7 +300,7 @@ class UserController extends Controller
      */
     public function changeSort(Request $request, string $id, string $type)
     {
-        $validSortTypes = ['books', 'bookshelves'];
+        $validSortTypes = ['books', 'bookshelves', 'shelf_books'];
         if (!in_array($type, $validSortTypes)) {
             return redirect()->back(500);
         }
index 46432c1b92594372b196fdb35fec9951833fffa9..a7a55a4270bddd0ca91f69a66845e2a6a5b88472 100644 (file)
@@ -9,19 +9,30 @@
     </div>
 
     <main class="card content-wrap">
-        <h1 class="break-text">{{$shelf->name}}</h1>
+
+        <div class="grid half v-center">
+            <h1 class="break-text">{{$shelf->name}}</h1>
+            <div class="text-m-right my-m">
+                @include('partials.sort', ['options' => [
+                    'name' => trans('common.sort_name'),
+                    'created_at' => trans('common.sort_created_at'),
+                    'updated_at' => trans('common.sort_updated_at'),
+                ], 'order' => $order, 'sort' => $sort, 'type' => 'shelf_books'])
+            </div>
+        </div>
+
         <div class="book-content">
             <p class="text-muted">{!! nl2br(e($shelf->description)) !!}</p>
-            @if(count($shelf->visibleBooks) > 0)
+            @if(count($sortedVisibleShelfBooks) > 0)
                 @if($view === 'list')
                     <div class="entity-list">
-                        @foreach($shelf->visibleBooks as $book)
+                        @foreach($sortedVisibleShelfBooks as $book)
                             @include('books.list-item', ['book' => $book])
                         @endforeach
                     </div>
                 @else
                     <div class="grid third">
-                        @foreach($shelf->visibleBooks as $key => $book)
+                        @foreach($sortedVisibleShelfBooks as $key => $book)
                             @include('partials.entity-grid-item', ['entity' => $book])
                         @endforeach
                     </div>