1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Sorting: Added auto sort option to book sort UI

Includes indicator on books added to sort operation.
This commit is contained in:
Dan Brown
2025-02-09 15:16:18 +00:00
parent ccd94684eb
commit ec79517493
8 changed files with 74 additions and 18 deletions

View File

@ -44,24 +44,40 @@ class BookSortController extends Controller
}
/**
* Sorts a book using a given mapping array.
* Update the sort options of a book, setting the auto-sort and/or updating
* child order via mapping.
*/
public function update(Request $request, BookSorter $sorter, string $bookSlug)
{
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
$this->checkOwnablePermission('book-update', $book);
$loggedActivityForBook = false;
// Return if no map sent
if (!$request->filled('sort-tree')) {
return redirect($book->getUrl());
// Sort via map
if ($request->filled('sort-tree')) {
$sortMap = BookSortMap::fromJson($request->get('sort-tree'));
$booksInvolved = $sorter->sortUsingMap($sortMap);
// Rebuild permissions and add activity for involved books.
foreach ($booksInvolved as $bookInvolved) {
Activity::add(ActivityType::BOOK_SORT, $bookInvolved);
if ($bookInvolved->id === $book->id) {
$loggedActivityForBook = true;
}
}
}
$sortMap = BookSortMap::fromJson($request->get('sort-tree'));
$booksInvolved = $sorter->sortUsingMap($sortMap);
// Rebuild permissions and add activity for involved books.
foreach ($booksInvolved as $bookInvolved) {
Activity::add(ActivityType::BOOK_SORT, $bookInvolved);
if ($request->filled('auto-sort')) {
$sortSetId = intval($request->get('auto-sort')) ?: null;
if ($sortSetId && SortSet::query()->find($sortSetId) === null) {
$sortSetId = null;
}
$book->sort_set_id = $sortSetId;
$book->save();
$sorter->runBookAutoSort($book);
if (!$loggedActivityForBook) {
Activity::add(ActivityType::BOOK_SORT, $book);
}
}
return redirect($book->getUrl());