]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'prev-next-button' of https://github.com/shubhamosmosys/BookStack into...
authorDan Brown <redacted>
Wed, 26 May 2021 21:13:19 +0000 (22:13 +0100)
committerDan Brown <redacted>
Wed, 26 May 2021 21:13:19 +0000 (22:13 +0100)
1  2 
app/Entities/Models/Page.php
app/Entities/Repos/PageRepo.php
app/Http/Controllers/PageController.php
resources/sass/_layout.scss
resources/views/pages/show.blade.php

index 93fb218932cf6e9f2796fce7f3aaac8586c43490,b60da01212f4c5ac8bf2fc5cd69efa0c501401c5..888a0db33b09445afb5e5639322190d6dd903e1b
@@@ -40,7 -40,7 +40,7 @@@ class Page extends BookChil
       */
      public function scopeVisible(Builder $query): Builder
      {
 -        $query = Permissions::enforceDraftVisiblityOnQuery($query);
 +        $query = Permissions::enforceDraftVisibilityOnQuery($query);
          return parent::scopeVisible($query);
      }
  
  
      /**
       * Get the associated page revisions, ordered by created date.
 -     * @return mixed
 +     * Only provides actual saved page revision instances, Not drafts.
 +     */
 +    public function revisions(): HasMany
 +    {
 +        return $this->allRevisions()
 +            ->where('type', '=', 'version')
 +            ->orderBy('created_at', 'desc')
 +            ->orderBy('id', 'desc');
 +    }
 +
 +    /**
 +     * Get all revision instances assigned to this page.
 +     * Includes all types of revisions.
       */
 -    public function revisions()
 +    public function allRevisions(): HasMany
      {
 -        return $this->hasMany(PageRevision::class)->where('type', '=', 'version')->orderBy('created_at', 'desc')->orderBy('id', 'desc');
 +        return $this->hasMany(PageRevision::class);
      }
  
      /**
          $refreshed->html = (new PageContent($refreshed))->render();
          return $refreshed;
      }
+     /**
+      * Get the parent chapter ID.
+      */
+     public function getParentChapter()
+     {
+         $chapterId = $this->chapter()->visible()
+         ->get('id');
+         return $chapterId;
+     }
  }
index 5eb882a026a3f803369b56b06b6334c46e8773c9,ca5748c86569fcf1a388ea91a63ca60174c8c189..651548885a815fca2c7853974f5f27926b8d2be8
@@@ -177,24 -177,25 +177,24 @@@ class PageRep
          // Hold the old details to compare later
          $oldHtml = $page->html;
          $oldName = $page->name;
 +        $oldMarkdown = $page->markdown;
  
          $this->updateTemplateStatusAndContentFromInput($page, $input);
          $this->baseRepo->update($page, $input);
  
          // Update with new details
          $page->revision_count++;
 -
 -        if (setting('app-editor') !== 'markdown') {
 -            $page->markdown = '';
 -        }
 -
          $page->save();
  
          // Remove all update drafts for this user & page.
          $this->getUserDraftQuery($page)->delete();
  
          // Save a revision after updating
 -        $summary = $input['summary'] ?? null;
 -        if ($oldHtml !== $input['html'] || $oldName !== $input['name'] || $summary !== null) {
 +        $summary = trim($input['summary'] ?? "");
 +        $htmlChanged = isset($input['html']) && $input['html'] !== $oldHtml;
 +        $nameChanged = isset($input['name']) && $input['name'] !== $oldName;
 +        $markdownChanged = isset($input['markdown']) && $input['markdown'] !== $oldMarkdown;
 +        if ($htmlChanged || $nameChanged || $markdownChanged || $summary) {
              $this->savePageRevision($page, $summary);
          }
  
          if (!empty($input['markdown'] ?? '')) {
              $pageContent->setNewMarkdown($input['markdown']);
          } else {
 -            $pageContent->setNewHTML($input['html']);
 +            $pageContent->setNewHTML($input['html'] ?? '');
          }
      }
  
      {
          $revision = new PageRevision($page->getAttributes());
  
 -        if (setting('app-editor') !== 'markdown') {
 -            $revision->markdown = '';
 -        }
 -
          $revision->page_id = $page->id;
          $revision->slug = $page->slug;
          $revision->book_slug = $page->book->slug;
  
          $page->fill($revision->toArray());
          $content = new PageContent($page);
 -        $content->setNewHTML($revision->html);
 +
 +        if (!empty($revision->markdown)) {
 +            $content->setNewMarkdown($revision->markdown);
 +        } else {
 +            $content->setNewHTML($revision->html);
 +        }
 +        
          $page->updated_by = user()->id;
          $page->refreshSlug();
          $page->save();
              ->where('page_id', '=', $page->id)
              ->orderBy('created_at', 'desc');
      }
+     /**
+      * Get page details by chapter ID.
+      */
+     public function getPageByChapterID(int $id){
+         return Page::visible()->where('chapter_id', '=', $id)->get(['id','slug']);
+     }
  }
index 134c22081382bdd0a3a407b469bd7684ccb9c4d0,2bfd55fa0cf07b1797a22d31060773d6e34ec758..616970a5d05758088d04e2ec034c46dda3766913
@@@ -1,6 -1,5 +1,6 @@@
  <?php namespace BookStack\Http\Controllers;
  
 +use BookStack\Actions\View;
  use BookStack\Entities\Tools\BookContents;
  use BookStack\Entities\Tools\PageContent;
  use BookStack\Entities\Tools\PageEditActivity;
@@@ -8,6 -7,7 +8,6 @@@ use BookStack\Entities\Models\Page
  use BookStack\Entities\Repos\PageRepo;
  use BookStack\Entities\Tools\PermissionsUpdater;
  use BookStack\Exceptions\NotFoundException;
 -use BookStack\Exceptions\NotifyException;
  use BookStack\Exceptions\PermissionsException;
  use Exception;
  use Illuminate\Http\Request;
@@@ -142,7 -142,39 +142,40 @@@ class PageController extends Controlle
              $page->load(['comments.createdBy']);
          }
  
 -        Views::add($page);
+         $chapterId = $page->getParentChapter();
+         $allPageSlugs = $this->pageRepo->getPageByChapterID($chapterId[0]->id);
+         $pos = 0;
+         foreach ($allPageSlugs as $slug){
+             if($pageSlug === $slug->slug){
+                 $currPagePos = $pos;
+             }
+             $pos++;
+             $pageUrl = $this->pageRepo->getBySlug($bookSlug, $slug->slug);
+             $urlLink[] = $pageUrl->getUrl();
+         }
+         for($i=0; $i <= $currPagePos; $i++){
+             $nextCount = $i+1;
+             $prevCount = $i-1;
+             $prevPage = '#';
+             $nextPage = '#';
+             if($nextCount < count($urlLink)){
+                 $nextPage = $urlLink[$nextCount];
+             }
+             if($currPagePos == $i && $currPagePos != 0){
+                 $prevPage = $urlLink[$prevCount];    
+             }
+         }
+         $disablePrev = "";
+         $disableNxt = "";
+         if($prevPage == "#"){
+             $disablePrev = "disabled";
+         }
+         if($nextPage == "#"){
+             $disableNxt = "disabled";
+         }
++        
 +        View::incrementFor($page);
          $this->setPageTitle($page->getShortName());
          return view('pages.show', [
              'page' => $page,
              'current' => $page,
              'sidebarTree' => $sidebarTree,
              'commentsEnabled' => $commentsEnabled,
-             'pageNav' => $pageNav
+             'pageNav' => $pageNav,
+             'prevPage' => $prevPage,
+             'nextPage' => $nextPage,
+             'disablePrev' => $disablePrev,
+             'disableNxt' => $disableNxt
          ]);
      }
  
       * Remove the specified page from storage.
       * @throws NotFoundException
       * @throws Throwable
 -     * @throws NotifyException
       */
      public function destroy(string $bookSlug, string $pageSlug)
      {
      /**
       * Remove the specified draft page from storage.
       * @throws NotFoundException
 -     * @throws NotifyException
       * @throws Throwable
       */
      public function destroyDraft(string $bookSlug, int $pageId)
              ->paginate(20)
              ->setPath(url('/pages/recently-updated'));
  
 -        return view('pages.detailed-listing', [
 +        return view('common.detailed-listing-paginated', [
              'title' => trans('entities.recently_updated_pages'),
 -            'pages' => $pages
 +            'entities' => $pages
          ]);
      }
  
index eb6b443a052757ea6fd4bf51a1c5a53bb03fbb41,57800d41ef436f791062f62d0b0288387866c0fb..c5af303f8751738b444e8beafdbb24f480e95d81
@@@ -62,6 -62,9 +62,9 @@@
  }
  
  @include smaller-than($m) {
+   .grid.third.prev-next:not(.no-break) {
+     grid-template-columns: 1fr 1fr 1fr;
+   }
    .grid.third:not(.no-break) {
      grid-template-columns: 1fr 1fr;
    }
    .grid.right-focus.reverse-collapse > *:nth-child(1) {
      order: 1;
    }
+   .grid.third:not(.no-break) .text-m-left {
+     margin-left: 20%;
+   }
+   .grid.third:not(.no-break) .text-m-right {
+     margin-left: 45%;
+   }
  }
  
  @include smaller-than($s) {
    .grid.third:not(.no-break) {
      grid-template-columns: 1fr;
    }
+   .grid.third:not(.no-break) .text-m-left {
+     margin-left: 18%;
+   }
+   .grid.third:not(.no-break) .text-m-right {
+     margin-left: 20%;
+   }
  }
  
  @include smaller-than($xs) {
    }
  }
  
 +#content {
 +  flex: 1 0 auto;
 +}
 +
  /**
   * Flexbox layout system
   */
@@@ -157,9 -168,6 +172,9 @@@ body.flexbox 
  .justify-center {
    justify-content: center;
  }
 +.justify-space-between {
 +  justify-content: space-between;
 +}
  .items-center {
    align-items: center;
  }
    .tri-layout-middle {
      grid-area: b;
      padding-top: $-m;
 +    min-width: 0;
    }
  }
  @include smaller-than($xxl) {
      margin-inline-end: 0;
    }
  }
+ .prev-next-btn {
+   height: 50px;
+ }
index 5baf2a16ced362cd0e9bb6bc70ae9ac635263541,38e819a9e1baecd2dc6d037409cc97fe3770ca43..3476f3a3d732815502c2d93aba8f20c560adc2e0
              @include('pages.page-display')
          </div>
      </main>
+        
+     <div class="prev-next-btn">
+         <div class="grid third no-row-gap prev-next">
+             <div class="text-m-left">
+                 <a class="{{ $disablePrev }}" href="{{ $prevPage }}">Previous Page</a>
+             </div>
+             <div></div>
+             <div class="text-m-right">
+                 <a class="{{ $disableNxt }}" href="{{ $nextPage }}">Next Page</a>
+             </div>
+         </div>
+     </div>
  
      @if ($commentsEnabled)
          <div class="container small p-none comments-container mb-l print-hidden">
  
              <hr class="primary-background"/>
  
 -            {{--Export--}}
 +            @if(signedInUser())
 +                @include('partials.entity-favourite-action', ['entity' => $page])
 +            @endif
              @include('partials.entity-export-menu', ['entity' => $page])
          </div>