X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/ea55b7f141a70e2d6edb209f6c48610a9c005e4e..refs/pull/63/head:/app/Http/Controllers/BookController.php diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php index ff172f3b2..a4365d605 100644 --- a/app/Http/Controllers/BookController.php +++ b/app/Http/Controllers/BookController.php @@ -42,8 +42,10 @@ class BookController extends Controller public function index() { $books = $this->bookRepo->getAllPaginated(10); - $recents = $this->bookRepo->getRecentlyViewed(10, 0); - return view('books/index', ['books' => $books, 'recents' => $recents]); + $recents = $this->signedIn ? $this->bookRepo->getRecentlyViewed(4, 0) : false; + $popular = $this->bookRepo->getPopular(4, 0); + $this->setPageTitle('Books'); + return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular]); } /** @@ -54,6 +56,7 @@ class BookController extends Controller public function create() { $this->checkPermission('book-create'); + $this->setPageTitle('Create New Book'); return view('books/create'); } @@ -88,8 +91,10 @@ class BookController extends Controller public function show($slug) { $book = $this->bookRepo->getBySlug($slug); + $bookChildren = $this->bookRepo->getChildren($book); Views::add($book); - return view('books/show', ['book' => $book, 'current' => $book]); + $this->setPageTitle($book->getShortName()); + return view('books/show', ['book' => $book, 'current' => $book, 'bookChildren' => $bookChildren]); } /** @@ -102,6 +107,7 @@ class BookController extends Controller { $this->checkPermission('book-update'); $book = $this->bookRepo->getBySlug($slug); + $this->setPageTitle('Edit Book ' . $book->getShortName()); return view('books/edit', ['book' => $book, 'current' => $book]); } @@ -137,6 +143,7 @@ class BookController extends Controller { $this->checkPermission('book-delete'); $book = $this->bookRepo->getBySlug($bookSlug); + $this->setPageTitle('Delete Book ' . $book->getShortName()); return view('books/delete', ['book' => $book, 'current' => $book]); } @@ -149,14 +156,23 @@ class BookController extends Controller { $this->checkPermission('book-update'); $book = $this->bookRepo->getBySlug($bookSlug); + $bookChildren = $this->bookRepo->getChildren($book); $books = $this->bookRepo->getAll(); - return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books]); + $this->setPageTitle('Sort Book ' . $book->getShortName()); + return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]); } + /** + * Shows the sort box for a single book. + * Used via AJAX when loading in extra books to a sort. + * @param $bookSlug + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ public function getSortItem($bookSlug) { $book = $this->bookRepo->getBySlug($bookSlug); - return view('books/sort-box', ['book' => $book]); + $bookChildren = $this->bookRepo->getChildren($book); + return view('books/sort-box', ['book' => $book, 'bookChildren' => $bookChildren]); } /** @@ -185,7 +201,7 @@ class BookController extends Controller $isPage = $bookChild->type == 'page'; $bookId = $this->bookRepo->exists($bookChild->book) ? $bookChild->book : $defaultBookId; $model = $isPage ? $this->pageRepo->getById($id) : $this->chapterRepo->getById($id); - $isPage ? $this->pageRepo->setBookId($bookId, $model) : $this->chapterRepo->setBookId($bookId, $model); + $isPage ? $this->pageRepo->changeBook($bookId, $model) : $this->chapterRepo->changeBook($bookId, $model); $model->priority = $index; if ($isPage) { $model->chapter_id = ($bookChild->parentChapter === false) ? 0 : $bookChild->parentChapter;