]> BookStack Code Mirror - bookstack/commitdiff
Made shelf listing more unique & efficient
authorDan Brown <redacted>
Sat, 16 Feb 2019 17:13:01 +0000 (17:13 +0000)
committerDan Brown <redacted>
Sat, 16 Feb 2019 17:13:01 +0000 (17:13 +0000)
- Now includes listing of all books within.

app/Entities/Book.php
app/Entities/Bookshelf.php
app/Entities/Repos/EntityRepo.php
app/Http/Controllers/BookshelfController.php
resources/assets/sass/_lists.scss
resources/assets/sass/_pages.scss
resources/views/books/list-item.blade.php
resources/views/shelves/list-item.blade.php
resources/views/shelves/list.blade.php

index 5ab5142c9f097d5c654f5d99e08b8d2efad2d113..3bce3860c9572119bd7997b421e161c96d7c4197 100644 (file)
@@ -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;
         }
index 6753c2882e80f8a8bae90d2bbe96e4f13de00dd5..d6a3cf0efec3cbd3f00da5b1b74b29a27b57960e 100644 (file)
@@ -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;
         }
index 15340c90693706340234ab7b959a1cfbaab41d1f..e5fd35407ce09f1ac9adac62fee0a9fcc4af5b02 100644 (file)
@@ -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';
index dd305be97ce9b631bfc7233572dc768d176d270c..4ac9431191d37e6f6c430d26681d6cfa30d8a5dd 100644 (file)
@@ -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);
index c99f2ecf3a72744d2e7791bc1ccecb67bc29a3d5..19c81066c09460dda28ebd0fb719d4e769ce92df 100644 (file)
@@ -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;
   }
index a260116c64ef21f1d5198d91fc3f28b00cdb58b9..3ab5a6a691e112f602e8311ed98f07488a7b55da 100755 (executable)
   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
index 966f67b226f9d8a28cb807b930e5b6f9a2e3d903..17cf4c71f9878117471b6afef38f3eccff615331 100644 (file)
@@ -1,5 +1,6 @@
 <a href="{{ $book->getUrl() }}" class="book entity-list-item" data-entity-type="book" data-entity-id="{{$book->id}}">
     <div class="entity-list-item-image bg-book" style="background-image: url('{{ $book->getBookCover() }}')">
+        @icon('book')
     </div>
     <div class="content">
         <h4 class="entity-list-item-name break-text">{{ $book->name }}</h4>
index 6b6d19a7e56678e032f9211c80a9be8b38747820..5766ca75590ef5cf79f4c0fcfc641085c7a22569 100644 (file)
@@ -1,10 +1,21 @@
 <a href="{{ $shelf->getUrl() }}" class="shelf entity-list-item" data-entity-type="bookshelf" data-entity-id="{{$shelf->id}}">
-    <div class="entity-list-item-image bg-shelf" style="background-image: url('{{ $shelf->getBookCover() }}')">
+    <div class="entity-list-item-image bg-shelf @if($shelf->image_id) has-image @endif" style="background-image: url('{{ $shelf->getBookCover() }}')">
+        @icon('bookshelf')
     </div>
-    <div class="content">
+    <div class="content py-xs">
         <h4 class="entity-list-item-name break-text">{{ $shelf->name }}</h4>
         <div class="entity-item-snippet">
-            <p class="text-muted break-text mb-s">{{ $shelf->getExcerpt() }}</p>
+            <p class="text-muted break-text mb-none">{{ $shelf->getExcerpt() }}</p>
         </div>
     </div>
-</a>
\ No newline at end of file
+</a>
+<div class="entity-shelf-books grid third entity-list-item-children">
+    @foreach($shelf->books as $book)
+        <div>
+            <a href="{{ $book->getUrl() }}" class="entity-chip text-book">
+                @icon('book')
+                {{ $book->name }}
+            </a>
+        </div>
+    @endforeach
+</div>
\ No newline at end of file
index a914eba4972d5393c992e609dd9c0913399bbe6a..84a0ded0ddfd792628c5641cc8f3c0ba4cc3933e 100644 (file)
     @if(count($shelves) > 0)
         @if($view === 'list')
             <div class="entity-list">
-                @foreach($shelves as $shelf)
+                @foreach($shelves as $index => $shelf)
+                    @if ($index !== 0)
+                        <hr class="my-m">
+                    @endif
                     @include('shelves.list-item', ['shelf' => $shelf])
                 @endforeach
             </div>