Skip to content

Commit

Permalink
Fix port pagination (#16127)
Browse files Browse the repository at this point in the history
* Fix ports pagination

* Style fix
  • Loading branch information
murrant committed Jun 17, 2024
1 parent 6785118 commit 8c4caab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions app/Http/Controllers/Device/Tabs/PortsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
class PortsController implements DeviceTab
{
private bool $detail = false;
private int $perPage = 15;
private int|string $perPage = 15;
private string $sortOrder = 'asc';
private string $sortColumn = 'default';

Expand All @@ -68,7 +68,8 @@ public function name(): string
public function data(Device $device, Request $request): array
{
Validator::validate($request->all(), [
'perPage' => 'int',
'page' => 'int',
'perPage' => ['regex:/^(\d+|all)$/'],
'sort' => 'in:media,mac,port,traffic,speed',
'order' => 'in:asc,desc',
'disabled' => 'in:0,1',
Expand Down Expand Up @@ -113,8 +114,10 @@ private function portData(Device $device, Request $request): array
$relationships[] = 'ipv6Networks.ipv6';
}

/** @var Collection|LengthAwarePaginator<Port> $ports */
$ports = $this->getFilteredPortsQuery($device, $request, $relationships)->paginate($this->perPage);
/** @var Collection<Port>|LengthAwarePaginator<Port> $ports */
$ports = $this->getFilteredPortsQuery($device, $request, $relationships)
->paginate(fn ($total) => $this->perPage == 'all' ? $total : (int) $this->perPage)

Check failure on line 119 in app/Http/Controllers/Device/Tabs/PortsController.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Parameter #1 $perPage of method Illuminate\Database\Eloquent\Builder<Illuminate\Database\Eloquent\Model>::paginate() expects int|null, Closure given.
->appends('perPage', $this->perPage);

$data = [
'ports' => $ports,
Expand Down
5 changes: 3 additions & 2 deletions resources/views/device/tabs/ports/detail.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
<div class="tw-flex tw-flex-row-reverse tw-m-3">
{{ $data['ports']->links('pagination::tailwind', ['perPage' => $data['perPage']]) }}
@isset($data['perPage'])
<x-select :options="['10', '25', '100', 'all']"
<x-select :options="['15', '25', '100', 'all']"
{{-- location.herf = --}}
x-on:change="
const params = new URLSearchParams(window.location.search);
params.set('perPage', $event.target.value);
params.delete('page');
window.location.search = params.toString();
" x-data="{}"
:selected="$data['perPage']"
selected="{{ $data['perPage'] }}"
name="perPage"
label="{{ __('Per Page') }}"
class="tw-mx-4"></x-select>
Expand Down

0 comments on commit 8c4caab

Please sign in to comment.