mirror of
https://github.com/pelican-dev/panel.git
synced 2025-09-10 00:08:52 +02:00
Fix table view power actions (#1490)
This commit is contained in:
parent
556551b4f3
commit
f8e802afcd
@ -110,7 +110,7 @@ class ListServers extends ListRecords
|
|||||||
->poll('15s')
|
->poll('15s')
|
||||||
->columns($usingGrid ? $this->gridColumns() : $this->tableColumns())
|
->columns($usingGrid ? $this->gridColumns() : $this->tableColumns())
|
||||||
->recordUrl(!$usingGrid ? (fn (Server $server) => Console::getUrl(panel: 'server', tenant: $server)) : null)
|
->recordUrl(!$usingGrid ? (fn (Server $server) => Console::getUrl(panel: 'server', tenant: $server)) : null)
|
||||||
->actions(!$usingGrid ? ActionGroup::make(static::getPowerActions()) : [])
|
->actions(!$usingGrid ? ActionGroup::make(static::getPowerActions(view: 'table')) : [])
|
||||||
->actionsAlignment(Alignment::Center->value)
|
->actionsAlignment(Alignment::Center->value)
|
||||||
->contentGrid($usingGrid ? ['default' => 1, 'md' => 2] : null)
|
->contentGrid($usingGrid ? ['default' => 1, 'md' => 2] : null)
|
||||||
->emptyStateIcon('tabler-brand-docker')
|
->emptyStateIcon('tabler-brand-docker')
|
||||||
@ -221,40 +221,46 @@ class ListServers extends ListRecords
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @return Action[]|ActionGroup[] */
|
/** @return Action[]|ActionGroup[] */
|
||||||
public static function getPowerActions(): array
|
public static function getPowerActions(string $view): array
|
||||||
{
|
{
|
||||||
return [
|
$actions = [
|
||||||
ActionGroup::make([
|
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 (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_START, $server))
|
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isStartable())
|
||||||
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isStartable())
|
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'start']),
|
||||||
->dispatch('powerAction', fn (Server $server) => ['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 (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_RESTART, $server))
|
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isRestartable())
|
||||||
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isRestartable())
|
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'restart']),
|
||||||
->dispatch('powerAction', fn (Server $server) => ['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 (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server))
|
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isStoppable())
|
||||||
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isStoppable())
|
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'stop']),
|
||||||
->dispatch('powerAction', fn (Server $server) => ['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 (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server))
|
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isKillable())
|
||||||
->visible(fn (Server $server) => !$server->isInConflictState() & $server->retrieveStatus()->isKillable())
|
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'kill']),
|
||||||
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'kill']),
|
|
||||||
])
|
|
||||||
->icon(fn (Server $server) => $server->condition->getIcon())
|
|
||||||
->color(fn (Server $server) => $server->condition->getColor())
|
|
||||||
->tooltip(fn (Server $server) => $server->condition->getLabel())
|
|
||||||
->iconSize(IconSize::Large),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($view === 'table') {
|
||||||
|
return $actions;
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
ActionGroup::make($actions)
|
||||||
|
->icon(fn (Server $server) => $server->condition->getIcon())
|
||||||
|
->color(fn (Server $server) => $server->condition->getColor())
|
||||||
|
->tooltip(fn (Server $server) => $server->condition->getLabel())
|
||||||
|
->iconSize(IconSize::Large),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<div class="end-0" x-on:click.stop>
|
<div class="end-0" x-on:click.stop>
|
||||||
<div class="flex-1 dark:bg-gray-800 dark:text-white rounded-b-lg overflow-hidden p-1">
|
<div class="flex-1 dark:bg-gray-800 dark:text-white rounded-b-lg overflow-hidden p-1">
|
||||||
<x-filament-tables::actions
|
<x-filament-tables::actions
|
||||||
:actions="\App\Filament\App\Resources\ServerResource\Pages\ListServers::getPowerActions()"
|
:actions="\App\Filament\App\Resources\ServerResource\Pages\ListServers::getPowerActions(view: 'grid')"
|
||||||
:alignment="\Filament\Support\Enums\Alignment::Center"
|
:alignment="\Filament\Support\Enums\Alignment::Center"
|
||||||
:record="$server"
|
:record="$server"
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user