GeezerVison is showing github.com — Merge pull request #3821 from BookStackApp/list_reworks · devdot/BookStack@33e5c85
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/analyse-php.yml +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,10 +18,10 @@ jobs: | 18 | 18 | - name: Get Composer Cache Directory | 19 | 19 | id: composer-cache | 20 | 20 | run: | | 21 | | - echo "::set-output name=dir::$(composer config cache-files-dir)" | | 21 | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | 22 | 22 |
| 23 | 23 | - name: Cache composer packages | 24 | | - uses: actions/cache@v2 | | 24 | + uses: actions/cache@v3 | 25 | 25 | with: | 26 | 26 | path: ${{ steps.composer-cache.outputs.dir }} | 27 | 27 | key: ${{ runner.os }}-composer-8.1 | |
Collapse file Copy file name to clipboardExpand all lines: .github/workflows/test-migrations.yml +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,10 +21,10 @@ jobs: | 21 | 21 | - name: Get Composer Cache Directory | 22 | 22 | id: composer-cache | 23 | 23 | run: | | 24 | | - echo "::set-output name=dir::$(composer config cache-files-dir)" | | 24 | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | 25 | 25 |
| 26 | 26 | - name: Cache composer packages | 27 | | - uses: actions/cache@v2 | | 27 | + uses: actions/cache@v3 | 28 | 28 | with: | 29 | 29 | path: ${{ steps.composer-cache.outputs.dir }} | 30 | 30 | key: ${{ runner.os }}-composer-${{ matrix.php }} | |
Collapse file Copy file name to clipboardExpand all lines: .github/workflows/test-php.yml +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,10 +21,10 @@ jobs: | 21 | 21 | - name: Get Composer Cache Directory | 22 | 22 | id: composer-cache | 23 | 23 | run: | | 24 | | - echo "::set-output name=dir::$(composer config cache-files-dir)" | | 24 | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | 25 | 25 |
| 26 | 26 | - name: Cache composer packages | 27 | | - uses: actions/cache@v2 | | 27 | + uses: actions/cache@v3 | 28 | 28 | with: | 29 | 29 | path: ${{ steps.composer-cache.outputs.dir }} | 30 | 30 | key: ${{ runner.os }}-composer-${{ matrix.php }} | |
Collapse file Copy file name to clipboard +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboardExpand all lines: app/Actions/TagRepo.php +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 |
| 5 | 5 | use BookStack\Auth\Permissions\PermissionApplicator; | 6 | 6 | use BookStack\Entities\Models\Entity; | | 7 | +use BookStack\Util\SimpleListOptions; | 7 | 8 | use Illuminate\Database\Eloquent\Builder; | 8 | 9 | use Illuminate\Support\Collection; | 9 | 10 | use Illuminate\Support\Facades\DB; | @@ -20,8 +21,14 @@ public function __construct(PermissionApplicator $permissions) | 20 | 21 | /** | 21 | 22 | * Start a query against all tags in the system. | 22 | 23 | */ | 23 | | - public function queryWithTotals(string $searchTerm, string $nameFilter): Builder | | 24 | + public function queryWithTotals(SimpleListOptions $listOptions, string $nameFilter): Builder | 24 | 25 | { | | 26 | + $searchTerm = $listOptions->getSearch(); | | 27 | + $sort = $listOptions->getSort(); | | 28 | + if ($sort === 'name' && $nameFilter) { | | 29 | + $sort = 'value'; | | 30 | + } | | 31 | + | 25 | 32 | $query = Tag::query() | 26 | 33 | ->select([ | 27 | 34 | 'name', | @@ -32,7 +39,7 @@ public function queryWithTotals(string $searchTerm, string $nameFilter): Builder | 32 | 39 | DB::raw('SUM(IF(entity_type = \'book\', 1, 0)) as book_count'), | 33 | 40 | DB::raw('SUM(IF(entity_type = \'bookshelf\', 1, 0)) as shelf_count'), | 34 | 41 | ]) | 35 | | - ->orderBy($nameFilter ? 'value' : 'name'); | | 42 | + ->orderBy($sort, $listOptions->getOrder()); | 36 | 43 |
| 37 | 44 | if ($nameFilter) { | 38 | 45 | $query->where('name', '=', $nameFilter); | |
Collapse file Copy file name to clipboard +35Lines changed: 35 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboardExpand all lines: app/Auth/Queries/UsersAllPaginatedAndSorted.php +10-9Lines changed: 10 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | namespace BookStack\Auth\Queries; | 4 | 4 |
| 5 | 5 | use BookStack\Auth\User; | | 6 | +use BookStack\Util\SimpleListOptions; | 6 | 7 | use Illuminate\Pagination\LengthAwarePaginator; | 7 | 8 |
| 8 | 9 | /** | | 11 | 12 | * user is assumed to be trusted. (Admin users). | 12 | 13 | * Email search can be abused to extract email addresses. | 13 | 14 | */ | 14 | | -class AllUsersPaginatedAndSorted | | 15 | +class UsersAllPaginatedAndSorted | 15 | 16 | { | 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 | 20 | 18 | { | 21 | | - $sort = $sortData['sort']; | | 19 | + $sort = $listOptions->getSort(); | | 20 | + if ($sort === 'created_at') { | | 21 | + $sort = 'users.created_at'; | | 22 | + } | 22 | 23 |
| 23 | 24 | $query = User::query()->select(['*']) | 24 | 25 | ->scopes(['withLastActivityAt']) | 25 | 26 | ->with(['roles', 'avatar']) | 26 | 27 | ->withCount('mfaValues') | 27 | | - ->orderBy($sort, $sortData['order']); | | 28 | + ->orderBy($sort, $listOptions->getOrder()); | 28 | 29 |
| 29 | | - if ($sortData['search']) { | 30 | | - $term = '%' . $sortData['search'] . '%'; | | 30 | + if ($listOptions->getSearch()) { | | 31 | + $term = '%' . $listOptions->getSearch() . '%'; | 31 | 32 | $query->where(function ($query) use ($term) { | 32 | 33 | $query->where('name', 'like', $term) | 33 | 34 | ->orWhere('email', 'like', $term); | |
Collapse file Copy file name to clipboardExpand all lines: app/Auth/Role.php -8Lines changed: 0 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -110,14 +110,6 @@ public static function getSystemRole(string $systemName): ?self | 110 | 110 | return static::query()->where('system_name', '=', $systemName)->first(); | 111 | 111 | } | 112 | 112 |
| 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 | | - | 121 | 113 | /** | 122 | 114 | * {@inheritdoc} | 123 | 115 | */ | |
Collapse file Copy file name to clipboardExpand all lines: app/Http/Controllers/AuditLogController.php +26-20Lines changed: 26 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | namespace BookStack\Http\Controllers; | 4 | 4 |
| 5 | 5 | use BookStack\Actions\Activity; | | 6 | +use BookStack\Actions\ActivityType; | | 7 | +use BookStack\Util\SimpleListOptions; | 6 | 8 | use Illuminate\Http\Request; | 7 | 9 | use Illuminate\Support\Facades\DB; | 8 | 10 |
| @@ -13,10 +15,15 @@ public function index(Request $request) | 13 | 15 | $this->checkPermission('settings-manage'); | 14 | 16 | $this->checkPermission('users-manage'); | 15 | 17 |
| 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 = [ | 18 | 26 | 'event' => $request->get('event', ''), | 19 | | - 'sort' => $request->get('sort', 'created_at'), | 20 | 27 | 'date_from' => $request->get('date_from', ''), | 21 | 28 | 'date_to' => $request->get('date_to', ''), | 22 | 29 | 'user' => $request->get('user', ''), | @@ -25,39 +32,38 @@ public function index(Request $request) | 25 | 32 |
| 26 | 33 | $query = Activity::query() | 27 | 34 | ->with([ | 28 | | - 'entity' => function ($query) { | 29 | | - $query->withTrashed(); | 30 | | - }, | | 35 | + 'entity' => fn ($query) => $query->withTrashed(), | 31 | 36 | 'user', | 32 | 37 | ]) | 33 | | - ->orderBy($listDetails['sort'], $listDetails['order']); | | 38 | + ->orderBy($listOptions->getSort(), $listOptions->getOrder()); | 34 | 39 |
| 35 | | - if ($listDetails['event']) { | 36 | | - $query->where('type', '=', $listDetails['event']); | | 40 | + if ($filters['event']) { | | 41 | + $query->where('type', '=', $filters['event']); | 37 | 42 | } | 38 | | - if ($listDetails['user']) { | 39 | | - $query->where('user_id', '=', $listDetails['user']); | | 43 | + if ($filters['user']) { | | 44 | + $query->where('user_id', '=', $filters['user']); | 40 | 45 | } | 41 | 46 |
| 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']); | 44 | 49 | } | 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']); | 47 | 52 | } | 48 | | - if ($listDetails['ip']) { | 49 | | - $query->where('ip', 'like', $listDetails['ip'] . '%'); | | 53 | + if ($filters['ip']) { | | 54 | + $query->where('ip', 'like', $filters['ip'] . '%'); | 50 | 55 | } | 51 | 56 |
| 52 | 57 | $activities = $query->paginate(100); | 53 | | - $activities->appends($listDetails); | | 58 | + $activities->appends($request->all()); | 54 | 59 |
| 55 | | - $types = DB::table('activities')->select('type')->distinct()->pluck('type'); | | 60 | + $types = ActivityType::all(); | 56 | 61 | $this->setPageTitle(trans('settings.audit')); | 57 | 62 |
| 58 | 63 | return view('settings.audit', [ | 59 | 64 | 'activities' => $activities, | 60 | | - 'listDetails' => $listDetails, | | 65 | + 'filters' => $filters, | | 66 | + 'listOptions' => $listOptions, | 61 | 67 | 'activityTypes' => $types, | 62 | 68 | ]); | 63 | 69 | } | |
Collapse file Copy file name to clipboardExpand all lines: app/Http/Controllers/BookController.php +9-6Lines changed: 9 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | use BookStack\Exceptions\NotFoundException; | 16 | 16 | use BookStack\Facades\Activity; | 17 | 17 | use BookStack\References\ReferenceFetcher; | | 18 | +use BookStack\Util\SimpleListOptions; | 18 | 19 | use Illuminate\Http\Request; | 19 | 20 | use Illuminate\Validation\ValidationException; | 20 | 21 | use Throwable; | @@ -35,13 +36,16 @@ public function __construct(ShelfContext $entityContextManager, BookRepo $bookRe | 35 | 36 | /** | 36 | 37 | * Display a listing of the book. | 37 | 38 | */ | 38 | | - public function index() | | 39 | + public function index(Request $request) | 39 | 40 | { | 40 | 41 | $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 | + ]); | 43 | 47 |
| 44 | | - $books = $this->bookRepo->getAllPaginated(18, $sort, $order); | | 48 | + $books = $this->bookRepo->getAllPaginated(18, $listOptions->getSort(), $listOptions->getOrder()); | 45 | 49 | $recents = $this->isSignedIn() ? $this->bookRepo->getRecentlyViewed(4) : false; | 46 | 50 | $popular = $this->bookRepo->getPopular(4); | 47 | 51 | $new = $this->bookRepo->getRecentlyCreated(4); | @@ -56,8 +60,7 @@ public function index() | 56 | 60 | 'popular' => $popular, | 57 | 61 | 'new' => $new, | 58 | 62 | 'view' => $view, | 59 | | - 'sort' => $sort, | 60 | | - 'order' => $order, | | 63 | + 'listOptions' => $listOptions, | 61 | 64 | ]); | 62 | 65 | } | 63 | 66 |
| |
|