]> BookStack Code Mirror - bookstack/commitdiff
Converted books view setting to user setting
authorDan Brown <redacted>
Wed, 6 Dec 2017 16:34:26 +0000 (16:34 +0000)
committerDan Brown <redacted>
Wed, 6 Dec 2017 16:34:26 +0000 (16:34 +0000)
Also cleaned up/moved new CSS and removed redundant new book methods.

app/Book.php
app/Http/Controllers/BookController.php
app/User.php
database/migrations/2017_08_29_102650_add_cover_image_display.php
resources/assets/js/global.js
resources/assets/sass/_grid.scss
resources/assets/sass/_lists.scss
resources/assets/sass/styles.scss
resources/views/books/grid-item.blade.php
resources/views/users/edit.blade.php
tests/UserProfileTest.php

index fed602332bb18c41489f0008793bf3b1228eb24d..15fbbe5ff737a2f692a35552ecdf62b5669a3017 100644 (file)
@@ -21,15 +21,14 @@ class Book extends Entity
     /**
      * Returns book cover image, if book cover not exists return default cover image.
      * @param int $height - Height of the image
-     * @param type $width - Width of the image
-     * @return type string
+     * @param int $width - Width of the image
+     * @return string
      */
     public function getBookCover($height = 170, $width = 300)
     {
         $default = baseUrl('/book_default_cover.png');
-        $image = $this->image_id;
-        if ($image === 0 || $image === '0' || $image === null) 
-            return $default;
+        if (!$this->image_id) return $default;
+
         try {
             $cover = $this->cover ? baseUrl($this->cover->getThumb($width, $height, false)) : $default;
         } catch (\Exception $err) {
@@ -38,17 +37,6 @@ class Book extends Entity
         return $cover;
     }
     
-    /**
-     * Get an excerpt of this book's name to the specified length or less.
-     * @param int $length
-     * @return string
-     */
-    public function getHeadingExcerpt($length = 35)
-    {
-        $bookHeading = $this->name;
-        return strlen($bookHeading) > $length ? substr($bookHeading, 0, $length-3) . '...' : $bookHeading;
-    }
-    
     /**
      * Get the cover image of the book
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
@@ -103,14 +91,5 @@ class Book extends Entity
     {
         return "'BookStack\\\\Book' as entity_type, id, id as entity_id, slug, name, {$this->textField} as text,'' as html, '0' as book_id, '0' as priority, '0' as chapter_id, '0' as draft, created_by, updated_by, updated_at, created_at";
     }
-    
-    /**
-     * Get the user that created the page revision
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
-     */
-    public function createdBy()
-    {   
-        return $this->belongsTo(User::class, 'created_by');
-    }
 
 }
index 2d961355be84f1ea740fb1e16db09c6358a21436..e181aec8967285956ab5f707dc9a4fd09e326bf7 100644 (file)
@@ -40,8 +40,8 @@ class BookController extends Controller
         $recents = $this->signedIn ? $this->entityRepo->getRecentlyViewed('book', 4, 0) : false;
         $popular = $this->entityRepo->getPopular('book', 4, 0);
         $new = $this->entityRepo->getRecentlyCreated('book', 4, 0);
-        $booksViewType = $this->currentUser->books_view_type;
-        $this->setPageTitle('Books');
+        $booksViewType = setting()->getUser($this->currentUser, 'books_view_type', 'list');
+        $this->setPageTitle(trans('entities.books'));
         return view('books/index', [
             'books' => $books,
             'recents' => $recents,
index 264723be9c615a8477ea47fd1be670c3756cf405..8033557e4cb9a0a048c1d7112c90f84dc4e4bf70 100644 (file)
@@ -22,7 +22,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
      * The attributes that are mass assignable.
      * @var array
      */
-    protected $fillable = ['name', 'email', 'image_id', 'books_view_type' ];
+    protected $fillable = ['name', 'email', 'image_id'];
 
     /**
      * The attributes excluded from the model's JSON form.
index a8bba51c8c7ee35cc87116f55c7695410d1b4545..6f99329243a73a8c18cee8b48e667fce15f4b87f 100644 (file)
@@ -13,12 +13,8 @@ class AddCoverImageDisplay extends Migration
      */
     public function up()
     {
-        Schema::table('users', function (Blueprint $table) {
-            $table->string('books_view_type',10)->default('grid');
-        });
-
         Schema::table('books', function (Blueprint $table) {
-            $table->integer('image_id');
+            $table->integer('image_id')->nullable()->default(null);
         });
     }
 
@@ -29,10 +25,6 @@ class AddCoverImageDisplay extends Migration
      */
     public function down()
     {
-        Schema::table('users', function (Blueprint $table) {
-            $table->dropColumn('books_view_type');
-        });
-
         Schema::table('books', function (Blueprint $table) {
             $table->dropColumn('image_id');
         });
index f746b28612dff39befb3f6b53b0f07e5bebc7549..352616c5a2e00c73a7b88e521f84e9eca414b76c 100644 (file)
@@ -119,19 +119,6 @@ jQuery.expr[":"].contains = $.expr.createPseudo(function (arg) {
     };
 });
 
-// Common jQuery actions
-$('[data-action="expand-entity-list-details"]').click(function() {
-    $('.entity-list.compact').find('p').not('.empty-text').slideToggle(240);
-});
-
-// Toggle thumbnail::hide image and reduce grid size
-$(document).ready(function(){
-   $('[data-action="expand-thumbnail"]').click(function(){
-     $('.gallery-item').toggleClass("collapse").find('img').slideToggle(50);
-   });
-});
-
-
 // Detect IE for css
 if(navigator.userAgent.indexOf('MSIE')!==-1
     || navigator.appVersion.indexOf('Trident/') > 0
index 0f755e9f0cf10bbda66ba50e2aa7bf081af6d17e..b42ad37bba95fbeaae2ebce887df6bbf0b20ecb1 100644 (file)
@@ -195,6 +195,14 @@ div[class^="col-"] img {
   display: inline-block;
 }
 
+@include larger-than(991px) {
+  .row.auto-clear .col-md-4:nth-child(3n+1){clear:left;}
+}
+
+@include smaller-than(992px) {
+  .row.auto-clear .col-xs-6:nth-child(2n+1){clear:left;}
+}
+
 .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 {
   position: relative;
   min-height: 1px;
index d30d4d4a22ab98745b5f7b1076db90297dc2fde0..4bc31bbb030d5cdcf331c14f5851684f367e7e72 100644 (file)
@@ -373,3 +373,51 @@ ul.pagination {
     border-bottom: 1px solid #DDD;
   }
 }
+
+// Books grid view
+.featured-image-container {
+  position: relative;
+  overflow: hidden;
+  background: #F2F2F2;
+  border: 1px solid #ddd;
+  border-bottom: 0;
+  img {
+    display: block;
+    max-width: 100%;
+    height: auto;
+    transition: all .5s ease;
+  }
+  img:hover {
+    transform: scale(1.15);
+    opacity: .5;
+  }
+}
+
+.book-grid-content {
+  padding: 30px;
+  border: 1px solid #ddd;
+  border-top: 0;
+  border-bottom-width: 2px;
+  h2 {
+    font-size: 1.5em;
+    margin: 0 0 10px;
+  }
+  h2 a {
+    display: block;
+    line-height: 1.2;
+    color: #009688;;
+    text-decoration: none;
+  }
+  p {
+    font-size: .85em;
+    margin: 0 0 10px;
+    line-height: 1.6em;
+  }
+  p.small {
+    font-size: .8em;
+  }
+}
+
+.book-grid-item {
+  margin-bottom : 20px;
+}
index 730cc8a65b989729573fbf5e65854434ef220083..6a80237c5b6a674b9cd4763408e6b82a95002f3c 100644 (file)
@@ -231,75 +231,4 @@ $btt-size: 40px;
   input {
     width: 100%;
   }
-}
-
-// styles for Books grid view
-.cover {
-    width: 290px;
-    border-radius: 3px;
-  }
-
-.featured-image-container {
-    position: relative;
-    overflow: hidden;
-    background: #F2F2F2;
-    border: 1px solid #ddd;
-    border-bottom: 0px;
-}
-
-.featured-image-container img {
-    display: block;
-    max-width: 100%;
-    height: auto;
-    -webkit-transition: all .5s ease;
-    -moz-transition: all .5s ease;
-    -ms-transition: all .5s ease;
-    -o-transition: all .5s ease;
-    transition: all .5s ease;
-}
-
-.book-content {
-    padding: 30px;
-    border: 1px solid #ddd;
-    border-top: 0px;
-    border-bottom-width: 2px;
-}
-.book-content h2 {
-    font-size: 1.5em;
-    line-height: 1.2;
-    margin: 0 0 10px;
-}
-
-.book-content  h2 a {
-    display: block;
-    color: #009688;;
-    text-decoration: none;
-}
-
-.book-content p {
-    font-size: .85em;
-    margin: 0 0 10px;
-    line-height: 1.6em;
-}
-
-.featured-image-container img:hover {
-    -webkit-transform: scale(1.15);
-    -moz-transform: scale(1.15);
-    -ms-transform: scale(1.15);
-    -o-transform: scale(1.15);
-    transform: scale(1.15);
-    opacity: .5;
-}
-.books-grid-div {
-    margin-bottom : 20px;
-}
-
-@media (min-width:992px){
-    .row.auto-clear .col-md-4:nth-child(3n+1){clear:left;}
-}
-@media (min-width:992px){
-    .row.auto-clear .col-md-4:nth-child(3n+1){clear:left;}
-}
-@media (max-width:991px){
-    .row.auto-clear .col-xs-6:nth-child(2n+1){clear:left;}
 }
\ No newline at end of file
index 74801ec845a83f5c9f34d1c9564a1711d702ffe4..cb2b447b07178a1df7e51b803a64d4540ac9a988 100644 (file)
@@ -1,13 +1,13 @@
-<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 books-grid-div"  data-entity-type="book" data-entity-id="{{$book->id}}">
+<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 book-grid-item"  data-entity-type="book" data-entity-id="{{$book->id}}">
     <div class="featured-image-container">
         <a href="{{$book->getUrl()}}" title="{{$book->name}}">
             <img width="1600" height="900" src="{{$book->getBookCover()}}" alt="{{$book->name}}">
         </a>
     </div>
-    <div class="book-content">
-        <h2><a href="{{$book->getUrl()}}" title="{{$book->name}}" > {{$book->getHeadingExcerpt()}} </a></h2>
+    <div class="book-grid-content">
+        <h2><a href="{{$book->getUrl()}}" title="{{$book->name}}" > {{$book->getShortName(35)}} </a></h2>
         @if(isset($book->searchSnippet))
-            <p >{{!! $book->searchSnippet !!}}</p>
+            <p >{!! $book->searchSnippet !!}</p>
         @else
             <p >{{ $book->getExcerpt(130) }}</p>
         @endif
index 00db029070f32657f626b4679e0778db83b70070..14ab19e0e9b97a1c651d80c9605243a7b8a8d9ca 100644 (file)
@@ -45,9 +45,9 @@
                             </div>
                             <div class="form-group">
                                 <label for="books-view-type">{{ trans('settings.users_books_view_type') }}</label>
-                                <select name="books_view_type" id="books-view-type">
-                                    <option @if($user->books_view_type === 'grid') selected @endif value="grid">Grid</option>
-                                    <option @if($user->books_view_type === 'list') selected @endif value="list">List</option>
+                                <select name="setting[books_view_type]" id="books-view-type">
+                                    <option @if(setting()->getUser($user, 'books_view_type', 'list') === 'list') selected @endif value="list">List</option>
+                                    <option @if(setting()->getUser($user, 'books_view_type', 'list') === 'grid') selected @endif value="grid">Grid</option>
                                 </select>
                             </div>
                         </div>
index 4636fc76cf5b3747fed6a0ae45a6357896c9a7f6..0c66363f0b34a0e8c241108d8675b7a29ca67105 100644 (file)
@@ -97,9 +97,8 @@ class UserProfileTest extends BrowserKitTest
 
     public function test_books_view_is_list()
     {
-        $editor = $this->getEditor([
-          'books_view_type' => 'list'
-        ]);
+        $editor = $this->getEditor();
+        setting()->putUser($editor, 'books_view_type', 'list');
 
         $this->actingAs($editor)
             ->visit('/books')
@@ -109,9 +108,8 @@ class UserProfileTest extends BrowserKitTest
 
     public function test_books_view_is_grid()
     {
-        $editor = $this->getEditor([
-          'books_view_type' => 'grid'
-        ]);
+        $editor = $this->getEditor();
+        setting()->putUser($editor, 'books_view_type', 'grid');
 
         $this->actingAs($editor)
             ->visit('/books')