]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'BookStackApp:development' into basic-pwa-support
authorJonatanRek <redacted>
Fri, 22 Sep 2023 08:48:48 +0000 (10:48 +0200)
committerGitHub <redacted>
Fri, 22 Sep 2023 08:48:48 +0000 (10:48 +0200)
1  2 
app/App/HomeController.php
resources/views/layouts/base.blade.php
routes/web.php

index d971247df738fecda62d3ef862a3b833bcd48106,24b7c3ed819eacb1e0f7dbe04638446dfdf69197..927fdfc1d22d13cc88339bf37cd7729f60edf2e0
@@@ -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;
                  '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]);
              $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);
 +    }
  }
index 4a0422dcd1af2cc73278eb38919ebf43352f5d3f,f303aff267752caaca1419eba7e07ba019d02e61..69a7e148efa88df4cf3cab299b7ca7d087720a75
@@@ -1,6 -1,6 +1,6 @@@
  <!DOCTYPE html>
- <html lang="{{ config('app.lang') }}"
-       dir="{{ config('app.rtl') ? 'rtl' : 'ltr' }}"
+ <html lang="{{ isset($locale) ? $locale->htmlLang() : config('app.default_locale') }}"
+       dir="{{ isset($locale) ? $locale->htmlDirection() : 'auto' }}"
        class="{{ setting()->getForCurrentUser('dark-mode-enabled') ? 'dark-mode ' : '' }}">
  <head>
      <title>{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ setting('app-name') }}</title>
      <link rel="icon" type="image/png" sizes="64x64" href="{{ setting('app-icon-64') ?: url('/icon-64.png') }}">
      <link rel="icon" type="image/png" sizes="32x32" href="{{ setting('app-icon-32') ?: url('/icon-32.png') }}">
  
 +    <!-- PWA -->
 +    <link rel="manifest" href="{{ url('/manifest.json') }}" />
 +    <meta name="mobile-web-app-capable" content="yes" /> 
 +
      @yield('head')
  
      <!-- Custom Styles & Head Content -->
@@@ -69,7 -65,9 +69,9 @@@
      </div>
  
      @yield('bottom')
-     <script src="{{ versioned_asset('dist/app.js') }}" nonce="{{ $cspNonce }}"></script>
+     @if($cspNonce ?? false)
+         <script src="{{ versioned_asset('dist/app.js') }}" nonce="{{ $cspNonce }}"></script>
+     @endif
      @yield('scripts')
  
      @include('layouts.parts.base-body-end')
diff --combined routes/web.php
index 6e80635e02e5c5e2fd0f232326edcdb3e455af50,c7fc92fc77da3bf5819dcc75cd558ce02756700d..8116cdaf8fb9c9b99b377c36b438f21a56a61dcf
@@@ -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 () {
      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']);
      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']);