From dbe02f6b2c043e90930e2f2752521f478616e7e8 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Sun, 1 Dec 2024 16:44:15 +0100 Subject: [PATCH] add sorting to server list --- .../ServerResource/Pages/ListServers.php | 12 ++++---- .../2024_12_01_152938_add_sort_to_servers.php | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2024_12_01_152938_add_sort_to_servers.php diff --git a/app/Filament/App/Resources/ServerResource/Pages/ListServers.php b/app/Filament/App/Resources/ServerResource/Pages/ListServers.php index 8becc75542..84e9f16da0 100644 --- a/app/Filament/App/Resources/ServerResource/Pages/ListServers.php +++ b/app/Filament/App/Resources/ServerResource/Pages/ListServers.php @@ -21,6 +21,8 @@ public function table(Table $table): Table return $table ->paginated(false) ->query(fn () => auth()->user()->can('viewList server') ? Server::query() : auth()->user()->accessibleServers()) + ->reorderable('sort') + ->defaultSort('sort') ->columns([ Stack::make([ ServerEntryColumn::make('server_entry') @@ -40,7 +42,7 @@ public function table(Table $table): Table // @phpstan-ignore-next-line private function uptime(Server $server): string { - $uptime = collect(cache()->get("servers.{$server->id}.uptime"))->last() ?? 0; + $uptime = collect(cache()->get("servers.$server->id.uptime"))->last() ?? 0; if ($uptime === 0) { return 'Offline'; @@ -52,7 +54,7 @@ private function uptime(Server $server): string // @phpstan-ignore-next-line private function cpu(Server $server): string { - $cpu = Number::format(collect(cache()->get("servers.{$server->id}.cpu_absolute"))->last() ?? 0, maxPrecision: 2, locale: auth()->user()->language) . '%'; + $cpu = Number::format(collect(cache()->get("servers.$server->id.cpu_absolute"))->last() ?? 0, maxPrecision: 2, locale: auth()->user()->language) . '%'; $max = Number::format($server->cpu, locale: auth()->user()->language) . '%'; return $cpu . ($server->cpu > 0 ? ' Of ' . $max : ''); @@ -61,8 +63,8 @@ private function cpu(Server $server): string // @phpstan-ignore-next-line private function memory(Server $server): string { - $latestMemoryUsed = collect(cache()->get("servers.{$server->id}.memory_bytes"))->last() ?? 0; - $totalMemory = collect(cache()->get("servers.{$server->id}.memory_limit_bytes"))->last() ?? 0; + $latestMemoryUsed = collect(cache()->get("servers.$server->id.memory_bytes"))->last() ?? 0; + $totalMemory = collect(cache()->get("servers.$server->id.memory_limit_bytes"))->last() ?? 0; $used = config('panel.use_binary_prefix') ? Number::format($latestMemoryUsed / 1024 / 1024 / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB' @@ -84,7 +86,7 @@ private function memory(Server $server): string // @phpstan-ignore-next-line private function disk(Server $server): string { - $usedDisk = collect(cache()->get("servers.{$server->id}.disk_bytes"))->last() ?? 0; + $usedDisk = collect(cache()->get("servers.$server->id.disk_bytes"))->last() ?? 0; $used = config('panel.use_binary_prefix') ? Number::format($usedDisk / 1024 / 1024 / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB' diff --git a/database/migrations/2024_12_01_152938_add_sort_to_servers.php b/database/migrations/2024_12_01_152938_add_sort_to_servers.php new file mode 100644 index 0000000000..2fe4c22053 --- /dev/null +++ b/database/migrations/2024_12_01_152938_add_sort_to_servers.php @@ -0,0 +1,28 @@ +unsignedSmallInteger('sort')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('sort'); + }); + } +};