]> BookStack Code Mirror - bookstack/commitdiff
Applied required changes in BookStack.
authorNilesh Deepak <redacted>
Wed, 5 Jul 2017 06:39:01 +0000 (12:09 +0530)
committerNilesh Deepak <redacted>
Wed, 5 Jul 2017 06:39:01 +0000 (12:09 +0530)
app/Book.php
app/Http/Controllers/BookController.php
app/User.php
database/migrations/2014_10_12_000000_create_users_table.php
database/migrations/2015_07_12_114933_create_books_table.php
resources/assets/sass/styles.scss
resources/views/books/index.blade.php
resources/views/users/edit.blade.php

index 06c00945d43c4dbdea946c21769ffef7a626888f..67bd4f5b224f19bd63017acaf3f76872cb9e83f6 100644 (file)
@@ -3,7 +3,7 @@
 class Book extends Entity
 {
 
-    protected $fillable = ['name', 'description'];
+    protected $fillable = ['name', 'description', 'image'];
 
     /**
      * Get the url for this book.
index 086929558ff55c08412369c8cd48a753c67c5d42..9c1154281be3f47b01ed10ab8efbd73c5db2daee 100644 (file)
@@ -36,11 +36,12 @@ class BookController extends Controller
      */
     public function index()
     {
-        $books = $this->entityRepo->getAllPaginated('book', 10);
+        $books = $this->entityRepo->getAllPaginated('book', 16);
         $recents = $this->signedIn ? $this->entityRepo->getRecentlyViewed('book', 4, 0) : false;
-        $popular = $this->entityRepo->getPopular('book', 4, 0);
+        $popular = $this->entityRepo->getPopular('book', 3, 0);
+        $books_display = $this->currentUser->books_display;
         $this->setPageTitle('Books');
-        return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular, 'display' => $display]);  //added displaly to access user display
+        return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular, 'books_display' => $books_display]);
     }
 
     /**
@@ -68,10 +69,7 @@ class BookController extends Controller
             'description' => 'string|max:1000'
         ]);
         $image = $request->file('image');
-        $input = time().'-'.$image->getClientOriginalName();
-        $destinationPath = public_path('uploads/book/');
-        $image->move($destinationPath, $input);
-        $path = baseUrl('/uploads/book/').'/'.$input;
+        $path = $this->getBookCoverURL($image);
         $book = $this->entityRepo->createFromInput('book', $request->all());
         $book->image = $path; 
         $book->save();
@@ -121,12 +119,8 @@ class BookController extends Controller
             'name' => 'required|string|max:255',
             'description' => 'string|max:1000'
         ]);
-            
-            $input = $request->file('image')->getClientOriginalName();
-            echo $input;
-         $destinationPath = public_path('uploads/book/');
-         $request->file('image')->move($destinationPath, $input);
-         $path = baseUrl('/uploads/book/').'/'.$input;
+         $image = $request->file('image');
+         $path = $this->getBookCoverURL($image);
          $book = $this->entityRepo->updateFromInput('book', $book, $request->all());
          $book->image = $path; 
          $book->save();
@@ -134,6 +128,20 @@ class BookController extends Controller
          return redirect($book->getUrl());
     }
 
+    /**
+     * Generate URL for book cover image
+     * @param  $image
+     * @return $path
+     */
+    public function getBookCoverURL($image)
+    {
+         $input = time().'-'.$image->getClientOriginalName();
+         $destinationPath = public_path('uploads/book/');
+         $image->move($destinationPath, $input);
+         $path = baseUrl('/uploads/book/').'/'.$input;
+         return $path;
+    }
+
     /**
      * Shows the page to confirm deletion
      * @param $bookSlug
index 3d77cd8ee009cfe0f4a57d27779f3b52fa4b4b75..24eca12f31c2f5d9d665830b7089c88fa6076b27 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', 'display']; //to write in user database 
+    protected $fillable = ['name', 'email', 'image_id', 'books_display'];
 
     /**
      * The attributes excluded from the model's JSON form.
index 17e71de5f99d933aaafb7d6996cb337203a468da..62ac94b606d91605c50b70a1d8b8b768335aebca 100644 (file)
@@ -18,6 +18,7 @@ class CreateUsersTable extends Migration
             $table->string('email')->unique();
             $table->string('password', 60);
             $table->rememberToken();
+            $table->string('books_display')->default('grid');
             $table->nullableTimestamps();
         });
 
@@ -26,6 +27,7 @@ class CreateUsersTable extends Migration
             'name' => 'Admin',
             'email' => '[email protected]',
             'password' => bcrypt('password'),
+            'books_display' => 'grid',
             'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
             'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
         ]);
index 4220809d56e5145e1be711392f618e066de59d9c..b8a6c9829f43e9d30c9f3cc7bd1983fee793d6f9 100644 (file)
@@ -24,6 +24,7 @@ class CreateBooksTable extends Migration
             $table->string('slug')->indexed();
             $table->text('description');
             $table->nullableTimestamps();
+            $table->string('image');
         });
     }
 
index afb9d531bd4a82ae8b17410083f97e1f6b0ab875..bfa95fc1e45ff8c842a7e42b2de1826eb525bc61 100644 (file)
@@ -276,3 +276,28 @@ $btt-size: 40px;
 
 
 
+.galleryItem {
+  width: 22%;
+  padding: 5px;
+  float: left;
+  height: 330px;
+  margin: 2% 1% 2% 1%;
+  overflow: hidden;
+  border: 1px solid #9e9e9e;
+  h3 {
+    font-size: 1.2em;
+    text-align: center;
+  }
+  p {
+    font-size: 0.8em;
+    text-align: center;
+  }
+  img {
+    height: 192px;
+    width: 120px;
+    margin-top: 5%;
+  }
+  &.collapse {
+    height: 130px;
+  }
+}
\ No newline at end of file
index 693c909aae5634fa61324e624ece4ec4143f3148..de13ab5cde63b2cfa92079ff6a13284b9b00ebfa 100644 (file)
@@ -24,7 +24,7 @@
                 <h1>{{ trans('entities.books') }}</h1>
                 {!! $books->render() !!}
                 @if(count($books) > 0)
-                    @if($display=='grid')
+                    @if($books_display=='grid')
                         @foreach($books as $book)
                             @include('books/grid-item', ['book' => $book])
                         @endforeach
index 3cacff645f378f1879654ab12db02864602188ea..152567d6c314790c1b95c69738f2ac36c306dc3e 100644 (file)
                             @endforeach
                         </select>
                     </div>
-                    <!--Select display type -->
                     <div class="form-group">
-                        <label for="display">Type of view</label>
-                        <select name="display" id="display">
-                            <option @if($user->display === 'grid') selected @endif value="grid">Grid</option>
-                            <option @if($user->display === 'list') selected @endif value="list">List</option>
+                        <label for="books_display">Type of view</label>
+                        <select name="books_display" id="books_display">
+                            <option @if($user->books_display === 'grid') selected @endif value="grid">Grid</option>
+                            <option @if($user->books_display === 'list') selected @endif value="list">List</option>
                         </select>
                     </div>
-                    <!---->
                 </div>
             </div>
             <div class="form-group">