mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Added favourites page with link from header and home
This commit is contained in:
parent
27942f5ce8
commit
1e0aa7ee2c
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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>
|
19
resources/views/common/detailed-listing-with-more.blade.php
Normal file
19
resources/views/common/detailed-listing-with-more.blade.php
Normal file
@ -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
|
@ -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>
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user