Sort Rules: Added creation hints to sort rule selection

To help direct/indicate how rules can be created.
For #5967
This commit is contained in:
Dan Brown
2026-04-12 14:31:40 +01:00
parent 684a94c419
commit 4e3fa4822f
4 changed files with 32 additions and 3 deletions

View File

@@ -173,6 +173,7 @@ return [
'books_sort_desc' => 'Move chapters and pages within a book to reorganise its contents. Other books can be added which allows easy moving of chapters and pages between books. Optionally an auto sort rule can be set to automatically sort this book\'s contents upon changes.',
'books_sort_auto_sort' => 'Auto Sort Option',
'books_sort_auto_sort_active' => 'Auto Sort Active: :sortName',
'books_sort_auto_sort_creation_hint' => 'Auto sort option rules can be created in the "Lists & Sorting" settings area by a user with the relevant permissions.',
'books_sort_named' => 'Sort Book :bookName',
'books_sort_name' => 'Sort by Name',
'books_sort_created' => 'Sort by Created Date',

View File

@@ -20,7 +20,12 @@
<h1 class="list-heading">{{ trans('entities.books_sort') }}</h1>
<div class="flex-container-row gap-m wrap mb-m">
<p class="text-muted flex min-width-s mb-none">{{ trans('entities.books_sort_desc') }}</p>
<div class="flex min-width-s">
<p class="text-muted mb-none">{{ trans('entities.books_sort_desc') }}</p>
@if(!userCan(\BookStack\Permissions\Permission::SettingsManage))
<p class="text-muted mb-none mt-s small">{{ trans('entities.books_sort_auto_sort_creation_hint') }}</p>
@endif
</div>
<div class="min-width-s">
@php
$autoSortVal = intval(old('auto-sort') ?? $book->sort_rule_id ?? 0);
@@ -41,6 +46,11 @@
</option>
@endforeach
</select>
@if(userCan(\BookStack\Permissions\Permission::SettingsManage))
<p class="small">
<a href="{{ url('/settings/sorting/rules/new') }}" class="text-button" target="_blank">{{ trans('settings.sort_rule_create') }}</a>
</p>
@endif
</div>
</div>

View File

@@ -38,9 +38,9 @@
<div>
<label for="setting-sorting-book-default"
class="setting-list-label">{{ trans('settings.sorting_book_default') }}</label>
<p class="small">{{ trans('settings.sorting_book_default_desc') }}</p>
<p class="small mb-s">{{ trans('settings.sorting_book_default_desc') }}</p>
</div>
<div>
<div class="pt-s">
<select id="setting-sorting-book-default" name="setting-sorting-book-default"
@if($errors->has('setting-sorting-book-default')) class="neg" @endif>
<option value="0" @if(intval(setting('sorting-book-default', '0')) === 0) selected @endif>
@@ -54,6 +54,9 @@
</option>
@endforeach
</select>
<p class="small">
<a href="{{ url('/settings/sorting/rules/new') }}" class="text-button" target="_blank">{{ trans('settings.sort_rule_create') }}</a>
</p>
</div>
</div>

View File

@@ -271,6 +271,21 @@ class BookSortTest extends TestCase
$this->withHtml($resp)->assertElementExists('select[name="auto-sort"] option[value="' . $sort->id . '"]');
}
public function test_auto_sort_rule_create_hint_shown_on_sort_page()
{
$book = $this->entities->book();
$hintText = 'Auto sort option rules can be created in the "Lists & Sorting" settings area by a user with the relevant permissions.';
// Admin users see link for creating new rule
$resp = $this->asAdmin()->get($book->getUrl('/sort'));
$this->withHtml($resp)->assertLinkExists(url('/settings/sorting/rules/new'), 'Create Sort Rule');
$resp->assertDontSee($hintText);
// Non-admin users see help text
$resp = $this->asEditor()->get($book->getUrl('/sort'));
$resp->assertSee($hintText);
}
public function test_auto_sort_option_submit_saves_to_book()
{
$sort = SortRule::factory()->create();