From 8eb2960950648c04c4a6d6facb913eaac81eabc4 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 20 Feb 2016 18:51:01 +0000 Subject: [PATCH] Added recently created & updated page listings Closes #46. --- app/Http/Controllers/PageController.php | 26 +++++++ app/Http/routes.php | 5 ++ app/Repos/PageRepo.php | 17 +++++ resources/assets/sass/_header.scss | 48 ------------ resources/assets/sass/_lists.scss | 75 +++++++++++++++++-- resources/assets/sass/_text.scss | 5 ++ resources/views/home.blade.php | 11 +-- .../views/pages/detailed-listing.blade.php | 18 +++++ resources/views/pages/list-item.blade.php | 29 ++++--- .../views/partials/entity-list.blade.php | 2 +- resources/views/search/all.blade.php | 2 +- tests/EntityTest.php | 18 +++++ 12 files changed, 185 insertions(+), 71 deletions(-) create mode 100644 resources/views/pages/detailed-listing.blade.php diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index b4ab9682b..2dbdb81e7 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -278,4 +278,30 @@ class PageController extends Controller ]); } + /** + * Show a listing of recently created pages + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function showRecentlyCreated() + { + $pages = $this->pageRepo->getRecentlyCreatedPaginated(20); + return view('pages/detailed-listing', [ + 'title' => 'Recently Created Pages', + 'pages' => $pages + ]); + } + + /** + * Show a listing of recently created pages + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function showRecentlyUpdated() + { + $pages = $this->pageRepo->getRecentlyUpdatedPaginated(20); + return view('pages/detailed-listing', [ + 'title' => 'Recently Updated Pages', + 'pages' => $pages + ]); + } + } diff --git a/app/Http/routes.php b/app/Http/routes.php index 02b2fa217..f753ad915 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -3,6 +3,11 @@ // Authenticated routes... Route::group(['middleware' => 'auth'], function () { + Route::group(['prefix' => 'pages'], function() { + Route::get('/recently-created', 'PageController@showRecentlyCreated'); + Route::get('/recently-updated', 'PageController@showRecentlyUpdated'); + }); + Route::group(['prefix' => 'books'], function () { // Books diff --git a/app/Repos/PageRepo.php b/app/Repos/PageRepo.php index 05052432e..25b869bc3 100644 --- a/app/Repos/PageRepo.php +++ b/app/Repos/PageRepo.php @@ -358,5 +358,22 @@ class PageRepo $page->delete(); } + /** + * Get the latest pages added to the system. + * @param $count + */ + public function getRecentlyCreatedPaginated($count = 20) + { + return $this->page->orderBy('created_at', 'desc')->paginate($count); + } + + /** + * Get the latest pages added to the system. + * @param $count + */ + public function getRecentlyUpdatedPaginated($count = 20) + { + return $this->page->orderBy('updated_at', 'desc')->paginate($count); + } } \ No newline at end of file diff --git a/resources/assets/sass/_header.scss b/resources/assets/sass/_header.scss index 2f06532c0..1edfc0037 100644 --- a/resources/assets/sass/_header.scss +++ b/resources/assets/sass/_header.scss @@ -139,54 +139,6 @@ form.search-box { height: 43px; } -.dropdown-container { - display: inline-block; - vertical-align: top; - position: relative; -} - -.dropdown-container ul { - display: none; - position: absolute; - z-index: 999; - top: 0; - list-style: none; - right: 0; - margin: $-m 0; - background-color: #FFFFFF; - box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.1); - border-radius: 1px; - border: 1px solid #EEE; - min-width: 180px; - padding: $-xs 0; - color: #555; - text-align: left !important; - &.wide { - min-width: 220px; - } - .text-muted { - color: #999; - } - a { - display: block; - padding: $-xs $-m; - color: #555; - &:hover { - text-decoration: none; - background-color: #EEE; - } - i { - margin-right: $-m; - padding-right: 0; - display: inline; - width: 22px; - } - } - li.border-bottom { - border-bottom: 1px solid #DDD; - } -} - .breadcrumbs span.sep { color: #aaa; padding: 0 $-xs; diff --git a/resources/assets/sass/_lists.scss b/resources/assets/sass/_lists.scss index d3f68ca2e..f0bd3b1ea 100644 --- a/resources/assets/sass/_lists.scss +++ b/resources/assets/sass/_lists.scss @@ -285,17 +285,30 @@ ul.pagination { } } -.entity-list.compact { - font-size: 0.6em; - > div { +.entity-list { + >div { padding: $-m 0; } - h3, a { - line-height: 1.2; - } h3 { margin: 0; } + p { + margin: $-xs 0 0 0; + } + hr { + margin: 0; + } + .text-small.text-muted { + color: #AAA; + font-size: 0.75em; + margin-top: $-xs; + } +} +.entity-list.compact { + font-size: 0.6em; + h3, a { + line-height: 1.2; + } p { display: none; font-size: $fs-m * 0.8; @@ -305,4 +318,52 @@ ul.pagination { hr { margin: 0; } -} \ No newline at end of file +} + +.dropdown-container { + display: inline-block; + vertical-align: top; + position: relative; +} + +.dropdown-container ul { + display: none; + position: absolute; + z-index: 999; + top: 0; + list-style: none; + right: 0; + margin: $-m 0; + background-color: #FFFFFF; + box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.1); + border-radius: 1px; + border: 1px solid #EEE; + min-width: 180px; + padding: $-xs 0; + color: #555; + text-align: left !important; + &.wide { + min-width: 220px; + } + .text-muted { + color: #999; + } + a { + display: block; + padding: $-xs $-m; + color: #555; + &:hover { + text-decoration: none; + background-color: #EEE; + } + i { + margin-right: $-m; + padding-right: 0; + display: inline; + width: 22px; + } + } + li.border-bottom { + border-bottom: 1px solid #DDD; + } +} diff --git a/resources/assets/sass/_text.scss b/resources/assets/sass/_text.scss index 4f14837a0..ec42fe080 100644 --- a/resources/assets/sass/_text.scss +++ b/resources/assets/sass/_text.scss @@ -254,10 +254,15 @@ ol { .text-bigger { font-size: 1.1em; } + .text-large { font-size: 1.6666em; } +.no-color { + color: inherit; +} + /** * Grouping */ diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index daed0e975..8aaae1e1b 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -28,14 +28,15 @@ @else

Recent Books

@endif - @include('partials/entity-list', ['entities' => $recents, 'size' => 'compact']) + @include('partials/entity-list', ['entities' => $recents, 'style' => 'compact'])
-

Recently Created Pages

- @include('partials/entity-list', ['entities' => $recentlyCreatedPages, 'size' => 'compact']) -

Recently Updated Pages

- @include('partials/entity-list', ['entities' => $recentlyCreatedPages, 'size' => 'compact']) +

Recently Created Pages

+ @include('partials/entity-list', ['entities' => $recentlyCreatedPages, 'style' => 'compact']) + +

Recently Updated Pages

+ @include('partials/entity-list', ['entities' => $recentlyCreatedPages, 'style' => 'compact'])
diff --git a/resources/views/pages/detailed-listing.blade.php b/resources/views/pages/detailed-listing.blade.php new file mode 100644 index 000000000..85b77fae1 --- /dev/null +++ b/resources/views/pages/detailed-listing.blade.php @@ -0,0 +1,18 @@ +@extends('base') + +@section('content') + +
+
+ +
+

{{ $title }}

+ @include('partials/entity-list', ['entities' => $pages, 'style' => 'detailed']) + {!! $pages->links() !!} +
+ +
+ +
+
+@stop \ No newline at end of file diff --git a/resources/views/pages/list-item.blade.php b/resources/views/pages/list-item.blade.php index 37fe9e66a..5271680ab 100644 --- a/resources/views/pages/list-item.blade.php +++ b/resources/views/pages/list-item.blade.php @@ -3,18 +3,29 @@ {{ $page->name }} - @if(isset($showMeta) && $showMeta) -
- {{ $page->book->name }} - @if($page->chapter) - {{ $page->chapter->name }} - @endif -
- @endif - @if(isset($page->searchSnippet))

{!! $page->searchSnippet !!}

@else

{{ $page->getExcerpt() }}

@endif + + @if(isset($style) && $style === 'detailed') +
+
+ Created {{$page->created_at->diffForHumans()}} @if($page->createdBy)by {{$page->createdBy->name}}@endif
+ Last updated {{ $page->updated_at->diffForHumans() }} @if($page->updatedBy)by {{$page->updatedBy->name}} @endif +
+
+ {{ $page->book->getExcerpt(30) }} +
+ @if($page->chapter) + {{ $page->chapter->getExcerpt(30) }} + @else + Page is not in a chapter + @endif +
+
+ @endif + +
\ No newline at end of file diff --git a/resources/views/partials/entity-list.blade.php b/resources/views/partials/entity-list.blade.php index 729f346e3..a52e5f013 100644 --- a/resources/views/partials/entity-list.blade.php +++ b/resources/views/partials/entity-list.blade.php @@ -1,5 +1,5 @@ -
+
@if(count($entities) > 0) @foreach($entities as $index => $entity) @if($entity->isA('page')) diff --git a/resources/views/search/all.blade.php b/resources/views/search/all.blade.php index e0920dacc..e944ca03a 100644 --- a/resources/views/search/all.blade.php +++ b/resources/views/search/all.blade.php @@ -13,7 +13,7 @@
@if(count($pages) > 0) @foreach($pages as $page) - @include('pages/list-item', ['page' => $page, 'showMeta' => true]) + @include('pages/list-item', ['page' => $page, 'style' => 'detailed'])
@endforeach @else diff --git a/tests/EntityTest.php b/tests/EntityTest.php index 5bfedb535..0c0a1dee4 100644 --- a/tests/EntityTest.php +++ b/tests/EntityTest.php @@ -250,5 +250,23 @@ class EntityTest extends TestCase ->click('Revisions')->seeStatusCode(200); } + public function test_recently_created_pages_view() + { + $user = $this->getNewUser(); + $content = $this->createEntityChainBelongingToUser($user); + + $this->asAdmin()->visit('/pages/recently-created') + ->seeInNthElement('.entity-list .page', 0, $content['page']->name); + } + + public function test_recently_updated_pages_view() + { + $user = $this->getNewUser(); + $content = $this->createEntityChainBelongingToUser($user); + + $this->asAdmin()->visit('/pages/recently-updated') + ->seeInNthElement('.entity-list .page', 0, $content['page']->name); + } + }