]> 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)
1  2 
app/Http/Controllers/BookshelfController.php
app/Http/Controllers/UserController.php

index 8574c1b48589970039ccf36aee51a4c85b0d3aaa,6c090a26da999cecbe12f7482b1e872d548d7421..14bc9d94efc61e8704f8691b368b7d56799d1f50
@@@ -32,7 -32,7 +32,7 @@@ class BookshelfController extends Contr
       */
      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 = [
          $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', config('app.views.books'));
 +        $view = setting()->getForCurrentUser('bookshelf_view_type');
  
          $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,f3ee0315615cf07bb536b9d8ef0584d7c7899dfa..59c6d6edfc90485c30cd1d97717b4cb39af6c9d9
@@@ -5,13 -5,10 +5,13 @@@ use BookStack\Auth\Access\SocialAuthSer
  use BookStack\Auth\Access\UserInviteService;
  use BookStack\Auth\User;
  use BookStack\Auth\UserRepo;
 +use BookStack\Exceptions\ImageUploadException;
  use BookStack\Exceptions\UserUpdateException;
  use BookStack\Uploads\ImageRepo;
 +use Exception;
  use Illuminate\Http\Request;
  use Illuminate\Support\Str;
 +use Illuminate\Validation\ValidationException;
  
  class UserController extends Controller
  {
@@@ -64,7 -61,7 +64,7 @@@
      /**
       * Store a newly created user in storage.
       * @throws UserUpdateException
 -     * @throws \Illuminate\Validation\ValidationException
 +     * @throws ValidationException
       */
      public function store(Request $request)
      {
@@@ -93,7 -90,6 +93,7 @@@
              $user->external_auth_id = $request->get('external_auth_id');
          }
  
 +        $user->refreshSlug();
          $user->save();
  
          if ($sendInvite) {
      /**
       * Update the specified user in storage.
       * @throws UserUpdateException
 -     * @throws \BookStack\Exceptions\ImageUploadException
 -     * @throws \Illuminate\Validation\ValidationException
 +     * @throws ImageUploadException
 +     * @throws ValidationException
       */
      public function update(Request $request, int $id)
      {
              $user->email = $request->get('email');
          }
  
 +        // Refresh the slug if the user's name has changed
 +        if ($user->isDirty('name')) {
 +            $user->refreshSlug();
 +        }
 +
          // Role updates
          if (userCan('users-manage') && $request->filled('roles')) {
              $roles = $request->get('roles');
  
      /**
       * Remove the specified user from storage.
 -     * @throws \Exception
 +     * @throws Exception
       */
      public function destroy(Request $request, int $id)
      {
          return redirect('/settings/users');
      }
  
 -    /**
 -     * Show the user profile page
 -     */
 -    public function showProfilePage($id)
 -    {
 -        $user = $this->userRepo->getById($id);
 -
 -        $userActivity = $this->userRepo->getActivity($user);
 -        $recentlyCreated = $this->userRepo->getRecentlyCreated($user, 5);
 -        $assetCounts = $this->userRepo->getAssetCounts($user);
 -
 -        return view('users.profile', [
 -            'user' => $user,
 -            'activity' => $userActivity,
 -            'recentlyCreated' => $recentlyCreated,
 -            'assetCounts' => $assetCounts
 -        ]);
 -    }
 -
      /**
       * Update the user's preferred book-list display setting.
       */
       */
      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);
          }