Skip to content

Commit 4e3fa48

Browse files
committed
Sort Rules: Added creation hints to sort rule selection
To help direct/indicate how rules can be created. For #5967
1 parent 684a94c commit 4e3fa48

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

lang/en/entities.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
'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.',
174174
'books_sort_auto_sort' => 'Auto Sort Option',
175175
'books_sort_auto_sort_active' => 'Auto Sort Active: :sortName',
176+
'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.',
176177
'books_sort_named' => 'Sort Book :bookName',
177178
'books_sort_name' => 'Sort by Name',
178179
'books_sort_created' => 'Sort by Created Date',

resources/views/books/sort.blade.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
<h1 class="list-heading">{{ trans('entities.books_sort') }}</h1>
2121

2222
<div class="flex-container-row gap-m wrap mb-m">
23-
<p class="text-muted flex min-width-s mb-none">{{ trans('entities.books_sort_desc') }}</p>
23+
<div class="flex min-width-s">
24+
<p class="text-muted mb-none">{{ trans('entities.books_sort_desc') }}</p>
25+
@if(!userCan(\BookStack\Permissions\Permission::SettingsManage))
26+
<p class="text-muted mb-none mt-s small">{{ trans('entities.books_sort_auto_sort_creation_hint') }}</p>
27+
@endif
28+
</div>
2429
<div class="min-width-s">
2530
@php
2631
$autoSortVal = intval(old('auto-sort') ?? $book->sort_rule_id ?? 0);
@@ -41,6 +46,11 @@ class="{{ $errors->has('auto-sort') ? 'neg' : '' }}">
4146
</option>
4247
@endforeach
4348
</select>
49+
@if(userCan(\BookStack\Permissions\Permission::SettingsManage))
50+
<p class="small">
51+
<a href="{{ url('/settings/sorting/rules/new') }}" class="text-button" target="_blank">{{ trans('settings.sort_rule_create') }}</a>
52+
</p>
53+
@endif
4454
</div>
4555
</div>
4656

resources/views/settings/categories/sorting.blade.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
<div>
3939
<label for="setting-sorting-book-default"
4040
class="setting-list-label">{{ trans('settings.sorting_book_default') }}</label>
41-
<p class="small">{{ trans('settings.sorting_book_default_desc') }}</p>
41+
<p class="small mb-s">{{ trans('settings.sorting_book_default_desc') }}</p>
4242
</div>
43-
<div>
43+
<div class="pt-s">
4444
<select id="setting-sorting-book-default" name="setting-sorting-book-default"
4545
@if($errors->has('setting-sorting-book-default')) class="neg" @endif>
4646
<option value="0" @if(intval(setting('sorting-book-default', '0')) === 0) selected @endif>
@@ -54,6 +54,9 @@ class="setting-list-label">{{ trans('settings.sorting_book_default') }}</label>
5454
</option>
5555
@endforeach
5656
</select>
57+
<p class="small">
58+
<a href="{{ url('/settings/sorting/rules/new') }}" class="text-button" target="_blank">{{ trans('settings.sort_rule_create') }}</a>
59+
</p>
5760
</div>
5861
</div>
5962

tests/Sorting/BookSortTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,21 @@ public function test_auto_sort_options_shown_on_sort_page()
271271
$this->withHtml($resp)->assertElementExists('select[name="auto-sort"] option[value="' . $sort->id . '"]');
272272
}
273273

274+
public function test_auto_sort_rule_create_hint_shown_on_sort_page()
275+
{
276+
$book = $this->entities->book();
277+
$hintText = 'Auto sort option rules can be created in the "Lists & Sorting" settings area by a user with the relevant permissions.';
278+
279+
// Admin users see link for creating new rule
280+
$resp = $this->asAdmin()->get($book->getUrl('/sort'));
281+
$this->withHtml($resp)->assertLinkExists(url('/settings/sorting/rules/new'), 'Create Sort Rule');
282+
$resp->assertDontSee($hintText);
283+
284+
// Non-admin users see help text
285+
$resp = $this->asEditor()->get($book->getUrl('/sort'));
286+
$resp->assertSee($hintText);
287+
}
288+
274289
public function test_auto_sort_option_submit_saves_to_book()
275290
{
276291
$sort = SortRule::factory()->create();

0 commit comments

Comments
 (0)