mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-01 22:39:13 +08:00
Reviewed and refactored next/previous navigation button implementation
- Updated styling to include item name. - Extracted used text to translations. - Updated the design to better suit the surrounding blocks. - Removed newly added model/repo methods. - Moved core logic out of controller and instead into a "NextPreviousContentLocator" helper with re-uses the output from the book-tree generation. - Also added the system to chapters. For #2511
This commit is contained in:
@ -4,6 +4,7 @@ use BookStack\Actions\View;
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Tools\BookContents;
|
||||
use BookStack\Entities\Repos\ChapterRepo;
|
||||
use BookStack\Entities\Tools\NextPreviousContentLocator;
|
||||
use BookStack\Entities\Tools\PermissionsUpdater;
|
||||
use BookStack\Exceptions\MoveOperationException;
|
||||
use BookStack\Exceptions\NotFoundException;
|
||||
@ -65,6 +66,7 @@ class ChapterController extends Controller
|
||||
|
||||
$sidebarTree = (new BookContents($chapter->book))->getTree();
|
||||
$pages = $chapter->getVisiblePages();
|
||||
$nextPreviousLocator = new NextPreviousContentLocator($chapter, $sidebarTree);
|
||||
View::incrementFor($chapter);
|
||||
|
||||
$this->setPageTitle($chapter->getShortName());
|
||||
@ -73,7 +75,9 @@ class ChapterController extends Controller
|
||||
'chapter' => $chapter,
|
||||
'current' => $chapter,
|
||||
'sidebarTree' => $sidebarTree,
|
||||
'pages' => $pages
|
||||
'pages' => $pages,
|
||||
'next' => $nextPreviousLocator->getNext(),
|
||||
'previous' => $nextPreviousLocator->getPrevious(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use BookStack\Actions\View;
|
||||
use BookStack\Entities\Tools\BookContents;
|
||||
use BookStack\Entities\Tools\NextPreviousContentLocator;
|
||||
use BookStack\Entities\Tools\PageContent;
|
||||
use BookStack\Entities\Tools\PageEditActivity;
|
||||
use BookStack\Entities\Models\Page;
|
||||
@ -142,39 +143,8 @@ class PageController extends Controller
|
||||
$page->load(['comments.createdBy']);
|
||||
}
|
||||
|
||||
$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];
|
||||
}
|
||||
}
|
||||
$nextPreviousLocator = new NextPreviousContentLocator($page, $sidebarTree);
|
||||
|
||||
$disablePrev = "";
|
||||
$disableNxt = "";
|
||||
if($prevPage == "#"){
|
||||
$disablePrev = "disabled";
|
||||
}
|
||||
if($nextPage == "#"){
|
||||
$disableNxt = "disabled";
|
||||
}
|
||||
|
||||
View::incrementFor($page);
|
||||
$this->setPageTitle($page->getShortName());
|
||||
return view('pages.show', [
|
||||
@ -184,10 +154,8 @@ class PageController extends Controller
|
||||
'sidebarTree' => $sidebarTree,
|
||||
'commentsEnabled' => $commentsEnabled,
|
||||
'pageNav' => $pageNav,
|
||||
'prevPage' => $prevPage,
|
||||
'nextPage' => $nextPage,
|
||||
'disablePrev' => $disablePrev,
|
||||
'disableNxt' => $disableNxt
|
||||
'next' => $nextPreviousLocator->getNext(),
|
||||
'previous' => $nextPreviousLocator->getPrevious(),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -280,8 +248,8 @@ class PageController extends Controller
|
||||
|
||||
$updateTime = $draft->updated_at->timestamp;
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => trans('entities.pages_edit_draft_save_at'),
|
||||
'status' => 'success',
|
||||
'message' => trans('entities.pages_edit_draft_save_at'),
|
||||
'timestamp' => $updateTime
|
||||
]);
|
||||
}
|
||||
@ -304,7 +272,7 @@ class PageController extends Controller
|
||||
{
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('page-delete', $page);
|
||||
$this->setPageTitle(trans('entities.pages_delete_named', ['pageName'=>$page->getShortName()]));
|
||||
$this->setPageTitle(trans('entities.pages_delete_named', ['pageName' => $page->getShortName()]));
|
||||
return view('pages.delete', [
|
||||
'book' => $page->book,
|
||||
'page' => $page,
|
||||
@ -320,7 +288,7 @@ class PageController extends Controller
|
||||
{
|
||||
$page = $this->pageRepo->getById($pageId);
|
||||
$this->checkOwnablePermission('page-update', $page);
|
||||
$this->setPageTitle(trans('entities.pages_delete_draft_named', ['pageName'=>$page->getShortName()]));
|
||||
$this->setPageTitle(trans('entities.pages_delete_draft_named', ['pageName' => $page->getShortName()]));
|
||||
return view('pages.delete', [
|
||||
'book' => $page->book,
|
||||
'page' => $page,
|
||||
@ -415,7 +383,7 @@ class PageController extends Controller
|
||||
try {
|
||||
$parent = $this->pageRepo->move($page, $entitySelection);
|
||||
} catch (Exception $exception) {
|
||||
if ($exception instanceof PermissionsException) {
|
||||
if ($exception instanceof PermissionsException) {
|
||||
$this->showPermissionError();
|
||||
}
|
||||
|
||||
@ -459,7 +427,7 @@ class PageController extends Controller
|
||||
try {
|
||||
$pageCopy = $this->pageRepo->copy($page, $entitySelection, $newName);
|
||||
} catch (Exception $exception) {
|
||||
if ($exception instanceof PermissionsException) {
|
||||
if ($exception instanceof PermissionsException) {
|
||||
$this->showPermissionError();
|
||||
}
|
||||
|
||||
@ -480,7 +448,7 @@ class PageController extends Controller
|
||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||
$this->checkOwnablePermission('restrictions-manage', $page);
|
||||
return view('pages.permissions', [
|
||||
'page' => $page,
|
||||
'page' => $page,
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user