Fix port pagination (#16127)

* Fix ports pagination

* Style fix
This commit is contained in:
Tony Murray
2024-06-17 02:28:36 -05:00
committed by GitHub
parent 67851188f1
commit 8c4caab81a
2 changed files with 10 additions and 6 deletions

View File

@@ -41,7 +41,7 @@ use LibreNMS\Interfaces\UI\DeviceTab;
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';
@@ -68,7 +68,8 @@ class PortsController implements DeviceTab
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',
@@ -113,8 +114,10 @@ class PortsController implements DeviceTab
$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)
->appends('perPage', $this->perPage);
$data = [
'ports' => $ports,