mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Made new pages in chapters have a better inital priority
This commit is contained in:
parent
cbff2c6035
commit
afc3583be8
@ -88,7 +88,6 @@ class PageController extends Controller
|
|||||||
|
|
||||||
$input = $request->all();
|
$input = $request->all();
|
||||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||||
$input['priority'] = $this->bookRepo->getNewPriority($book);
|
|
||||||
|
|
||||||
$draftPage = $this->pageRepo->getById($pageId, true);
|
$draftPage = $this->pageRepo->getById($pageId, true);
|
||||||
|
|
||||||
@ -96,6 +95,12 @@ class PageController extends Controller
|
|||||||
$parent = $chapterId !== 0 ? $this->chapterRepo->getById($chapterId) : $book;
|
$parent = $chapterId !== 0 ? $this->chapterRepo->getById($chapterId) : $book;
|
||||||
$this->checkOwnablePermission('page-create', $parent);
|
$this->checkOwnablePermission('page-create', $parent);
|
||||||
|
|
||||||
|
if ($parent->isA('chapter')) {
|
||||||
|
$input['priority'] = $this->chapterRepo->getNewPriority($parent);
|
||||||
|
} else {
|
||||||
|
$input['priority'] = $this->bookRepo->getNewPriority($parent);
|
||||||
|
}
|
||||||
|
|
||||||
$page = $this->pageRepo->publishDraft($draftPage, $input);
|
$page = $this->pageRepo->publishDraft($draftPage, $input);
|
||||||
|
|
||||||
Activity::add($page, 'page_create', $book->id);
|
Activity::add($page, 'page_create', $book->id);
|
||||||
|
@ -136,6 +136,18 @@ class ChapterRepo extends EntityRepo
|
|||||||
return $slug;
|
return $slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a new priority value for a new page to be added
|
||||||
|
* to the given chapter.
|
||||||
|
* @param Chapter $chapter
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getNewPriority(Chapter $chapter)
|
||||||
|
{
|
||||||
|
$lastPage = $chapter->pages->last();
|
||||||
|
return $lastPage !== null ? $lastPage->priority + 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get chapters by the given search term.
|
* Get chapters by the given search term.
|
||||||
* @param string $term
|
* @param string $term
|
||||||
|
Loading…
Reference in New Issue
Block a user