GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #3821 from BookStackApp/list_reworks · devdot/BookStack@33e5c85

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/workflows
    • analyse-php.yml
    • test-migrations.yml
    • test-php.yml
  • app
    • Actions
      • Queries
        • WebhooksAllPaginatedAndSorted.php
      • TagRepo.php
    • Auth
      • Queries
        • RolesAllPaginatedAndSorted.php
        • UsersAllPaginatedAndSorted.php
      • Role.php
    • Http/Controllers
      • AuditLogController.php
      • BookController.php
      • BookshelfController.php
      • HomeController.php
      • PageRevisionController.php
      • RoleController.php
      • TagController.php
      • UserController.php
      • UserPreferencesController.php
      • WebhookController.php
    • Util
      • SimpleListOptions.php
  • resources
    • js/components
      • entity-permissions.js
      • list-sort-control.js
      • permissions-table.js
    • lang/en
      • entities.php
      • settings.php
    • sass
      • _blocks.scss
      • _components.scss
      • _layout.scss
      • _opacity.scss
      • styles.scss
    • views
      • books
        • index.blade.php
        • parts
          • list.blade.php
      • common
        • sort.blade.php
        • status-indicator.blade.php
      • form
        • entity-permissions-row.blade.php
        • entity-permissions.blade.php
      • pages
        • parts
          • revisions-index-row.blade.php
        • revisions.blade.php
      • search/parts
        • term-list.blade.php
      • settings
        • audit.blade.php
        • parts
          • table-user.blade.php
        • recycle-bin
          • index.blade.php
          • parts
            • recycle-bin-list-item.blade.php
        • roles
          • index.blade.php
          • parts
            • asset-permissions-row.blade.php
            • form.blade.php
            • related-asset-permissions-row.blade.php
            • roles-list-item.blade.php
        • webhooks
          • index.blade.php
          • parts
            • webhooks-list-item.blade.php
      • shelves
        • index.blade.php
        • parts
          • list.blade.php
        • show.blade.php
      • tags
        • index.blade.php
        • parts
          • table-row.blade.php
          • tags-list-item.blade.php
      • users
        • api-tokens/parts
          • list.blade.php
        • index.blade.php
        • parts
          • users-list-item.blade.php
  • routes
    • web.php
  • tests
    • Actions
      • AuditLogTest.php
    • Entity
      • PageRevisionTest.php
      • TagTest.php
    • Settings
      • RecycleBinTest.php
    • User
      • UserPreferencesTest.php

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/workflows/analyse-php.yml‎

Copy file name to clipboardExpand all lines: .github/workflows/analyse-php.yml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jobs:
1818
- name: Get Composer Cache Directory
1919
id: composer-cache
2020
run: |
21-
echo "::set-output name=dir::$(composer config cache-files-dir)"
21+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
2222
2323
- name: Cache composer packages
24-
uses: actions/cache@v2
24+
uses: actions/cache@v3
2525
with:
2626
path: ${{ steps.composer-cache.outputs.dir }}
2727
key: ${{ runner.os }}-composer-8.1
Collapse file

‎.github/workflows/test-migrations.yml‎

Copy file name to clipboardExpand all lines: .github/workflows/test-migrations.yml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
- name: Get Composer Cache Directory
2222
id: composer-cache
2323
run: |
24-
echo "::set-output name=dir::$(composer config cache-files-dir)"
24+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
2525
2626
- name: Cache composer packages
27-
uses: actions/cache@v2
27+
uses: actions/cache@v3
2828
with:
2929
path: ${{ steps.composer-cache.outputs.dir }}
3030
key: ${{ runner.os }}-composer-${{ matrix.php }}
Collapse file

‎.github/workflows/test-php.yml‎

Copy file name to clipboardExpand all lines: .github/workflows/test-php.yml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
- name: Get Composer Cache Directory
2222
id: composer-cache
2323
run: |
24-
echo "::set-output name=dir::$(composer config cache-files-dir)"
24+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
2525
2626
- name: Cache composer packages
27-
uses: actions/cache@v2
27+
uses: actions/cache@v3
2828
with:
2929
path: ${{ steps.composer-cache.outputs.dir }}
3030
key: ${{ runner.os }}-composer-${{ matrix.php }}
Collapse file

‎app/Actions/Queries/WebhooksAllPaginatedAndSorted.php‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace BookStack\Actions\Queries;
4+
5+
use BookStack\Actions\Webhook;
6+
use BookStack\Util\SimpleListOptions;
7+
use Illuminate\Pagination\LengthAwarePaginator;
8+
9+
/**
10+
* Get all the webhooks in the system in a paginated format.
11+
*/
12+
class WebhooksAllPaginatedAndSorted
13+
{
14+
public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
15+
{
16+
$query = Webhook::query()->select(['*'])
17+
->withCount(['trackedEvents'])
18+
->orderBy($listOptions->getSort(), $listOptions->getOrder());
19+
20+
if ($listOptions->getSearch()) {
21+
$term = '%' . $listOptions->getSearch() . '%';
22+
$query->where(function ($query) use ($term) {
23+
$query->where('name', 'like', $term)
24+
->orWhere('endpoint', 'like', $term);
25+
});
26+
}
27+
28+
return $query->paginate($count);
29+
}
30+
}
Collapse file

‎app/Actions/TagRepo.php‎

Copy file name to clipboardExpand all lines: app/Actions/TagRepo.php
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use BookStack\Auth\Permissions\PermissionApplicator;
66
use BookStack\Entities\Models\Entity;
7+
use BookStack\Util\SimpleListOptions;
78
use Illuminate\Database\Eloquent\Builder;
89
use Illuminate\Support\Collection;
910
use Illuminate\Support\Facades\DB;
@@ -20,8 +21,14 @@ public function __construct(PermissionApplicator $permissions)
2021
/**
2122
* Start a query against all tags in the system.
2223
*/
23-
public function queryWithTotals(string $searchTerm, string $nameFilter): Builder
24+
public function queryWithTotals(SimpleListOptions $listOptions, string $nameFilter): Builder
2425
{
26+
$searchTerm = $listOptions->getSearch();
27+
$sort = $listOptions->getSort();
28+
if ($sort === 'name' && $nameFilter) {
29+
$sort = 'value';
30+
}
31+
2532
$query = Tag::query()
2633
->select([
2734
'name',
@@ -32,7 +39,7 @@ public function queryWithTotals(string $searchTerm, string $nameFilter): Builder
3239
DB::raw('SUM(IF(entity_type = \'book\', 1, 0)) as book_count'),
3340
DB::raw('SUM(IF(entity_type = \'bookshelf\', 1, 0)) as shelf_count'),
3441
])
35-
->orderBy($nameFilter ? 'value' : 'name');
42+
->orderBy($sort, $listOptions->getOrder());
3643

3744
if ($nameFilter) {
3845
$query->where('name', '=', $nameFilter);
Collapse file

‎app/Auth/Queries/RolesAllPaginatedAndSorted.php‎

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace BookStack\Auth\Queries;
4+
5+
use BookStack\Auth\Role;
6+
use BookStack\Util\SimpleListOptions;
7+
use Illuminate\Pagination\LengthAwarePaginator;
8+
9+
/**
10+
* Get all the roles in the system in a paginated format.
11+
*/
12+
class RolesAllPaginatedAndSorted
13+
{
14+
public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
15+
{
16+
$sort = $listOptions->getSort();
17+
if ($sort === 'created_at') {
18+
$sort = 'users.created_at';
19+
}
20+
21+
$query = Role::query()->select(['*'])
22+
->withCount(['users', 'permissions'])
23+
->orderBy($sort, $listOptions->getOrder());
24+
25+
if ($listOptions->getSearch()) {
26+
$term = '%' . $listOptions->getSearch() . '%';
27+
$query->where(function ($query) use ($term) {
28+
$query->where('display_name', 'like', $term)
29+
->orWhere('description', 'like', $term);
30+
});
31+
}
32+
33+
return $query->paginate($count);
34+
}
35+
}
Collapse file

‎…h/Queries/AllUsersPaginatedAndSorted.php‎ ‎…h/Queries/UsersAllPaginatedAndSorted.php‎app/Auth/Queries/AllUsersPaginatedAndSorted.php renamed to app/Auth/Queries/UsersAllPaginatedAndSorted.php app/Auth/Queries/AllUsersPaginatedAndSorted.php renamed to app/Auth/Queries/UsersAllPaginatedAndSorted.php

Copy file name to clipboardExpand all lines: app/Auth/Queries/UsersAllPaginatedAndSorted.php
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BookStack\Auth\Queries;
44

55
use BookStack\Auth\User;
6+
use BookStack\Util\SimpleListOptions;
67
use Illuminate\Pagination\LengthAwarePaginator;
78

89
/**
@@ -11,23 +12,23 @@
1112
* user is assumed to be trusted. (Admin users).
1213
* Email search can be abused to extract email addresses.
1314
*/
14-
class AllUsersPaginatedAndSorted
15+
class UsersAllPaginatedAndSorted
1516
{
16-
/**
17-
* @param array{sort: string, order: string, search: string} $sortData
18-
*/
19-
public function run(int $count, array $sortData): LengthAwarePaginator
17+
public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
2018
{
21-
$sort = $sortData['sort'];
19+
$sort = $listOptions->getSort();
20+
if ($sort === 'created_at') {
21+
$sort = 'users.created_at';
22+
}
2223

2324
$query = User::query()->select(['*'])
2425
->scopes(['withLastActivityAt'])
2526
->with(['roles', 'avatar'])
2627
->withCount('mfaValues')
27-
->orderBy($sort, $sortData['order']);
28+
->orderBy($sort, $listOptions->getOrder());
2829

29-
if ($sortData['search']) {
30-
$term = '%' . $sortData['search'] . '%';
30+
if ($listOptions->getSearch()) {
31+
$term = '%' . $listOptions->getSearch() . '%';
3132
$query->where(function ($query) use ($term) {
3233
$query->where('name', 'like', $term)
3334
->orWhere('email', 'like', $term);
Collapse file

‎app/Auth/Role.php‎

Copy file name to clipboardExpand all lines: app/Auth/Role.php
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,6 @@ public static function getSystemRole(string $systemName): ?self
110110
return static::query()->where('system_name', '=', $systemName)->first();
111111
}
112112

113-
/**
114-
* Get all visible roles.
115-
*/
116-
public static function visible(): Collection
117-
{
118-
return static::query()->where('hidden', '=', false)->orderBy('name')->get();
119-
}
120-
121113
/**
122114
* {@inheritdoc}
123115
*/
Collapse file

‎app/Http/Controllers/AuditLogController.php‎

Copy file name to clipboardExpand all lines: app/Http/Controllers/AuditLogController.php
+26-20Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace BookStack\Http\Controllers;
44

55
use BookStack\Actions\Activity;
6+
use BookStack\Actions\ActivityType;
7+
use BookStack\Util\SimpleListOptions;
68
use Illuminate\Http\Request;
79
use Illuminate\Support\Facades\DB;
810

@@ -13,10 +15,15 @@ public function index(Request $request)
1315
$this->checkPermission('settings-manage');
1416
$this->checkPermission('users-manage');
1517

16-
$listDetails = [
17-
'order' => $request->get('order', 'desc'),
18+
$sort = $request->get('sort', 'activity_date');
19+
$order = $request->get('order', 'desc');
20+
$listOptions = (new SimpleListOptions('', $sort, $order))->withSortOptions([
21+
'created_at' => trans('settings.audit_table_date'),
22+
'type' => trans('settings.audit_table_event'),
23+
]);
24+
25+
$filters = [
1826
'event' => $request->get('event', ''),
19-
'sort' => $request->get('sort', 'created_at'),
2027
'date_from' => $request->get('date_from', ''),
2128
'date_to' => $request->get('date_to', ''),
2229
'user' => $request->get('user', ''),
@@ -25,39 +32,38 @@ public function index(Request $request)
2532

2633
$query = Activity::query()
2734
->with([
28-
'entity' => function ($query) {
29-
$query->withTrashed();
30-
},
35+
'entity' => fn ($query) => $query->withTrashed(),
3136
'user',
3237
])
33-
->orderBy($listDetails['sort'], $listDetails['order']);
38+
->orderBy($listOptions->getSort(), $listOptions->getOrder());
3439

35-
if ($listDetails['event']) {
36-
$query->where('type', '=', $listDetails['event']);
40+
if ($filters['event']) {
41+
$query->where('type', '=', $filters['event']);
3742
}
38-
if ($listDetails['user']) {
39-
$query->where('user_id', '=', $listDetails['user']);
43+
if ($filters['user']) {
44+
$query->where('user_id', '=', $filters['user']);
4045
}
4146

42-
if ($listDetails['date_from']) {
43-
$query->where('created_at', '>=', $listDetails['date_from']);
47+
if ($filters['date_from']) {
48+
$query->where('created_at', '>=', $filters['date_from']);
4449
}
45-
if ($listDetails['date_to']) {
46-
$query->where('created_at', '<=', $listDetails['date_to']);
50+
if ($filters['date_to']) {
51+
$query->where('created_at', '<=', $filters['date_to']);
4752
}
48-
if ($listDetails['ip']) {
49-
$query->where('ip', 'like', $listDetails['ip'] . '%');
53+
if ($filters['ip']) {
54+
$query->where('ip', 'like', $filters['ip'] . '%');
5055
}
5156

5257
$activities = $query->paginate(100);
53-
$activities->appends($listDetails);
58+
$activities->appends($request->all());
5459

55-
$types = DB::table('activities')->select('type')->distinct()->pluck('type');
60+
$types = ActivityType::all();
5661
$this->setPageTitle(trans('settings.audit'));
5762

5863
return view('settings.audit', [
5964
'activities' => $activities,
60-
'listDetails' => $listDetails,
65+
'filters' => $filters,
66+
'listOptions' => $listOptions,
6167
'activityTypes' => $types,
6268
]);
6369
}
Collapse file

‎app/Http/Controllers/BookController.php‎

Copy file name to clipboardExpand all lines: app/Http/Controllers/BookController.php
+9-6Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use BookStack\Exceptions\NotFoundException;
1616
use BookStack\Facades\Activity;
1717
use BookStack\References\ReferenceFetcher;
18+
use BookStack\Util\SimpleListOptions;
1819
use Illuminate\Http\Request;
1920
use Illuminate\Validation\ValidationException;
2021
use Throwable;
@@ -35,13 +36,16 @@ public function __construct(ShelfContext $entityContextManager, BookRepo $bookRe
3536
/**
3637
* Display a listing of the book.
3738
*/
38-
public function index()
39+
public function index(Request $request)
3940
{
4041
$view = setting()->getForCurrentUser('books_view_type');
41-
$sort = setting()->getForCurrentUser('books_sort', 'name');
42-
$order = setting()->getForCurrentUser('books_sort_order', 'asc');
42+
$listOptions = SimpleListOptions::fromRequest($request, 'books')->withSortOptions([
43+
'name' => trans('common.sort_name'),
44+
'created_at' => trans('common.sort_created_at'),
45+
'updated_at' => trans('common.sort_updated_at'),
46+
]);
4347

44-
$books = $this->bookRepo->getAllPaginated(18, $sort, $order);
48+
$books = $this->bookRepo->getAllPaginated(18, $listOptions->getSort(), $listOptions->getOrder());
4549
$recents = $this->isSignedIn() ? $this->bookRepo->getRecentlyViewed(4) : false;
4650
$popular = $this->bookRepo->getPopular(4);
4751
$new = $this->bookRepo->getRecentlyCreated(4);
@@ -56,8 +60,7 @@ public function index()
5660
'popular' => $popular,
5761
'new' => $new,
5862
'view' => $view,
59-
'sort' => $sort,
60-
'order' => $order,
63+
'listOptions' => $listOptions,
6164
]);
6265
}
6366

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.