Applied required changes in BookStack.

This commit is contained in:
Nilesh Deepak 2017-07-05 12:09:01 +05:30
parent fdf139edb2
commit 947c58f227
8 changed files with 56 additions and 22 deletions

View File

@ -3,7 +3,7 @@
class Book extends Entity class Book extends Entity
{ {
protected $fillable = ['name', 'description']; protected $fillable = ['name', 'description', 'image'];
/** /**
* Get the url for this book. * Get the url for this book.

View File

@ -36,11 +36,12 @@ class BookController extends Controller
*/ */
public function index() 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; $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'); $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' 'description' => 'string|max:1000'
]); ]);
$image = $request->file('image'); $image = $request->file('image');
$input = time().'-'.$image->getClientOriginalName(); $path = $this->getBookCoverURL($image);
$destinationPath = public_path('uploads/book/');
$image->move($destinationPath, $input);
$path = baseUrl('/uploads/book/').'/'.$input;
$book = $this->entityRepo->createFromInput('book', $request->all()); $book = $this->entityRepo->createFromInput('book', $request->all());
$book->image = $path; $book->image = $path;
$book->save(); $book->save();
@ -121,12 +119,8 @@ class BookController extends Controller
'name' => 'required|string|max:255', 'name' => 'required|string|max:255',
'description' => 'string|max:1000' 'description' => 'string|max:1000'
]); ]);
$image = $request->file('image');
$input = $request->file('image')->getClientOriginalName(); $path = $this->getBookCoverURL($image);
echo $input;
$destinationPath = public_path('uploads/book/');
$request->file('image')->move($destinationPath, $input);
$path = baseUrl('/uploads/book/').'/'.$input;
$book = $this->entityRepo->updateFromInput('book', $book, $request->all()); $book = $this->entityRepo->updateFromInput('book', $book, $request->all());
$book->image = $path; $book->image = $path;
$book->save(); $book->save();
@ -134,6 +128,20 @@ class BookController extends Controller
return redirect($book->getUrl()); 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 * Shows the page to confirm deletion
* @param $bookSlug * @param $bookSlug

View File

@ -22,7 +22,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
* The attributes that are mass assignable. * The attributes that are mass assignable.
* @var array * @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. * The attributes excluded from the model's JSON form.

View File

@ -18,6 +18,7 @@ class CreateUsersTable extends Migration
$table->string('email')->unique(); $table->string('email')->unique();
$table->string('password', 60); $table->string('password', 60);
$table->rememberToken(); $table->rememberToken();
$table->string('books_display')->default('grid');
$table->nullableTimestamps(); $table->nullableTimestamps();
}); });
@ -26,6 +27,7 @@ class CreateUsersTable extends Migration
'name' => 'Admin', 'name' => 'Admin',
'email' => 'admin@admin.com', 'email' => 'admin@admin.com',
'password' => bcrypt('password'), 'password' => bcrypt('password'),
'books_display' => 'grid',
'created_at' => \Carbon\Carbon::now()->toDateTimeString(), 'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
'updated_at' => \Carbon\Carbon::now()->toDateTimeString() 'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
]); ]);

View File

@ -24,6 +24,7 @@ class CreateBooksTable extends Migration
$table->string('slug')->indexed(); $table->string('slug')->indexed();
$table->text('description'); $table->text('description');
$table->nullableTimestamps(); $table->nullableTimestamps();
$table->string('image');
}); });
} }

View 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;
}
}

View File

@ -24,7 +24,7 @@
<h1>{{ trans('entities.books') }}</h1> <h1>{{ trans('entities.books') }}</h1>
{!! $books->render() !!} {!! $books->render() !!}
@if(count($books) > 0) @if(count($books) > 0)
@if($display=='grid') @if($books_display=='grid')
@foreach($books as $book) @foreach($books as $book)
@include('books/grid-item', ['book' => $book]) @include('books/grid-item', ['book' => $book])
@endforeach @endforeach

View File

@ -49,15 +49,13 @@
@endforeach @endforeach
</select> </select>
</div> </div>
<!--Select display type -->
<div class="form-group"> <div class="form-group">
<label for="display">Type of view</label> <label for="books_display">Type of view</label>
<select name="display" id="display"> <select name="books_display" id="books_display">
<option @if($user->display === 'grid') selected @endif value="grid">Grid</option> <option @if($user->books_display === 'grid') selected @endif value="grid">Grid</option>
<option @if($user->display === 'list') selected @endif value="list">List</option> <option @if($user->books_display === 'list') selected @endif value="list">List</option>
</select> </select>
</div> </div>
<!---->
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">