This commit is contained in:
notCharles 2025-06-24 18:42:50 -04:00
parent 11b3acf8fc
commit 4f3e07d4e4
2 changed files with 68 additions and 61 deletions

View File

@ -238,34 +238,34 @@ class ListServers extends ListRecords
} }
/** @return Action[] */ /** @return Action[] */
public static function getPowerActions(): array public static function getPowerActions(Server $server): array
{ {
return [ return [
Action::make('start') Action::make('start')
->color('primary') ->color('primary')
->icon('tabler-player-play-filled') ->icon('tabler-player-play-filled')
->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_START, $server)) ->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_START, $server))
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isStartable()) ->visible(fn () => !$server->isInConflictState() & $server->retrieveStatus()->isStartable())
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'start']), ->dispatch('powerAction', fn () => ['server' => $server, 'action' => 'start']),
Action::make('restart') Action::make('restart')
->color('gray') ->color('gray')
->icon('tabler-reload') ->icon('tabler-reload')
->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_RESTART, $server)) ->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_RESTART, $server))
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isRestartable()) ->visible(fn () => !$server->isInConflictState() & $server->retrieveStatus()->isRestartable())
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'restart']), ->dispatch('powerAction', fn () => ['server' => $server, 'action' => 'restart']),
Action::make('stop') Action::make('stop')
->color('danger') ->color('danger')
->icon('tabler-player-stop-filled') ->icon('tabler-player-stop-filled')
->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server)) ->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server))
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isStoppable()) ->visible(fn () => !$server->isInConflictState() & $server->retrieveStatus()->isStoppable())
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'stop']), ->dispatch('powerAction', fn () => ['server' => $server, 'action' => 'stop']),
Action::make('kill') Action::make('kill')
->color('danger') ->color('danger')
->icon('tabler-alert-square') ->icon('tabler-alert-square')
->tooltip('This can result in data corruption and/or data loss!') ->tooltip('This can result in data corruption and/or data loss!')
->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server)) ->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server))
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isKillable()) ->visible(fn () => !$server->isInConflictState() & $server->retrieveStatus()->isKillable())
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'kill']), ->dispatch('powerAction', fn () => ['server' => $server, 'action' => 'kill']),
]; ];
} }
} }

View File

@ -1,11 +1,13 @@
<div wire:poll.15s class="relative"> <div wire:poll.15s
<a href="{{ \App\Filament\Server\Pages\Console::getUrl(panel: 'server', tenant: $server) }}" wire:navigate> class="relative cursor-pointer"
<div x-on:click="window.location.href = '{{ \App\Filament\Server\Pages\Console::getUrl(panel: 'server', tenant: $server) }}'">
class="absolute left-0 top-1 bottom-0 w-1 rounded-lg"
<div class="absolute left-0 top-1 bottom-0 w-1 rounded-lg"
style="background-color: {{ $server->condition->getColor(true) }};"> style="background-color: {{ $server->condition->getColor(true) }};">
</div> </div>
<div class="flex-1 dark:bg-gray-800 dark:text-white rounded-lg overflow-hidden p-3"> <div class="flex-1 dark:bg-gray-800 dark:text-white rounded-lg overflow-hidden p-3">
<div class="flex items-center mb-5 gap-2"> <div class="flex items-center mb-5 gap-2">
<x-filament::icon-button <x-filament::icon-button
:icon="$server->condition->getIcon()" :icon="$server->condition->getIcon()"
@ -15,11 +17,13 @@
/> />
<h2 class="text-xl font-bold"> <h2 class="text-xl font-bold">
{{ $server->name }} {{ $server->name }}
<span class="dark:text-gray-400">({{ $server->formatResource('uptime', type: \App\Enums\ServerResourceType::Time) }})</span> <span class="dark:text-gray-400">
({{ $server->formatResource('uptime', type: \App\Enums\ServerResourceType::Time) }})
</span>
</h2> </h2>
</div> </div>
<div class="flex justify-between text-center"> <div class="flex justify-between text-center items-center gap-4">
<div> <div>
<p class="text-sm dark:text-gray-400">CPU</p> <p class="text-sm dark:text-gray-400">CPU</p>
<p class="text-md font-semibold">{{ $server->formatResource('cpu_absolute', type: \App\Enums\ServerResourceType::Percentage) }}</p> <p class="text-md font-semibold">{{ $server->formatResource('cpu_absolute', type: \App\Enums\ServerResourceType::Percentage) }}</p>
@ -43,13 +47,16 @@
<hr class="p-0.5"> <hr class="p-0.5">
<p class="text-md font-semibold">{{ $server->allocation->address }} </p> <p class="text-md font-semibold">{{ $server->allocation->address }} </p>
</div> </div>
</div> <div x-on:click.stop>
</div> <x-filament-actions::group
</a> :actions="\App\Filament\App\Resources\ServerResource\Pages\ListServers::getPowerActions($server)"
size="xl"
<x-filament-tables::actions icon="tabler-power"
:actions="\App\Filament\App\Resources\ServerResource\Pages\ListServers::getPowerActions()" tooltip="Power Actions"
:alignment="\Filament\Support\Enums\Alignment::Center"
:record="$server"
/> />
</div> </div>
</div>
</div>
<x-filament-actions::modals />
</div>