Skip to content

Commit 10f5cee

Browse files
committed
List page settings: Review of #5606
Updated setting display to show mulitple number inputs under one heading group. Updated settings to use general number field form view template. Updated translations to match display changes, and to advise on counts. Added page count control for search results. Added setting service method, to get settings as integers, with min/max/default control. Updating sorting group to be names "Lists & Sorting". Added tests to cover.
1 parent 9886bbd commit 10f5cee

File tree

11 files changed

+137
-48
lines changed

11 files changed

+137
-48
lines changed

app/App/HomeController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function index(
8383
if ($homepageOption === 'bookshelves') {
8484
$shelves = $this->queries->shelves->visibleForListWithCover()
8585
->orderBy($commonData['listOptions']->getSort(), $commonData['listOptions']->getOrder())
86-
->paginate(intval(setting('sorting-shelves-per-page', '18')));
86+
->paginate(setting()->getInteger('lists-page-count-shelves', 18, 1, 1000));
8787
$data = array_merge($commonData, ['shelves' => $shelves]);
8888

8989
return view('home.shelves', $data);
@@ -92,7 +92,7 @@ public function index(
9292
if ($homepageOption === 'books') {
9393
$books = $this->queries->books->visibleForListWithCover()
9494
->orderBy($commonData['listOptions']->getSort(), $commonData['listOptions']->getOrder())
95-
->paginate(intval(setting('sorting-books-per-page', '18')));
95+
->paginate(setting()->getInteger('lists-page-count-books', 18, 1, 1000));
9696
$data = array_merge($commonData, ['books' => $books]);
9797

9898
return view('home.books', $data);

app/Entities/Controllers/BookController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function index(Request $request)
5252

5353
$books = $this->queries->visibleForListWithCover()
5454
->orderBy($listOptions->getSort(), $listOptions->getOrder())
55-
->paginate(intval(setting('sorting-books-per-page', '18')));
55+
->paginate(setting()->getInteger('lists-page-count-books', 18, 1, 1000));
5656
$recents = $this->isSignedIn() ? $this->queries->recentlyViewedForCurrentUser()->take(4)->get() : false;
5757
$popular = $this->queries->popularForList()->take(4)->get();
5858
$new = $this->queries->visibleForList()->orderBy('created_at', 'desc')->take(4)->get();

app/Entities/Controllers/BookshelfController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function index(Request $request)
4545

4646
$shelves = $this->queries->visibleForListWithCover()
4747
->orderBy($listOptions->getSort(), $listOptions->getOrder())
48-
->paginate(intval(setting('sorting-shelves-per-page', '18')));
48+
->paginate(setting()->getInteger('lists-page-count-shelves', 18, 1, 1000));
4949
$recents = $this->isSignedIn() ? $this->queries->recentlyViewedForCurrentUser()->get() : false;
5050
$popular = $this->queries->popularForList()->get();
5151
$new = $this->queries->visibleForList()

app/Search/SearchController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public function search(Request $request, SearchResultsFormatter $formatter)
2525
$searchOpts = SearchOptions::fromRequest($request);
2626
$fullSearchString = $searchOpts->toString();
2727
$page = intval($request->get('page', '0')) ?: 1;
28+
$count = setting()->getInteger('lists-page-count-search', 18, 1, 1000);
2829

29-
$results = $this->searchRunner->searchEntities($searchOpts, 'all', $page, 20);
30+
$results = $this->searchRunner->searchEntities($searchOpts, 'all', $page, $count);
3031
$formatter->format($results['results']->all(), $searchOpts);
31-
$paginator = new LengthAwarePaginator($results['results'], $results['total'], 20, $page);
32+
$paginator = new LengthAwarePaginator($results['results'], $results['total'], $count, $page);
3233
$paginator->setPath('/search');
3334
$paginator->appends($request->except('page'));
3435

app/Settings/AppSettingsStore.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function __construct(
1414
) {
1515
}
1616

17-
public function storeFromUpdateRequest(Request $request, string $category)
17+
public function storeFromUpdateRequest(Request $request, string $category): void
1818
{
1919
$this->storeSimpleSettings($request);
2020
if ($category === 'customization') {
@@ -76,7 +76,7 @@ protected function updateAppLogo(Request $request): void
7676
protected function storeSimpleSettings(Request $request): void
7777
{
7878
foreach ($request->all() as $name => $value) {
79-
if (strpos($name, 'setting-') !== 0) {
79+
if (!str_starts_with($name, 'setting-')) {
8080
continue;
8181
}
8282

@@ -85,7 +85,7 @@ protected function storeSimpleSettings(Request $request): void
8585
}
8686
}
8787

88-
protected function destroyExistingSettingImage(string $settingKey)
88+
protected function destroyExistingSettingImage(string $settingKey): void
8989
{
9090
$existingVal = setting()->get($settingKey);
9191
if ($existingVal) {

app/Settings/SettingService.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ public function get(string $key, $default = null): mixed
2828
return $this->formatValue($value, $default);
2929
}
3030

31+
/**
32+
* Get a setting from the database as an integer.
33+
* Returns the default value if not found or not an integer, and clamps the value to the given min/max range.
34+
*/
35+
public function getInteger(string $key, int $default, int $min = 0, int $max = PHP_INT_MAX): int
36+
{
37+
$value = $this->get($key, $default);
38+
if (!is_numeric($value)) {
39+
return $default;
40+
}
41+
42+
$int = intval($value);
43+
return max($min, min($max, $int));
44+
}
45+
3146
/**
3247
* Get a value from the session instead of the main store option.
3348
*/

lang/en/settings.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,8 @@
7575
'reg_confirm_restrict_domain_placeholder' => 'No restriction set',
7676

7777
// Sorting Settings
78-
'sorting' => 'Sorting',
79-
'sorting_shelves_per_page' => 'Shelves Per Page',
80-
'sorting_shelves_per_page_desc' => 'Sets the number of shelves shown per page in shelf listings.',
81-
'sorting_books_per_page' => 'Books Per Page',
82-
'sorting_books_per_page_desc' => 'Sets the number of books shown per page in book listings.',
83-
'sorting_book_default' => 'Default Book Sort',
78+
'sorting' => 'Lists & Sorting',
79+
'sorting_book_default' => 'Default Book Sort Rule',
8480
'sorting_book_default_desc' => 'Select the default sort rule to apply to new books. This won\'t affect existing books, and can be overridden per-book.',
8581
'sorting_rules' => 'Sort Rules',
8682
'sorting_rules_desc' => 'These are predefined sorting operations which can be applied to content in the system.',
@@ -107,6 +103,8 @@
107103
'sort_rule_op_updated_date' => 'Updated Date',
108104
'sort_rule_op_chapters_first' => 'Chapters First',
109105
'sort_rule_op_chapters_last' => 'Chapters Last',
106+
'sorting_page_limits' => 'Per-Page Display Limits',
107+
'sorting_page_limits_desc' => 'Set how many items to show per-page in various lists within the system. Typically a lower amount will be more performant, while a higher amount avoids the need to click through multiple pages. Using an even multiple of 3 (18, 24, 30, etc...) is recommended.',
110108

111109
// Maintenance settings
112110
'maint' => 'Maintenance',

resources/sass/_forms.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ input[type=color] {
348348
}
349349
}
350350

351+
.small-inputs input {
352+
width: 150px;
353+
}
354+
351355
.simple-code-input {
352356
background-color: #F8F8F8;
353357
font-family: monospace;

resources/views/form/number.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
@if($readonly ?? false) readonly="readonly" @endif
77
@if($min ?? false) min="{{ $min }}" @endif
88
@if($max ?? false) max="{{ $max }}" @endif
9-
@if(isset($model) || old($name)) value="{{ old($name) ? old($name) : $model->$name}}" @endif>
9+
@if($step ?? false) step="{{ $step }}" @endif
10+
@if(isset($model) || old($name) || isset($value)) value="{{ old($name) ?? $model->$name ?? $value }}" @endif>
1011
@if($errors->has($name))
1112
<div class="text-neg text-small">{{ $errors->first($name) }}</div>
1213
@endif

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

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,30 @@
1010
{{ csrf_field() }}
1111
<input type="hidden" name="section" value="sorting">
1212

13-
<div class="grid half gap-xl items-center">
14-
<div>
15-
<label for="setting-sorting-shelves-per-page"
16-
class="setting-list-label">{{ trans('settings.sorting_shelves_per_page') }}</label>
17-
<p class="small">{{ trans('settings.sorting_shelves_per_page_desc') }}</p>
18-
</div>
19-
<div>
20-
<input type="number"
21-
id="setting-sorting-shelves-per-page"
22-
name="setting-sorting-shelves-per-page"
23-
value="{{ intval(setting('sorting-shelves-per-page', 18)) }}"
24-
min="1"
25-
step="1"
26-
class="@if($errors->has('setting-sorting-shelves-per-page')) neg @endif">
27-
</div>
28-
</div>
29-
30-
<div class="grid half gap-xl items-center">
31-
<div>
32-
<label for="setting-sorting-books-per-page"
33-
class="setting-list-label">{{ trans('settings.sorting_books_per_page') }}</label>
34-
<p class="small">{{ trans('settings.sorting_books_per_page_desc') }}</p>
35-
</div>
13+
<div class="setting-list">
3614
<div>
37-
<input type="number"
38-
id="setting-sorting-books-per-page"
39-
name="setting-sorting-books-per-page"
40-
value="{{ intval(setting('sorting-books-per-page', 18)) }}"
41-
min="1"
42-
step="1"
43-
class="@if($errors->has('setting-sorting-books-per-page')) neg @endif">
15+
<div class="mb-m">
16+
<label class="setting-list-label">{{ trans('settings.sorting_page_limits') }}</label>
17+
<p class="small">{{ trans('settings.sorting_page_limits_desc') }}</p>
18+
</div>
19+
<div class="flex-container-row wrap gap-m small-inputs">
20+
@php
21+
$labelByKey = ['shelves' => trans('entities.shelves'), 'books' => trans('entities.books'), 'search' => trans('entities.search_results')];
22+
@endphp
23+
@foreach($labelByKey as $key => $label)
24+
<div>
25+
<label for="setting-lists-page-count-{{ $key }}">{{ $label }}</label>
26+
@include('form.number', [
27+
'name' => 'setting-lists-page-count-' . $key,
28+
'value' => setting()->getInteger('lists-page-count-' . $key, 18, 1, 1000),
29+
'min' => 1,
30+
'step' => 1,
31+
])
32+
</div>
33+
@endforeach
34+
</div>
4435
</div>
45-
</div>
4636

47-
<div class="setting-list">
4837
<div class="grid half gap-xl items-center">
4938
<div>
5039
<label for="setting-sorting-book-default"

0 commit comments

Comments
 (0)