Added shelves and search shortcuts to profile page

This commit is contained in:
Dan Brown 2019-04-06 16:21:20 +01:00
parent 666ced9c3b
commit 17969c0bbf
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
5 changed files with 81 additions and 41 deletions

View file

@ -6,6 +6,7 @@ use BookStack\Exceptions\NotFoundException;
use BookStack\Exceptions\UserUpdateException; use BookStack\Exceptions\UserUpdateException;
use BookStack\Uploads\Image; use BookStack\Uploads\Image;
use Exception; use Exception;
use Illuminate\Database\Eloquent\Builder;
use Images; use Images;
class UserRepo class UserRepo
@ -48,7 +49,7 @@ class UserRepo
/** /**
* Get all the users with their permissions. * Get all the users with their permissions.
* @return \Illuminate\Database\Eloquent\Builder|static * @return Builder|static
*/ */
public function getAllUsers() public function getAllUsers()
{ {
@ -59,7 +60,7 @@ class UserRepo
* Get all the users with their permissions in a paginated format. * Get all the users with their permissions in a paginated format.
* @param int $count * @param int $count
* @param $sortData * @param $sortData
* @return \Illuminate\Database\Eloquent\Builder|static * @return Builder|static
*/ */
public function getAllUsersPaginatedAndSorted($count, $sortData) public function getAllUsersPaginatedAndSorted($count, $sortData)
{ {
@ -223,16 +224,15 @@ class UserRepo
*/ */
public function getRecentlyCreated(User $user, $count = 20) public function getRecentlyCreated(User $user, $count = 20)
{ {
$createdByUserQuery = function(Builder $query) use ($user) {
$query->where('created_by', '=', $user->id);
};
return [ return [
'pages' => $this->entityRepo->getRecentlyCreated('page', $count, 0, function ($query) use ($user) { 'pages' => $this->entityRepo->getRecentlyCreated('page', $count, 0, $createdByUserQuery),
$query->where('created_by', '=', $user->id); 'chapters' => $this->entityRepo->getRecentlyCreated('chapter', $count, 0, $createdByUserQuery),
}), 'books' => $this->entityRepo->getRecentlyCreated('book', $count, 0, $createdByUserQuery),
'chapters' => $this->entityRepo->getRecentlyCreated('chapter', $count, 0, function ($query) use ($user) { 'shelves' => $this->entityRepo->getRecentlyCreated('bookshelf', $count, 0, $createdByUserQuery)
$query->where('created_by', '=', $user->id);
}),
'books' => $this->entityRepo->getRecentlyCreated('book', $count, 0, function ($query) use ($user) {
$query->where('created_by', '=', $user->id);
})
]; ];
} }
@ -247,6 +247,7 @@ class UserRepo
'pages' => $this->entityRepo->getUserTotalCreated('page', $user), 'pages' => $this->entityRepo->getUserTotalCreated('page', $user),
'chapters' => $this->entityRepo->getUserTotalCreated('chapter', $user), 'chapters' => $this->entityRepo->getUserTotalCreated('chapter', $user),
'books' => $this->entityRepo->getUserTotalCreated('book', $user), 'books' => $this->entityRepo->getUserTotalCreated('book', $user),
'shelves' => $this->entityRepo->getUserTotalCreated('bookshelf', $user),
]; ];
} }

View file

@ -41,7 +41,7 @@ class UserController extends Controller
$users = $this->userRepo->getAllUsersPaginatedAndSorted(20, $listDetails); $users = $this->userRepo->getAllUsersPaginatedAndSorted(20, $listDetails);
$this->setPageTitle(trans('settings.users')); $this->setPageTitle(trans('settings.users'));
$users->appends($listDetails); $users->appends($listDetails);
return view('users/index', ['users' => $users, 'listDetails' => $listDetails]); return view('users.index', ['users' => $users, 'listDetails' => $listDetails]);
} }
/** /**
@ -53,7 +53,7 @@ class UserController extends Controller
$this->checkPermission('users-manage'); $this->checkPermission('users-manage');
$authMethod = config('auth.method'); $authMethod = config('auth.method');
$roles = $this->userRepo->getAllRoles(); $roles = $this->userRepo->getAllRoles();
return view('users/create', ['authMethod' => $authMethod, 'roles' => $roles]); return view('users.create', ['authMethod' => $authMethod, 'roles' => $roles]);
} }
/** /**
@ -118,7 +118,7 @@ class UserController extends Controller
$activeSocialDrivers = $socialAuthService->getActiveDrivers(); $activeSocialDrivers = $socialAuthService->getActiveDrivers();
$this->setPageTitle(trans('settings.user_profile')); $this->setPageTitle(trans('settings.user_profile'));
$roles = $this->userRepo->getAllRoles(); $roles = $this->userRepo->getAllRoles();
return view('users/edit', ['user' => $user, 'activeSocialDrivers' => $activeSocialDrivers, 'authMethod' => $authMethod, 'roles' => $roles]); return view('users.edit', ['user' => $user, 'activeSocialDrivers' => $activeSocialDrivers, 'authMethod' => $authMethod, 'roles' => $roles]);
} }
/** /**
@ -190,7 +190,7 @@ class UserController extends Controller
$user = $this->userRepo->getById($id); $user = $this->userRepo->getById($id);
$this->setPageTitle(trans('settings.users_delete_named', ['userName' => $user->name])); $this->setPageTitle(trans('settings.users_delete_named', ['userName' => $user->name]));
return view('users/delete', ['user' => $user]); return view('users.delete', ['user' => $user]);
} }
/** /**
@ -232,10 +232,12 @@ class UserController extends Controller
public function showProfilePage($id) public function showProfilePage($id)
{ {
$user = $this->userRepo->getById($id); $user = $this->userRepo->getById($id);
$userActivity = $this->userRepo->getActivity($user); $userActivity = $this->userRepo->getActivity($user);
$recentlyCreated = $this->userRepo->getRecentlyCreated($user, 5, 0); $recentlyCreated = $this->userRepo->getRecentlyCreated($user, 5, 0);
$assetCounts = $this->userRepo->getAssetCounts($user); $assetCounts = $this->userRepo->getAssetCounts($user);
return view('users/profile', [
return view('users.profile', [
'user' => $user, 'user' => $user,
'activity' => $userActivity, 'activity' => $userActivity,
'recentlyCreated' => $recentlyCreated, 'recentlyCreated' => $recentlyCreated,

View file

@ -23,6 +23,7 @@ return [
// Actions // Actions
'actions' => 'Actions', 'actions' => 'Actions',
'view' => 'View', 'view' => 'View',
'view_all' => 'View All',
'create' => 'Create', 'create' => 'Create',
'update' => 'Update', 'update' => 'Update',
'edit' => 'Edit', 'edit' => 'Edit',

View file

@ -11,6 +11,7 @@ return [
'recently_updated_pages' => 'Recently Updated Pages', 'recently_updated_pages' => 'Recently Updated Pages',
'recently_created_chapters' => 'Recently Created Chapters', 'recently_created_chapters' => 'Recently Created Chapters',
'recently_created_books' => 'Recently Created Books', 'recently_created_books' => 'Recently Created Books',
'recently_created_shelves' => 'Recently Created Shelves',
'recently_update' => 'Recently Updated', 'recently_update' => 'Recently Updated',
'recently_viewed' => 'Recently Viewed', 'recently_viewed' => 'Recently Viewed',
'recent_activity' => 'Recent Activity', 'recent_activity' => 'Recent Activity',
@ -67,6 +68,7 @@ return [
// Shelves // Shelves
'shelf' => 'Shelf', 'shelf' => 'Shelf',
'shelves' => 'Shelves', 'shelves' => 'Shelves',
'x_shelves' => ':count Shelf|:count Shelves',
'shelves_long' => 'Bookshelves', 'shelves_long' => 'Bookshelves',
'shelves_empty' => 'No shelves have been created', 'shelves_empty' => 'No shelves have been created',
'shelves_create' => 'Create New Shelf', 'shelves_create' => 'Create New Shelf',
@ -274,6 +276,7 @@ return [
'profile_not_created_pages' => ':userName has not created any pages', 'profile_not_created_pages' => ':userName has not created any pages',
'profile_not_created_chapters' => ':userName has not created any chapters', 'profile_not_created_chapters' => ':userName has not created any chapters',
'profile_not_created_books' => ':userName has not created any books', 'profile_not_created_books' => ':userName has not created any books',
'profile_not_created_shelves' => ':userName has not created any shelves',
// Comments // Comments
'comment' => 'Comment', 'comment' => 'Comment',

View file

@ -1,9 +1,5 @@
@extends('simple-layout') @extends('simple-layout')
{{--TODO - Include links to search based on this user being the creator for each entity type--}}
{{--Linking either the "Created content" items or as "View All" links next to headers--}}
{{--TODO - Add shelves?--}}
@section('body') @section('body')
<div class="container pt-xl"> <div class="container pt-xl">
@ -13,13 +9,13 @@
<div> <div>
<div id="recent-user-activity" class="mb-xl"> <div id="recent-user-activity" class="mb-xl">
<h5>{{ trans('entities.recent_activity') }}</h5> <h5>{{ trans('entities.recent_activity') }}</h5>
@include('partials/activity-list', ['activity' => $activity]) @include('partials.activity-list', ['activity' => $activity])
</div> </div>
</div> </div>
<div> <div>
<div class="card content-wrap auto-height"> <div class="card content-wrap auto-height">
<div class="grid left-focus v-center"> <div class="grid half v-center">
<div> <div>
<div class="mr-m float left"> <div class="mr-m float left">
<img class="avatar square huge" src="{{ $user->getAvatar(120) }}" alt="{{ $user->name }}"> <img class="avatar square huge" src="{{ $user->getAvatar(120) }}" alt="{{ $user->name }}">
@ -33,19 +29,27 @@
</div> </div>
<div id="content-counts"> <div id="content-counts">
<div class="text-muted">{{ trans('entities.profile_created_content') }}</div> <div class="text-muted">{{ trans('entities.profile_created_content') }}</div>
<div class="icon-list"> <div class="grid half v-center">
<a href="#recent-books" class="text-book icon-list-item"> <div class="icon-list">
<span>@icon('book')</span> <a href="#recent-pages" class="text-page icon-list-item">
<span>{{ trans_choice('entities.x_books', $assetCounts['books']) }}</span> <span>@icon('page')</span>
</a> <span>{{ trans_choice('entities.x_pages', $assetCounts['pages']) }}</span>
<a href="#recent-chapters" class="text-chapter icon-list-item"> </a>
<span>@icon('chapter')</span> <a href="#recent-chapters" class="text-chapter icon-list-item">
<span>{{ trans_choice('entities.x_chapters', $assetCounts['chapters']) }}</span> <span>@icon('chapter')</span>
</a> <span>{{ trans_choice('entities.x_chapters', $assetCounts['chapters']) }}</span>
<a href="#recent-pages" class="text-page icon-list-item"> </a>
<span>@icon('page')</span> </div>
<span>{{ trans_choice('entities.x_pages', $assetCounts['pages']) }}</span> <div class="icon-list">
</a> <a href="#recent-books" class="text-book icon-list-item">
<span>@icon('book')</span>
<span>{{ trans_choice('entities.x_books', $assetCounts['books']) }}</span>
</a>
<a href="#recent-shelves" class="text-bookshelf icon-list-item">
<span>@icon('bookshelf')</span>
<span>{{ trans_choice('entities.x_shelves', $assetCounts['shelves']) }}</span>
</a>
</div>
</div> </div>
</div> </div>
@ -53,31 +57,60 @@
</div> </div>
<div class="card content-wrap auto-height book-contents"> <div class="card content-wrap auto-height book-contents">
<h2 id="recent-pages" class="list-heading">{{ trans('entities.recently_created_pages') }}</h2> <h2 id="recent-pages" class="list-heading">
{{ trans('entities.recently_created_pages') }}
@if (count($recentlyCreated['pages']) > 0)
<a href="{{ baseUrl('/search?term=' . urlencode('{created_by:'.$user->id.'} {type:page}') ) }}" class="text-small ml-s">{{ trans('common.view_all') }}</a>
@endif
</h2>
@if (count($recentlyCreated['pages']) > 0) @if (count($recentlyCreated['pages']) > 0)
@include('partials/entity-list', ['entities' => $recentlyCreated['pages']]) @include('partials.entity-list', ['entities' => $recentlyCreated['pages'], 'showPath' => true])
@else @else
<p class="text-muted">{{ trans('entities.profile_not_created_pages', ['userName' => $user->name]) }}</p> <p class="text-muted">{{ trans('entities.profile_not_created_pages', ['userName' => $user->name]) }}</p>
@endif @endif
</div> </div>
<div class="card content-wrap auto-height book-contents"> <div class="card content-wrap auto-height book-contents">
<h2 id="recent-chapters" class="list-heading">{{ trans('entities.recently_created_chapters') }}</h2> <h2 id="recent-chapters" class="list-heading">
{{ trans('entities.recently_created_chapters') }}
@if (count($recentlyCreated['chapters']) > 0)
<a href="{{ baseUrl('/search?term=' . urlencode('{created_by:'.$user->id.'} {type:chapter}') ) }}" class="text-small ml-s">{{ trans('common.view_all') }}</a>
@endif
</h2>
@if (count($recentlyCreated['chapters']) > 0) @if (count($recentlyCreated['chapters']) > 0)
@include('partials/entity-list', ['entities' => $recentlyCreated['chapters']]) @include('partials.entity-list', ['entities' => $recentlyCreated['chapters'], 'showPath' => true])
@else @else
<p class="text-muted">{{ trans('entities.profile_not_created_chapters', ['userName' => $user->name]) }}</p> <p class="text-muted">{{ trans('entities.profile_not_created_chapters', ['userName' => $user->name]) }}</p>
@endif @endif
</div> </div>
<div class="card content-wrap auto-height book-contents"> <div class="card content-wrap auto-height book-contents">
<h2 id="recent-books" class="list-heading">{{ trans('entities.recently_created_books') }}</h2> <h2 id="recent-books" class="list-heading">
{{ trans('entities.recently_created_books') }}
@if (count($recentlyCreated['books']) > 0)
<a href="{{ baseUrl('/search?term=' . urlencode('{created_by:'.$user->id.'} {type:book}') ) }}" class="text-small ml-s">{{ trans('common.view_all') }}</a>
@endif
</h2>
@if (count($recentlyCreated['books']) > 0) @if (count($recentlyCreated['books']) > 0)
@include('partials/entity-list', ['entities' => $recentlyCreated['books']]) @include('partials.entity-list', ['entities' => $recentlyCreated['books'], 'showPath' => true])
@else @else
<p class="text-muted">{{ trans('entities.profile_not_created_books', ['userName' => $user->name]) }}</p> <p class="text-muted">{{ trans('entities.profile_not_created_books', ['userName' => $user->name]) }}</p>
@endif @endif
</div> </div>
<div class="card content-wrap auto-height book-contents">
<h2 id="recent-shelves" class="list-heading">
{{ trans('entities.recently_created_shelves') }}
@if (count($recentlyCreated['shelves']) > 0)
<a href="{{ baseUrl('/search?term=' . urlencode('{created_by:'.$user->id.'} {type:bookshelf}') ) }}" class="text-small ml-s">{{ trans('common.view_all') }}</a>
@endif
</h2>
@if (count($recentlyCreated['shelves']) > 0)
@include('partials.entity-list', ['entities' => $recentlyCreated['shelves'], 'showPath' => true])
@else
<p class="text-muted">{{ trans('entities.profile_not_created_shelves', ['userName' => $user->name]) }}</p>
@endif
</div>
</div> </div>
</div> </div>