]> BookStack Code Mirror - bookstack/commitdiff
Added favourites page with link from header and home
authorDan Brown <redacted>
Sun, 23 May 2021 12:34:08 +0000 (13:34 +0100)
committerDan Brown <redacted>
Sun, 23 May 2021 12:34:08 +0000 (13:34 +0100)
app/Entities/Queries/TopFavourites.php
app/Http/Controllers/FavouriteController.php
app/Http/Controllers/HomeController.php
app/Http/Controllers/PageController.php
resources/lang/en/entities.php
resources/views/common/detailed-listing-paginated.blade.php [moved from resources/views/pages/detailed-listing.blade.php with 82% similarity]
resources/views/common/detailed-listing-with-more.blade.php [new file with mode: 0644]
resources/views/common/header.blade.php
resources/views/common/home-sidebar.blade.php
resources/views/common/home.blade.php
routes/web.php

index aaacdc5ad8561b2e7c629f5e92e2b9a100deca29..a527c2a4eac34f822dd7d5c7d911f8a73ecaceb6 100644 (file)
@@ -1,13 +1,12 @@
 <?php namespace BookStack\Entities\Queries;
 
-
 use BookStack\Actions\View;
 use Illuminate\Database\Query\JoinClause;
 use Illuminate\Support\Facades\DB;
 
 class TopFavourites extends EntityQuery
 {
-    public function run(int $count, int $page)
+    public function run(int $count, int $skip = 0)
     {
         $user = user();
         if ($user === null || $user->isDefault()) {
@@ -26,11 +25,10 @@ class TopFavourites extends EntityQuery
             ->orderBy('view_count', 'desc');
 
         return $query->with('viewable')
-            ->skip($count * ($page - 1))
+            ->skip($skip)
             ->take($count)
             ->get()
             ->pluck('viewable')
             ->filter();
     }
-
-}
\ No newline at end of file
+}
index 8a26eac8ebbd02a27c35a9d831afbf849502832c..f4aeb4faa1389c16f484fbaed3113a283b07aa7d 100644 (file)
@@ -3,12 +3,31 @@
 namespace BookStack\Http\Controllers;
 
 use BookStack\Entities\Models\Entity;
+use BookStack\Entities\Queries\TopFavourites;
 use BookStack\Interfaces\Favouritable;
 use BookStack\Model;
 use Illuminate\Http\Request;
 
 class FavouriteController extends Controller
 {
+    /**
+     * Show a listing of all favourite items for the current user.
+     */
+    public function index(Request $request)
+    {
+        $viewCount = 20;
+        $page = intval($request->get('page', 1));
+        $favourites = (new TopFavourites)->run($viewCount + 1, (($page - 1) * $viewCount));
+
+        $hasMoreLink = ($favourites->count() > $viewCount) ? url("/favourites?page=" . ($page+1)) : null;
+
+        return view('common.detailed-listing-with-more', [
+            'title' => trans('entities.my_favourites'),
+            'entities' => $favourites->slice(0, $viewCount),
+            'hasMoreLink' => $hasMoreLink,
+        ]);
+    }
+
     /**
      * Add a new item as a favourite.
      */
index f5ab212040c6eb5dc1f5f411999b32ec5f56c492..7bc17052652aa65652b762c9335aee9fd72eaf4f 100644 (file)
@@ -35,11 +35,11 @@ class HomeController extends Controller
         $recents = $this->isSignedIn() ?
             (new RecentlyViewed)->run(12*$recentFactor, 1)
             : Book::visible()->orderBy('created_at', 'desc')->take(12 * $recentFactor)->get();
-        $faviourites = (new TopFavourites)->run(6, 1);
+        $favourites = (new TopFavourites)->run(6);
         $recentlyUpdatedPages = Page::visible()->with('book')
             ->where('draft', false)
             ->orderBy('updated_at', 'desc')
-            ->take($faviourites->count() > 0 ? 6 : 12)
+            ->take($favourites->count() > 0 ? 6 : 12)
             ->get();
 
         $homepageOptions = ['default', 'books', 'bookshelves', 'page'];
@@ -53,7 +53,7 @@ class HomeController extends Controller
             'recents' => $recents,
             'recentlyUpdatedPages' => $recentlyUpdatedPages,
             'draftPages' => $draftPages,
-            'favourites' => $faviourites,
+            'favourites' => $favourites,
         ];
 
         // Add required list ordering & sorting for books & shelves views.
index 769ea8e691f3ff53e7e3f104a4ee69c4f55f686c..134c22081382bdd0a3a407b469bd7684ccb9c4d0 100644 (file)
@@ -338,9 +338,9 @@ class PageController extends Controller
             ->paginate(20)
             ->setPath(url('/pages/recently-updated'));
 
-        return view('pages.detailed-listing', [
+        return view('common.detailed-listing-paginated', [
             'title' => trans('entities.recently_updated_pages'),
-            'pages' => $pages
+            'entities' => $pages
         ]);
     }
 
index 6c3341368ee19ba7988909bac39507e1a23722fe..462402f33f407b458700e80e2c15f22257ceba52 100644 (file)
@@ -28,6 +28,7 @@ return [
     'my_recent_drafts' => 'My Recent Drafts',
     'my_recently_viewed' => 'My Recently Viewed',
     'my_most_viewed_favourites' => 'My Most Viewed Favourites',
+    'my_favourites' => 'My Favourites',
     'no_pages_viewed' => 'You have not viewed any pages',
     'no_pages_recently_created' => 'No pages have been recently created',
     'no_pages_recently_updated' => 'No pages have been recently updated',
similarity index 82%
rename from resources/views/pages/detailed-listing.blade.php
rename to resources/views/common/detailed-listing-paginated.blade.php
index c2bbdb53711629d86bc7a3272f8fcab12ff6ba20..af9490a410f897a62891230268130591f8e253c3 100644 (file)
@@ -6,11 +6,11 @@
             <h1 class="list-heading">{{ $title }}</h1>
 
             <div class="book-contents">
-                @include('partials.entity-list', ['entities' => $pages, 'style' => 'detailed'])
+                @include('partials.entity-list', ['entities' => $entities, 'style' => 'detailed'])
             </div>
 
             <div class="text-center">
-                {!! $pages->links() !!}
+                {!! $entities->links() !!}
             </div>
         </main>
     </div>
diff --git a/resources/views/common/detailed-listing-with-more.blade.php b/resources/views/common/detailed-listing-with-more.blade.php
new file mode 100644 (file)
index 0000000..5790f20
--- /dev/null
@@ -0,0 +1,19 @@
+@extends('simple-layout')
+
+@section('body')
+    <div class="container small pt-xl">
+        <main class="card content-wrap">
+            <h1 class="list-heading">{{ $title }}</h1>
+
+            <div class="book-contents">
+                @include('partials.entity-list', ['entities' => $entities, 'style' => 'detailed'])
+            </div>
+
+            <div class="text-right">
+                @if($hasMoreLink)
+                    <a href="{{ $hasMoreLink }}" class="button outline">{{ trans('common.more') }}</a>
+                @endif
+            </div>
+        </main>
+    </div>
+@stop
\ No newline at end of file
index 4799aba24507ae8bfc397853e616a6d76b8ea4b4..274a09996125f21303d4d38a58b91f4214fe65f1 100644 (file)
@@ -61,6 +61,9 @@
                             <span class="name">{{ $currentUser->getShortName(9) }}</span> @icon('caret-down')
                         </span>
                         <ul refs="dropdown@menu" class="dropdown-menu" role="menu">
+                            <li>
+                                <a href="{{ url('/favourites') }}">@icon('star'){{ trans('entities.my_favourites') }}</a>
+                            </li>
                             <li>
                                 <a href="{{ $currentUser->getProfileUrl() }}">@icon('user'){{ trans('common.view_profile') }}</a>
                             </li>
index b66c8495d4f159742ccaedfe3674b231d714fffe..5db89e8709147b66f745e9cf4f59042816b933c3 100644 (file)
@@ -7,7 +7,9 @@
 
 @if(count($favourites) > 0)
     <div id="top-favourites" class="card mb-xl">
-        <h3 class="card-title">{{ trans('entities.my_most_viewed_favourites') }}</h3>
+        <h3 class="card-title">
+            <a href="{{ url('/favourites') }}" class="no-color">{{ trans('entities.my_most_viewed_favourites') }}</a>
+        </h3>
         <div class="px-m">
             @include('partials.entity-list', [
             'entities' => $favourites,
index acfca97b2ef205474202724a3a8ec2e73eb40550..3a360b19cc16ac7f12d1a7f1564ff4ccd1e67ae5 100644 (file)
@@ -44,7 +44,9 @@
             <div>
                 @if(count($favourites) > 0)
                     <div id="top-favourites" class="card mb-xl">
-                        <h3 class="card-title">{{ trans('entities.my_most_viewed_favourites') }}</h3>
+                        <h3 class="card-title">
+                            <a href="{{ url('/favourites') }}" class="no-color">{{ trans('entities.my_most_viewed_favourites') }}</a>
+                        </h3>
                         <div class="px-m">
                             @include('partials.entity-list', [
                             'entities' => $favourites,
index 69823b4ba39426ec130e2e7c2f1ca0760b407cc3..59a6eddc630db85801523895be76970be027520b 100644 (file)
@@ -157,6 +157,7 @@ Route::group(['middleware' => 'auth'], function () {
     Route::get('/templates/{templateId}', 'PageTemplateController@get');
 
     // Favourites
+    Route::get('/favourites', 'FavouriteController@index');
     Route::post('/favourites/add', 'FavouriteController@add');
     Route::post('/favourites/remove', 'FavouriteController@remove');