1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Sorting: Improved sort set display, delete, added action on edit

- Changes to a sort set will now auto-apply to assinged books (basic
  chunck through all on save).
- Added book count indicator to sort set list items.
- Deletion now has confirmation and auto-handling of assigned
  books/settings.
This commit is contained in:
Dan Brown
2025-02-06 14:58:08 +00:00
parent c13ce18837
commit ccd94684eb
6 changed files with 61 additions and 17 deletions

View File

@ -16,6 +16,15 @@ class BookSorter
) {
}
public function runBookAutoSortForAllWithSet(SortSet $set): void
{
$set->books()->chunk(50, function ($books) {
foreach ($books as $book) {
$this->runBookAutoSort($book);
}
});
}
/**
* Runs the auto-sort for a book if the book has a sort set applied to it.
* This does not consider permissions since the sort operations are centrally

View File

@ -52,7 +52,7 @@ class SortSetController extends Controller
return view('settings.sort-sets.edit', ['set' => $set]);
}
public function update(string $id, Request $request)
public function update(string $id, Request $request, BookSorter $bookSorter)
{
$this->validate($request, [
'name' => ['required', 'string', 'min:1', 'max:200'],
@ -67,26 +67,44 @@ class SortSetController extends Controller
$set->name = $request->input('name');
$set->setOperations($operations);
$changedSequence = $set->isDirty('sequence');
$set->save();
$this->logActivity(ActivityType::SORT_SET_UPDATE, $set);
if ($changedSequence) {
$bookSorter->runBookAutoSortForAllWithSet($set);
}
return redirect('/settings/sorting');
}
public function destroy(string $id)
public function destroy(string $id, Request $request)
{
$set = SortSet::query()->findOrFail($id);
$confirmed = $request->input('confirm') === 'true';
$booksAssigned = $set->books()->count();
$warnings = [];
if ($set->books()->count() > 0) {
$this->showErrorNotification(trans('settings.sort_set_delete_fail_books'));
return redirect($set->getUrl());
if ($booksAssigned > 0) {
if ($confirmed) {
$set->books()->update(['sort_set_id' => null]);
} else {
$warnings[] = trans('settings.sort_set_delete_warn_books', ['count' => $booksAssigned]);
}
}
$defaultBookSortSetting = intval(setting('sorting-book-default', '0'));
if ($defaultBookSortSetting === intval($id)) {
$this->showErrorNotification(trans('settings.sort_set_delete_fail_default'));
return redirect($set->getUrl());
if ($confirmed) {
setting()->remove('sorting-book-default');
} else {
$warnings[] = trans('settings.sort_set_delete_warn_default');
}
}
if (count($warnings) > 0) {
return redirect($set->getUrl() . '#delete')->withErrors(['delete' => $warnings]);
}
$set->delete();