From f1e571a57c03b4d1985f863443fff510cd95e0db Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 16 Feb 2019 17:13:01 +0000 Subject: [PATCH] Made shelf listing more unique & efficient - Now includes listing of all books within. --- app/Entities/Book.php | 2 +- app/Entities/Bookshelf.php | 2 +- app/Entities/Repos/EntityRepo.php | 13 ++++++++- app/Http/Controllers/BookshelfController.php | 4 ++- resources/assets/sass/_lists.scss | 29 ++++++++++++++++++++ resources/assets/sass/_pages.scss | 13 ++++++--- resources/views/books/list-item.blade.php | 1 + resources/views/shelves/list-item.blade.php | 19 ++++++++++--- resources/views/shelves/list.blade.php | 5 +++- 9 files changed, 75 insertions(+), 13 deletions(-) diff --git a/app/Entities/Book.php b/app/Entities/Book.php index 5ab5142c9..3bce3860c 100644 --- a/app/Entities/Book.php +++ b/app/Entities/Book.php @@ -38,7 +38,7 @@ class Book extends Entity */ public function getBookCover($width = 440, $height = 250) { - $default = baseUrl('/book_default_cover.png'); + $default = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='; if (!$this->image_id) { return $default; } diff --git a/app/Entities/Bookshelf.php b/app/Entities/Bookshelf.php index 6753c2882..d6a3cf0ef 100644 --- a/app/Entities/Bookshelf.php +++ b/app/Entities/Bookshelf.php @@ -51,7 +51,7 @@ class Bookshelf extends Entity public function getBookCover($width = 440, $height = 250) { // TODO - Make generic, focused on books right now, Perhaps set-up a better image - $default = baseUrl('/book_default_cover.png'); + $default = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='; if (!$this->image_id) { return $default; } diff --git a/app/Entities/Repos/EntityRepo.php b/app/Entities/Repos/EntityRepo.php index 15340c906..e5fd35407 100644 --- a/app/Entities/Repos/EntityRepo.php +++ b/app/Entities/Repos/EntityRepo.php @@ -182,15 +182,26 @@ class EntityRepo * @param int $count * @param string $sort * @param string $order + * @param null|callable $queryAddition * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator */ - public function getAllPaginated($type, int $count = 10, string $sort = 'name', string $order = 'asc') + public function getAllPaginated($type, int $count = 10, string $sort = 'name', string $order = 'asc', $queryAddition = null) { $query = $this->entityQuery($type); $query = $this->addSortToQuery($query, $sort, $order); + if ($queryAddition) { + $queryAddition($query); + } return $query->paginate($count); } + /** + * Add sorting operations to an entity query. + * @param Builder $query + * @param string $sort + * @param string $order + * @return Builder + */ protected function addSortToQuery(Builder $query, string $sort = 'name', string $order = 'asc') { $order = ($order === 'asc') ? 'asc' : 'desc'; diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index dd305be97..4ac943119 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -47,7 +47,9 @@ class BookshelfController extends Controller 'updated_at' => trans('common.sort_updated_at'), ]; - $shelves = $this->entityRepo->getAllPaginated('bookshelf', 18, $sort, $order); + $shelves = $this->entityRepo->getAllPaginated('bookshelf', 18, $sort, $order, function($query) { + $query->with(['books']); + }); $recents = $this->signedIn ? $this->entityRepo->getRecentlyViewed('bookshelf', 4, 0) : false; $popular = $this->entityRepo->getPopular('bookshelf', 4, 0); $new = $this->entityRepo->getRecentlyCreated('bookshelf', 4, 0); diff --git a/resources/assets/sass/_lists.scss b/resources/assets/sass/_lists.scss index c99f2ecf3..19c81066c 100644 --- a/resources/assets/sass/_lists.scss +++ b/resources/assets/sass/_lists.scss @@ -307,14 +307,43 @@ ul.pagination { background-color: #EEEEEE; } +.entity-list-item-children { + padding: $-m; + > div { + overflow: hidden; + padding: $-xs 0; + margin-top: -$-xs; + } + .entity-chip { + text-overflow: ellipsis; + height: 2.5em; + overflow: hidden; + text-align: left; + display: block; + white-space: nowrap; + } +} + .entity-list-item-image { align-self: stretch; width: 140px; + flex: none; background-size: cover; background-position: 50% 50%; border-radius: 3px; position: relative; margin-right: $-l; + + .svg-icon { + color: #FFF; + fill: #FFF; + font-size: 2rem; + margin-right: 0; + position: absolute; + bottom: $-xs; + left: $-xs; + } + @include smaller-than($m) { width: 80px; } diff --git a/resources/assets/sass/_pages.scss b/resources/assets/sass/_pages.scss index a260116c6..3ab5a6a69 100755 --- a/resources/assets/sass/_pages.scss +++ b/resources/assets/sass/_pages.scss @@ -389,20 +389,25 @@ justify-content: center; text-align: center; font-size: 0.9em; - border-radius: 2em; + border-radius: 3px; position: relative; overflow: hidden; - padding: $-xs $-m; - color: #666; + padding: $-xs $-s; fill: currentColor; + opacity: 0.85; + transition: opacity ease-in-out 120ms; &:after { content: ''; position: absolute; background-color: currentColor; - opacity: 0.2; + opacity: 0.15; left: 0; top: 0; width: 100%; height: 100%; } + &:hover { + text-decoration: none; + opacity: 1; + } } \ No newline at end of file diff --git a/resources/views/books/list-item.blade.php b/resources/views/books/list-item.blade.php index 966f67b22..17cf4c71f 100644 --- a/resources/views/books/list-item.blade.php +++ b/resources/views/books/list-item.blade.php @@ -1,5 +1,6 @@
+ @icon('book')

{{ $book->name }}

diff --git a/resources/views/shelves/list-item.blade.php b/resources/views/shelves/list-item.blade.php index 6b6d19a7e..5766ca755 100644 --- a/resources/views/shelves/list-item.blade.php +++ b/resources/views/shelves/list-item.blade.php @@ -1,10 +1,21 @@
-
+
+ @icon('bookshelf')
-
+

{{ $shelf->name }}

-

{{ $shelf->getExcerpt() }}

+

{{ $shelf->getExcerpt() }}

-
\ No newline at end of file + +
+ @foreach($shelf->books as $book) + + @endforeach +
\ No newline at end of file diff --git a/resources/views/shelves/list.blade.php b/resources/views/shelves/list.blade.php index a914eba49..84a0ded0d 100644 --- a/resources/views/shelves/list.blade.php +++ b/resources/views/shelves/list.blade.php @@ -12,7 +12,10 @@ @if(count($shelves) > 0) @if($view === 'list')
- @foreach($shelves as $shelf) + @foreach($shelves as $index => $shelf) + @if ($index !== 0) +
+ @endif @include('shelves.list-item', ['shelf' => $shelf]) @endforeach