Skip to content

Commit

Permalink
Fix sort
Browse files Browse the repository at this point in the history
  • Loading branch information
murrant committed Jun 16, 2024
1 parent 89d17c5 commit 471d81f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/Http/Controllers/Device/Tabs/PortsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PortsController implements DeviceTab
private bool $detail = false;
private int $perPage = 15;
private string $sortOrder = 'asc';
private string $sortColumn = 'default';

public function visible(Device $device): bool
{
Expand Down Expand Up @@ -97,7 +98,7 @@ public function data(Device $device, Request $request): array
],
'page_links' => $this->pageLinks($request),
'perPage' => $this->perPage,
'sort' => $this->sortOrder,
'sort' => $this->sortColumn,
'next_order' => $this->sortOrder == 'asc' ? 'desc' : 'asc',
], $data);
}
Expand Down Expand Up @@ -330,11 +331,14 @@ private function getFilteredPortsQuery(Device $device, Request $request, array $
{
$this->perPage = $request->input('perPage', 15);
$this->sortOrder = $request->input('order', 'asc');
$orderBy = match ($request->input('sort', 'port')) {
$this->sortColumn = $request->input('sort', 'default');

$orderBy = match ($this->sortColumn) {
'traffic' => \DB::raw('ports.ifInOctets_rate + ports.ifOutOctets_rate'),
'speed' => 'ifSpeed',
'media' => 'ifType',
'mac' => 'ifPhysAddress',
'port' => 'ifName',
default => 'ifIndex',
};

Expand Down

0 comments on commit 471d81f

Please sign in to comment.