Added recent pages to home view and made the home content more compact
Showing
8 changed files
with
173 additions
and
79 deletions
| ... | @@ -3,25 +3,21 @@ | ... | @@ -3,25 +3,21 @@ |
| 3 | namespace BookStack\Http\Controllers; | 3 | namespace BookStack\Http\Controllers; |
| 4 | 4 | ||
| 5 | use Activity; | 5 | use Activity; |
| 6 | -use Illuminate\Http\Request; | 6 | +use BookStack\Repos\EntityRepo; |
| 7 | - | ||
| 8 | use BookStack\Http\Requests; | 7 | use BookStack\Http\Requests; |
| 9 | -use BookStack\Repos\BookRepo; | ||
| 10 | use Views; | 8 | use Views; |
| 11 | 9 | ||
| 12 | class HomeController extends Controller | 10 | class HomeController extends Controller |
| 13 | { | 11 | { |
| 14 | - | 12 | + protected $entityRepo; |
| 15 | - protected $activityService; | ||
| 16 | - protected $bookRepo; | ||
| 17 | 13 | ||
| 18 | /** | 14 | /** |
| 19 | * HomeController constructor. | 15 | * HomeController constructor. |
| 20 | - * @param BookRepo $bookRepo | 16 | + * @param EntityRepo $entityRepo |
| 21 | */ | 17 | */ |
| 22 | - public function __construct(BookRepo $bookRepo) | 18 | + public function __construct(EntityRepo $entityRepo) |
| 23 | { | 19 | { |
| 24 | - $this->bookRepo = $bookRepo; | 20 | + $this->entityRepo = $entityRepo; |
| 25 | parent::__construct(); | 21 | parent::__construct(); |
| 26 | } | 22 | } |
| 27 | 23 | ||
| ... | @@ -33,9 +29,16 @@ class HomeController extends Controller | ... | @@ -33,9 +29,16 @@ class HomeController extends Controller |
| 33 | */ | 29 | */ |
| 34 | public function index() | 30 | public function index() |
| 35 | { | 31 | { |
| 36 | - $activity = Activity::latest(); | 32 | + $activity = Activity::latest(10); |
| 37 | - $recents = $this->signedIn ? Views::getUserRecentlyViewed(10, 0) : $this->bookRepo->getLatest(10); | 33 | + $recents = $this->signedIn ? Views::getUserRecentlyViewed(12, 0) : $this->entityRepo->getRecentlyCreatedBooks(10); |
| 38 | - return view('home', ['activity' => $activity, 'recents' => $recents]); | 34 | + $recentlyCreatedPages = $this->entityRepo->getRecentlyCreatedPages(5); |
| 35 | + $recentlyUpdatedPages = $this->entityRepo->getRecentlyUpdatedPages(5); | ||
| 36 | + return view('home', [ | ||
| 37 | + 'activity' => $activity, | ||
| 38 | + 'recents' => $recents, | ||
| 39 | + 'recentlyCreatedPages' => $recentlyCreatedPages, | ||
| 40 | + 'recentlyUpdatedPages' => $recentlyUpdatedPages | ||
| 41 | + ]); | ||
| 39 | } | 42 | } |
| 40 | 43 | ||
| 41 | } | 44 | } | ... | ... |
app/Repos/EntityRepo.php
0 → 100644
| 1 | +<?php namespace BookStack\Repos; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +use BookStack\Book; | ||
| 5 | +use BookStack\Chapter; | ||
| 6 | +use BookStack\Page; | ||
| 7 | + | ||
| 8 | +class EntityRepo | ||
| 9 | +{ | ||
| 10 | + | ||
| 11 | + public $book; | ||
| 12 | + public $chapter; | ||
| 13 | + public $page; | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * EntityService constructor. | ||
| 17 | + * @param $book | ||
| 18 | + * @param $chapter | ||
| 19 | + * @param $page | ||
| 20 | + */ | ||
| 21 | + public function __construct(Book $book, Chapter $chapter, Page $page) | ||
| 22 | + { | ||
| 23 | + $this->book = $book; | ||
| 24 | + $this->chapter = $chapter; | ||
| 25 | + $this->page = $page; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * Get the latest books added to the system. | ||
| 30 | + * @param $count | ||
| 31 | + * @param $page | ||
| 32 | + */ | ||
| 33 | + public function getRecentlyCreatedBooks($count = 20, $page = 0) | ||
| 34 | + { | ||
| 35 | + return $this->book->orderBy('created_at', 'desc')->skip($page*$count)->take($count)->get(); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Get the most recently updated books. | ||
| 40 | + * @param $count | ||
| 41 | + * @param int $page | ||
| 42 | + * @return mixed | ||
| 43 | + */ | ||
| 44 | + public function getRecentlyUpdatedBooks($count = 20, $page = 0) | ||
| 45 | + { | ||
| 46 | + return $this->book->orderBy('updated_at', 'desc')->skip($page*$count)->take($count)->get(); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Get the latest pages added to the system. | ||
| 51 | + * @param $count | ||
| 52 | + * @param $page | ||
| 53 | + */ | ||
| 54 | + public function getRecentlyCreatedPages($count = 20, $page = 0) | ||
| 55 | + { | ||
| 56 | + return $this->page->orderBy('created_at', 'desc')->skip($page*$count)->take($count)->get(); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Get the most recently updated pages. | ||
| 61 | + * @param $count | ||
| 62 | + * @param int $page | ||
| 63 | + * @return mixed | ||
| 64 | + */ | ||
| 65 | + public function getRecentlyUpdatedPages($count = 20, $page = 0) | ||
| 66 | + { | ||
| 67 | + return $this->page->orderBy('updated_at', 'desc')->skip($page*$count)->take($count)->get(); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + | ||
| 71 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | <?php namespace BookStack\Repos; | 1 | <?php namespace BookStack\Repos; |
| 2 | 2 | ||
| 3 | - | ||
| 4 | -use BookStack\Page; | ||
| 5 | use BookStack\Role; | 3 | use BookStack\Role; |
| 6 | -use BookStack\Services\EntityService; | ||
| 7 | use BookStack\User; | 4 | use BookStack\User; |
| 8 | -use Carbon\Carbon; | ||
| 9 | use Setting; | 5 | use Setting; |
| 10 | 6 | ||
| 11 | class UserRepo | 7 | class UserRepo |
| ... | @@ -13,19 +9,19 @@ class UserRepo | ... | @@ -13,19 +9,19 @@ class UserRepo |
| 13 | 9 | ||
| 14 | protected $user; | 10 | protected $user; |
| 15 | protected $role; | 11 | protected $role; |
| 16 | - protected $entityService; | 12 | + protected $entityRepo; |
| 17 | 13 | ||
| 18 | /** | 14 | /** |
| 19 | * UserRepo constructor. | 15 | * UserRepo constructor. |
| 20 | * @param User $user | 16 | * @param User $user |
| 21 | * @param Role $role | 17 | * @param Role $role |
| 22 | - * @param EntityService $entityService | 18 | + * @param EntityRepo $entityRepo |
| 23 | */ | 19 | */ |
| 24 | - public function __construct(User $user, Role $role, EntityService $entityService) | 20 | + public function __construct(User $user, Role $role, EntityRepo $entityRepo) |
| 25 | { | 21 | { |
| 26 | $this->user = $user; | 22 | $this->user = $user; |
| 27 | $this->role = $role; | 23 | $this->role = $role; |
| 28 | - $this->entityService = $entityService; | 24 | + $this->entityRepo = $entityRepo; |
| 29 | } | 25 | } |
| 30 | 26 | ||
| 31 | /** | 27 | /** |
| ... | @@ -141,11 +137,11 @@ class UserRepo | ... | @@ -141,11 +137,11 @@ class UserRepo |
| 141 | public function getRecentlyCreated(User $user, $count = 20) | 137 | public function getRecentlyCreated(User $user, $count = 20) |
| 142 | { | 138 | { |
| 143 | return [ | 139 | return [ |
| 144 | - 'pages' => $this->entityService->page->where('created_by', '=', $user->id)->orderBy('created_at', 'desc') | 140 | + 'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->orderBy('created_at', 'desc') |
| 145 | ->take($count)->get(), | 141 | ->take($count)->get(), |
| 146 | - 'chapters' => $this->entityService->chapter->where('created_by', '=', $user->id)->orderBy('created_at', 'desc') | 142 | + 'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->orderBy('created_at', 'desc') |
| 147 | ->take($count)->get(), | 143 | ->take($count)->get(), |
| 148 | - 'books' => $this->entityService->book->where('created_by', '=', $user->id)->orderBy('created_at', 'desc') | 144 | + 'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->orderBy('created_at', 'desc') |
| 149 | ->take($count)->get() | 145 | ->take($count)->get() |
| 150 | ]; | 146 | ]; |
| 151 | } | 147 | } |
| ... | @@ -158,9 +154,9 @@ class UserRepo | ... | @@ -158,9 +154,9 @@ class UserRepo |
| 158 | public function getAssetCounts(User $user) | 154 | public function getAssetCounts(User $user) |
| 159 | { | 155 | { |
| 160 | return [ | 156 | return [ |
| 161 | - 'pages' => $this->entityService->page->where('created_by', '=', $user->id)->count(), | 157 | + 'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->count(), |
| 162 | - 'chapters' => $this->entityService->chapter->where('created_by', '=', $user->id)->count(), | 158 | + 'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->count(), |
| 163 | - 'books' => $this->entityService->book->where('created_by', '=', $user->id)->count(), | 159 | + 'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->count(), |
| 164 | ]; | 160 | ]; |
| 165 | } | 161 | } |
| 166 | 162 | ... | ... |
app/Services/EntityService.php
deleted
100644 → 0
| 1 | -<?php namespace BookStack\Services; | ||
| 2 | - | ||
| 3 | - | ||
| 4 | -use BookStack\Book; | ||
| 5 | -use BookStack\Chapter; | ||
| 6 | -use BookStack\Page; | ||
| 7 | - | ||
| 8 | -class EntityService | ||
| 9 | -{ | ||
| 10 | - | ||
| 11 | - public $book; | ||
| 12 | - public $chapter; | ||
| 13 | - public $page; | ||
| 14 | - | ||
| 15 | - /** | ||
| 16 | - * EntityService constructor. | ||
| 17 | - * @param $book | ||
| 18 | - * @param $chapter | ||
| 19 | - * @param $page | ||
| 20 | - */ | ||
| 21 | - public function __construct(Book $book, Chapter $chapter, Page $page) | ||
| 22 | - { | ||
| 23 | - $this->book = $book; | ||
| 24 | - $this->chapter = $chapter; | ||
| 25 | - $this->page = $page; | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | - | ||
| 29 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -106,6 +106,12 @@ $(function () { | ... | @@ -106,6 +106,12 @@ $(function () { |
| 106 | } | 106 | } |
| 107 | }); | 107 | }); |
| 108 | 108 | ||
| 109 | + // Common jQuery actions | ||
| 110 | + $('[data-action="expand-entity-list-details"]').click(function() { | ||
| 111 | + $('.entity-list.compact').find('p').slideToggle(240); | ||
| 112 | + }); | ||
| 113 | + | ||
| 114 | + | ||
| 109 | }); | 115 | }); |
| 110 | 116 | ||
| 111 | 117 | ... | ... |
| ... | @@ -283,4 +283,26 @@ ul.pagination { | ... | @@ -283,4 +283,26 @@ ul.pagination { |
| 283 | a { | 283 | a { |
| 284 | color: $primary; | 284 | color: $primary; |
| 285 | } | 285 | } |
| 286 | +} | ||
| 287 | + | ||
| 288 | +.entity-list.compact { | ||
| 289 | + font-size: 0.6em; | ||
| 290 | + > div { | ||
| 291 | + padding: $-m 0; | ||
| 292 | + } | ||
| 293 | + h3, a { | ||
| 294 | + line-height: 1.2; | ||
| 295 | + } | ||
| 296 | + h3 { | ||
| 297 | + margin: 0; | ||
| 298 | + } | ||
| 299 | + p { | ||
| 300 | + display: none; | ||
| 301 | + font-size: $fs-m * 0.8; | ||
| 302 | + padding-top: $-xs; | ||
| 303 | + margin: 0; | ||
| 304 | + } | ||
| 305 | + hr { | ||
| 306 | + margin: 0; | ||
| 307 | + } | ||
| 286 | } | 308 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -2,20 +2,43 @@ | ... | @@ -2,20 +2,43 @@ |
| 2 | 2 | ||
| 3 | @section('content') | 3 | @section('content') |
| 4 | 4 | ||
| 5 | + <div class="faded-small toolbar"> | ||
| 6 | + <div class="container"> | ||
| 7 | + <div class="row"> | ||
| 8 | + <div class="col-sm-4 faded"> | ||
| 9 | + <div class="action-buttons text-left"> | ||
| 10 | + <a data-action="expand-entity-list-details" class="text-primary text-button"><i class="zmdi zmdi-wrap-text"></i>Toggle Details</a> | ||
| 11 | + </div> | ||
| 12 | + </div> | ||
| 13 | + <div class="col-sm-8 faded"> | ||
| 14 | + <div class="action-buttons"> | ||
| 15 | + | ||
| 16 | + </div> | ||
| 17 | + </div> | ||
| 18 | + </div> | ||
| 19 | + </div> | ||
| 20 | + </div> | ||
| 21 | + | ||
| 5 | <div class="container" ng-non-bindable> | 22 | <div class="container" ng-non-bindable> |
| 6 | <div class="row"> | 23 | <div class="row"> |
| 7 | 24 | ||
| 8 | - <div class="col-md-7"> | 25 | + <div class="col-sm-4"> |
| 9 | @if($signedIn) | 26 | @if($signedIn) |
| 10 | - <h2>My Recently Viewed</h2> | 27 | + <h3>My Recently Viewed</h3> |
| 11 | @else | 28 | @else |
| 12 | - <h2>Recent Books</h2> | 29 | + <h3>Recent Books</h3> |
| 13 | @endif | 30 | @endif |
| 14 | - @include('partials/entity-list', ['entities' => $recents]) | 31 | + @include('partials/entity-list', ['entities' => $recents, 'size' => 'compact']) |
| 32 | + </div> | ||
| 33 | + | ||
| 34 | + <div class="col-sm-4"> | ||
| 35 | + <h3>Recently Created Pages</h3> | ||
| 36 | + @include('partials/entity-list', ['entities' => $recentlyCreatedPages, 'size' => 'compact']) | ||
| 37 | + <h3>Recently Updated Pages</h3> | ||
| 38 | + @include('partials/entity-list', ['entities' => $recentlyCreatedPages, 'size' => 'compact']) | ||
| 15 | </div> | 39 | </div> |
| 16 | 40 | ||
| 17 | - <div class="col-md-4 col-md-offset-1" id="recent-activity"> | 41 | + <div class="col-sm-4" id="recent-activity"> |
| 18 | - <div class="margin-top large"> </div> | ||
| 19 | <h3>Recent Activity</h3> | 42 | <h3>Recent Activity</h3> |
| 20 | @include('partials/activity-list', ['activity' => $activity]) | 43 | @include('partials/activity-list', ['activity' => $activity]) |
| 21 | </div> | 44 | </div> | ... | ... |
| 1 | 1 | ||
| 2 | -@if(count($entities) > 0) | 2 | +<div class="entity-list @if(isset($size)){{ $size }}@endif"> |
| 3 | - @foreach($entities as $index => $entity) | 3 | + @if(count($entities) > 0) |
| 4 | - @if($entity->isA('page')) | 4 | + @foreach($entities as $index => $entity) |
| 5 | - @include('pages/list-item', ['page' => $entity]) | 5 | + @if($entity->isA('page')) |
| 6 | - @elseif($entity->isA('book')) | 6 | + @include('pages/list-item', ['page' => $entity]) |
| 7 | - @include('books/list-item', ['book' => $entity]) | 7 | + @elseif($entity->isA('book')) |
| 8 | - @elseif($entity->isA('chapter')) | 8 | + @include('books/list-item', ['book' => $entity]) |
| 9 | - @include('chapters/list-item', ['chapter' => $entity, 'hidePages' => true]) | 9 | + @elseif($entity->isA('chapter')) |
| 10 | - @endif | 10 | + @include('chapters/list-item', ['chapter' => $entity, 'hidePages' => true]) |
| 11 | + @endif | ||
| 11 | 12 | ||
| 12 | - @if($index !== count($entities) - 1) | 13 | + @if($index !== count($entities) - 1) |
| 13 | - <hr> | 14 | + <hr> |
| 14 | - @endif | 15 | + @endif |
| 15 | 16 | ||
| 16 | - @endforeach | ||
| 17 | -@else | ||
| 18 | - <p class="text-muted"> | ||
| 19 | - No items available | ||
| 20 | - </p> | ||
| 21 | -@endif | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 17 | + @endforeach | ||
| 18 | + @else | ||
| 19 | + <p class="text-muted"> | ||
| 20 | + No items available | ||
| 21 | + </p> | ||
| 22 | + @endif | ||
| 23 | +</div> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment