X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/7ad8314bd71adef5336ed6482e6933d02805f26a..refs/pull/1444/head:/app/Http/Controllers/HomeController.php diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index e47250318..ba93bfe65 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -1,8 +1,7 @@ $draftPages, ]; + // Add required list ordering & sorting for books & shelves views. + if ($homepageOption === 'bookshelves' || $homepageOption === 'books') { + $key = $homepageOption; + $view = setting()->getUser($this->currentUser, $key . '_view_type', config('app.views.' . $key)); + $sort = setting()->getUser($this->currentUser, $key . '_sort', 'name'); + $order = setting()->getUser($this->currentUser, $key . '_sort_order', 'asc'); + + $sortOptions = [ + 'name' => trans('common.sort_name'), + 'created_at' => trans('common.sort_created_at'), + 'updated_at' => trans('common.sort_updated_at'), + ]; + + $commonData = array_merge($commonData, [ + 'view' => $view, + 'sort' => $sort, + 'order' => $order, + 'sortOptions' => $sortOptions, + ]); + } + if ($homepageOption === 'bookshelves') { - $shelves = $this->entityRepo->getAllPaginated('bookshelf', 18); - $shelvesViewType = setting()->getUser($this->currentUser, 'bookshelves_view_type', config('app.views.bookshelves', 'grid')); - $data = array_merge($commonData, ['shelves' => $shelves, 'shelvesViewType' => $shelvesViewType]); + $shelves = $this->entityRepo->getAllPaginated('bookshelf', 18, $commonData['sort'], $commonData['order']); + foreach ($shelves as $shelf) { + $shelf->books = $this->entityRepo->getBookshelfChildren($shelf); + } + $data = array_merge($commonData, ['shelves' => $shelves]); return view('common.home-shelves', $data); } if ($homepageOption === 'books') { - $books = $this->entityRepo->getAllPaginated('book', 18); - $booksViewType = setting()->getUser($this->currentUser, 'books_view_type', config('app.views.books', 'list')); - $data = array_merge($commonData, ['books' => $books, 'booksViewType' => $booksViewType]); + $books = $this->entityRepo->getAllPaginated('book', 18, $commonData['sort'], $commonData['order']); + $data = array_merge($commonData, ['books' => $books]); return view('common.home-book', $data); } @@ -80,6 +100,7 @@ class HomeController extends Controller { $locale = app()->getLocale(); $cacheKey = 'GLOBAL_TRANSLATIONS_' . $locale; + if (cache()->has($cacheKey) && config('app.env') !== 'development') { $resp = cache($cacheKey); } else { @@ -90,15 +111,6 @@ class HomeController extends Controller 'entities' => trans('entities'), 'errors' => trans('errors') ]; - if ($locale !== 'en') { - $enTrans = [ - 'common' => trans('common', [], 'en'), - 'components' => trans('components', [], 'en'), - 'entities' => trans('entities', [], 'en'), - 'errors' => trans('errors', [], 'en') - ]; - $translations = array_replace_recursive($enTrans, $translations); - } $resp = 'window.translations = ' . json_encode($translations); cache()->put($cacheKey, $resp, 120); } @@ -114,7 +126,7 @@ class HomeController extends Controller */ public function customHeadContent() { - return view('partials/custom-head-content'); + return view('partials.custom-head-content'); } /** @@ -129,7 +141,7 @@ class HomeController extends Controller $allowRobots = $sitePublic; } return response() - ->view('common/robots', ['allowRobots' => $allowRobots]) + ->view('common.robots', ['allowRobots' => $allowRobots]) ->header('Content-Type', 'text/plain'); } @@ -138,6 +150,6 @@ class HomeController extends Controller */ public function getNotFound() { - return response()->view('errors/404', [], 404); + return response()->view('errors.404', [], 404); } }