*/
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;
+ }
}
// 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']);
+ }
}
<?php namespace BookStack\Http\Controllers;
+use BookStack\Actions\View;
use BookStack\Entities\Tools\BookContents;
use BookStack\Entities\Tools\PageContent;
use BookStack\Entities\Tools\PageEditActivity;
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;
$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
]);
}
}
@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
*/
.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;
+ }
@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>