From: JonatanRek Date: Fri, 22 Sep 2023 08:48:48 +0000 (+0200) Subject: Merge branch 'BookStackApp:development' into basic-pwa-support X-Git-Tag: v23.10~1^2~19^2~8^2 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/effc03e99e8a455932884dccf1195287f87d09a3?hp=-c Merge branch 'BookStackApp:development' into basic-pwa-support --- effc03e99e8a455932884dccf1195287f87d09a3 diff --combined app/App/HomeController.php index d971247df,24b7c3ed8..927fdfc1d --- a/app/App/HomeController.php +++ b/app/App/HomeController.php @@@ -18,41 -18,41 +18,41 @@@ use Illuminate\Http\Request class HomeController extends Controller { /** - * Display the homepage. - */ + * Display the homepage. + */ public function index(Request $request, ActivityQueries $activities) { $activity = $activities->latest(10); $draftPages = []; - + if ($this->isSignedIn()) { $draftPages = Page::visible() - ->where('draft', '=', true) - ->where('created_by', '=', user()->id) - ->orderBy('updated_at', 'desc') - ->with('book') - ->take(6) - ->get(); + ->where('draft', '=', true) + ->where('created_by', '=', user()->id) + ->orderBy('updated_at', 'desc') + ->with('book') + ->take(6) + ->get(); } - + $recentFactor = count($draftPages) > 0 ? 0.5 : 1; $recents = $this->isSignedIn() ? - (new RecentlyViewed())->run(12 * $recentFactor, 1) - : Book::visible()->orderBy('created_at', 'desc')->take(12 * $recentFactor)->get(); + (new RecentlyViewed())->run(12 * $recentFactor, 1) + : Book::visible()->orderBy('created_at', 'desc')->take(12 * $recentFactor)->get(); $favourites = (new TopFavourites())->run(6); $recentlyUpdatedPages = Page::visible()->with('book') - ->where('draft', false) - ->orderBy('updated_at', 'desc') - ->take($favourites->count() > 0 ? 5 : 10) - ->select(Page::$listAttributes) - ->get(); - + ->where('draft', false) + ->orderBy('updated_at', 'desc') + ->take($favourites->count() > 0 ? 5 : 10) + ->select(Page::$listAttributes) + ->get(); + $homepageOptions = ['default', 'books', 'bookshelves', 'page']; $homepageOption = setting('app-homepage-type', 'default'); if (!in_array($homepageOption, $homepageOptions)) { $homepageOption = 'default'; } - + $commonData = [ 'activity' => $activity, 'recents' => $recents, @@@ -60,7 -60,7 +60,7 @@@ 'draftPages' => $draftPages, 'favourites' => $favourites, ]; - + // Add required list ordering & sorting for books & shelves views. if ($homepageOption === 'bookshelves' || $homepageOption === 'books') { $key = $homepageOption; @@@ -70,27 -70,27 +70,27 @@@ 'created_at' => trans('common.sort_created_at'), 'updated_at' => trans('common.sort_updated_at'), ]); - + $commonData = array_merge($commonData, [ 'view' => $view, 'listOptions' => $listOptions, ]); } - + if ($homepageOption === 'bookshelves') { - $shelves = app(BookshelfRepo::class)->getAllPaginated(18, $commonData['listOptions']->getSort(), $commonData['listOptions']->getOrder()); + $shelves = app()->make(BookshelfRepo::class)->getAllPaginated(18, $commonData['listOptions']->getSort(), $commonData['listOptions']->getOrder()); $data = array_merge($commonData, ['shelves' => $shelves]); - + return view('home.shelves', $data); } - + if ($homepageOption === 'books') { - $books = app(BookRepo::class)->getAllPaginated(18, $commonData['listOptions']->getSort(), $commonData['listOptions']->getOrder()); + $books = app()->make(BookRepo::class)->getAllPaginated(18, $commonData['listOptions']->getSort(), $commonData['listOptions']->getOrder()); $data = array_merge($commonData, ['books' => $books]); - + return view('home.books', $data); } - + if ($homepageOption === 'page') { $homepageSetting = setting('app-homepage', '0:'); $id = intval(explode(':', $homepageSetting)[0]); @@@ -98,59 -98,46 +98,59 @@@ $customHomepage = Page::query()->where('draft', '=', false)->findOrFail($id); $pageContent = new PageContent($customHomepage); $customHomepage->html = $pageContent->render(false); - + return view('home.specific-page', array_merge($commonData, ['customHomepage' => $customHomepage])); } - + return view('home.default', $commonData); } - + /** - * Show the view for /robots.txt. - */ + * Show the view for /robots.txt. + */ public function robots() { $sitePublic = setting('app-public', false); $allowRobots = config('app.allow_robots'); - + if ($allowRobots === null) { $allowRobots = $sitePublic; } - + return response() - ->view('misc.robots', ['allowRobots' => $allowRobots]) - ->header('Content-Type', 'text/plain'); + ->view('misc.robots', ['allowRobots' => $allowRobots]) + ->header('Content-Type', 'text/plain'); } - + /** - * Show the route for 404 responses. - */ + * Show the route for 404 responses. + */ public function notFound() { return response()->view('errors.404', [], 404); } - + /** - * Serve the application favicon. - * Ensures a 'favicon.ico' file exists at the web root location (if writable) to be served - * directly by the webserver in the future. - */ + * Serve the application favicon. + * Ensures a 'favicon.ico' file exists at the web root location (if writable) to be served + * directly by the webserver in the future. + */ public function favicon(FaviconHandler $favicons) { $exists = $favicons->restoreOriginalIfNotExists(); return response()->file($exists ? $favicons->getPath() : $favicons->getOriginalPath()); } + + /** + * Serve the application manifest. + * Ensures a 'manifest.json' + */ + public function manifest() + { + $manifest = config('manifest'); + + $manifest["background_color"] = setting('app-color'); + + return response()->json($manifest); + } } diff --combined resources/views/layouts/base.blade.php index 4a0422dcd,f303aff26..69a7e148e --- a/resources/views/layouts/base.blade.php +++ b/resources/views/layouts/base.blade.php @@@ -1,6 -1,6 +1,6 @@@ - {{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ setting('app-name') }} @@@ -29,10 -29,6 +29,10 @@@ + + + + @yield('head') @@@ -69,7 -65,9 +69,9 @@@ @yield('bottom') - + @if($cspNonce ?? false) + + @endif @yield('scripts') @include('layouts.parts.base-body-end') diff --combined routes/web.php index 6e80635e0,c7fc92fc7..8116cdaf8 --- a/routes/web.php +++ b/routes/web.php @@@ -20,7 -20,6 +20,7 @@@ use Illuminate\View\Middleware\ShareErr Route::get('/status', [SettingControllers\StatusController::class, 'show']); Route::get('/robots.txt', [HomeController::class, 'robots']); Route::get('/favicon.ico', [HomeController::class, 'favicon']); +Route::get('/manifest.json', [HomeController::class, 'manifest']); // Authenticated routes... Route::middleware('auth')->group(function () { @@@ -195,6 -194,9 +195,9 @@@ Route::post('/favourites/add', [ActivityControllers\FavouriteController::class, 'add']); Route::post('/favourites/remove', [ActivityControllers\FavouriteController::class, 'remove']); + // Watching + Route::put('/watching/update', [ActivityControllers\WatchController::class, 'update']); + // Other Pages Route::get('/', [HomeController::class, 'index']); Route::get('/home', [HomeController::class, 'index']); @@@ -229,9 -231,11 +232,11 @@@ Route::delete('/settings/users/{id}', [UserControllers\UserController::class, 'destroy']); // User Preferences - Route::redirect('/preferences', '/'); + Route::get('/preferences', [UserControllers\UserPreferencesController::class, 'index']); Route::get('/preferences/shortcuts', [UserControllers\UserPreferencesController::class, 'showShortcuts']); Route::put('/preferences/shortcuts', [UserControllers\UserPreferencesController::class, 'updateShortcuts']); + Route::get('/preferences/notifications', [UserControllers\UserPreferencesController::class, 'showNotifications']); + Route::put('/preferences/notifications', [UserControllers\UserPreferencesController::class, 'updateNotifications']); Route::patch('/preferences/change-view/{type}', [UserControllers\UserPreferencesController::class, 'changeView']); Route::patch('/preferences/change-sort/{type}', [UserControllers\UserPreferencesController::class, 'changeSort']); Route::patch('/preferences/change-expansion/{type}', [UserControllers\UserPreferencesController::class, 'changeExpansion']);