From 947c58f2274f0e5a698e71486f8fae5a894111b5 Mon Sep 17 00:00:00 2001 From: Nilesh Deepak Date: Wed, 5 Jul 2017 12:09:01 +0530 Subject: [PATCH] Applied required changes in BookStack. --- app/Book.php | 2 +- app/Http/Controllers/BookController.php | 34 ++++++++++++------- app/User.php | 2 +- .../2014_10_12_000000_create_users_table.php | 2 ++ .../2015_07_12_114933_create_books_table.php | 1 + resources/assets/sass/styles.scss | 25 ++++++++++++++ resources/views/books/index.blade.php | 2 +- resources/views/users/edit.blade.php | 10 +++--- 8 files changed, 56 insertions(+), 22 deletions(-) diff --git a/app/Book.php b/app/Book.php index 06c00945d..67bd4f5b2 100644 --- a/app/Book.php +++ b/app/Book.php @@ -3,7 +3,7 @@ class Book extends Entity { - protected $fillable = ['name', 'description']; + protected $fillable = ['name', 'description', 'image']; /** * Get the url for this book. diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php index 086929558..9c1154281 100644 --- a/app/Http/Controllers/BookController.php +++ b/app/Http/Controllers/BookController.php @@ -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 diff --git a/app/User.php b/app/User.php index 3d77cd8ee..24eca12f3 100644 --- a/app/User.php +++ b/app/User.php @@ -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. diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 17e71de5f..62ac94b60 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -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' => 'admin@admin.com', 'password' => bcrypt('password'), + 'books_display' => 'grid', 'created_at' => \Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => \Carbon\Carbon::now()->toDateTimeString() ]); diff --git a/database/migrations/2015_07_12_114933_create_books_table.php b/database/migrations/2015_07_12_114933_create_books_table.php index 4220809d5..b8a6c9829 100644 --- a/database/migrations/2015_07_12_114933_create_books_table.php +++ b/database/migrations/2015_07_12_114933_create_books_table.php @@ -24,6 +24,7 @@ class CreateBooksTable extends Migration $table->string('slug')->indexed(); $table->text('description'); $table->nullableTimestamps(); + $table->string('image'); }); } diff --git a/resources/assets/sass/styles.scss b/resources/assets/sass/styles.scss index afb9d531b..bfa95fc1e 100644 --- a/resources/assets/sass/styles.scss +++ b/resources/assets/sass/styles.scss @@ -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 diff --git a/resources/views/books/index.blade.php b/resources/views/books/index.blade.php index 693c909aa..de13ab5cd 100644 --- a/resources/views/books/index.blade.php +++ b/resources/views/books/index.blade.php @@ -24,7 +24,7 @@

{{ trans('entities.books') }}

{!! $books->render() !!} @if(count($books) > 0) - @if($display=='grid') + @if($books_display=='grid') @foreach($books as $book) @include('books/grid-item', ['book' => $book]) @endforeach diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 3cacff645..152567d6c 100644 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -49,15 +49,13 @@ @endforeach -
- - + +
-