mirror of
https://github.com/pelican-dev/panel.git
synced 2025-09-20 12:54:43 +02:00
Fix powerActions visible while loading (#1708)
This commit is contained in:
parent
ce393af7a6
commit
68f8244298
@ -112,7 +112,7 @@ class ListServers extends ListRecords
|
||||
->poll('15s')
|
||||
->columns($usingGrid ? $this->gridColumns() : $this->tableColumns())
|
||||
->recordUrl(!$usingGrid ? (fn (Server $server) => Console::getUrl(panel: 'server', tenant: $server)) : null)
|
||||
->recordActions(!$usingGrid ? ActionGroup::make(static::getPowerActions(view: 'table')) : [])
|
||||
->recordActions(!$usingGrid ? static::getPowerActionGroup() : [])
|
||||
->recordActionsAlignment(Alignment::Center->value)
|
||||
->contentGrid($usingGrid ? ['default' => 1, 'md' => 2] : null)
|
||||
->emptyStateIcon('tabler-brand-docker')
|
||||
@ -225,47 +225,43 @@ class ListServers extends ListRecords
|
||||
}
|
||||
}
|
||||
|
||||
/** @return Action[]|ActionGroup[] */
|
||||
public static function getPowerActions(string $view): array
|
||||
public static function getPowerActionGroup(): ActionGroup
|
||||
{
|
||||
$actions = [
|
||||
return ActionGroup::make([
|
||||
Action::make('start')
|
||||
->label(trans('server/console.power_actions.start'))
|
||||
->color('primary')
|
||||
->icon('tabler-player-play-filled')
|
||||
->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->retrieveStatus()->isStartable())
|
||||
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'start']),
|
||||
Action::make('restart')
|
||||
->label(trans('server/console.power_actions.restart'))
|
||||
->color('gray')
|
||||
->icon('tabler-reload')
|
||||
->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->retrieveStatus()->isRestartable())
|
||||
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'restart']),
|
||||
Action::make('stop')
|
||||
->label(trans('server/console.power_actions.stop'))
|
||||
->color('danger')
|
||||
->icon('tabler-player-stop-filled')
|
||||
->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->retrieveStatus()->isStoppable() && !$server->retrieveStatus()->isKillable())
|
||||
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'stop']),
|
||||
Action::make('kill')
|
||||
->label(trans('server/console.power_actions.kill'))
|
||||
->color('danger')
|
||||
->icon('tabler-alert-square')
|
||||
->tooltip('This can result in data corruption and/or data loss!')
|
||||
->tooltip(trans('server/console.power_actions.kill_tooltip'))
|
||||
->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->retrieveStatus()->isKillable())
|
||||
->dispatch('powerAction', fn (Server $server) => ['server' => $server, 'action' => 'kill']),
|
||||
];
|
||||
|
||||
if ($view === 'table') {
|
||||
return $actions;
|
||||
} else {
|
||||
return [
|
||||
ActionGroup::make($actions)
|
||||
->icon('tabler-power')
|
||||
->color('primary')
|
||||
->tooltip('Power Actions')
|
||||
->iconSize(IconSize::Large),
|
||||
];
|
||||
}
|
||||
])
|
||||
->icon('tabler-power')
|
||||
->color('primary')
|
||||
->tooltip(trans('server/dashboard.power_actions'))
|
||||
->hidden(fn (Server $server) => $server->isInConflictState())
|
||||
->iconSize(IconSize::Large);
|
||||
}
|
||||
}
|
||||
|
@ -158,45 +158,52 @@ class Console extends Page
|
||||
/** @return array<Action|ActionGroup> */
|
||||
protected function getDefaultHeaderActions(): array
|
||||
{
|
||||
/** @var Server $server */
|
||||
$server = Filament::getTenant();
|
||||
|
||||
return [
|
||||
Action::make('start')
|
||||
->label(trans('server/console.power_actions.start'))
|
||||
->color('primary')
|
||||
->size(Size::ExtraLarge)
|
||||
->action(fn () => $this->dispatch('setServerState', state: 'start', uuid: $server->uuid))
|
||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_START, $server))
|
||||
->disabled(fn () => $server->isInConflictState() || !$this->status->isStartable())
|
||||
->icon('tabler-player-play-filled'),
|
||||
Action::make('restart')
|
||||
->label(trans('server/console.power_actions.restart'))
|
||||
->color('gray')
|
||||
->size(Size::ExtraLarge)
|
||||
->action(fn () => $this->dispatch('setServerState', state: 'restart', uuid: $server->uuid))
|
||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_RESTART, $server))
|
||||
->disabled(fn () => $server->isInConflictState() || !$this->status->isRestartable())
|
||||
->icon('tabler-reload'),
|
||||
Action::make('stop')
|
||||
->label(trans('server/console.power_actions.stop'))
|
||||
->color('danger')
|
||||
->size(Size::ExtraLarge)
|
||||
->action(fn () => $this->dispatch('setServerState', state: 'stop', uuid: $server->uuid))
|
||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server))
|
||||
->hidden(fn () => $this->status->isStartingOrStopping() || $this->status->isKillable())
|
||||
->disabled(fn () => $server->isInConflictState() || !$this->status->isStoppable())
|
||||
->icon('tabler-player-stop-filled'),
|
||||
Action::make('kill')
|
||||
->label(trans('server/console.power_actions.kill'))
|
||||
->color('danger')
|
||||
->tooltip(trans('server/console.power_actions.kill_tooltip'))
|
||||
->requiresConfirmation()
|
||||
->size(Size::ExtraLarge)
|
||||
->action(fn () => $this->dispatch('setServerState', state: 'kill', uuid: $server->uuid))
|
||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server))
|
||||
->hidden(fn () => $server->isInConflictState() || !$this->status->isKillable())
|
||||
->icon('tabler-alert-square'),
|
||||
ActionGroup::make([
|
||||
Action::make('start')
|
||||
->label(trans('server/console.power_actions.start'))
|
||||
->color('primary')
|
||||
->icon('tabler-player-play-filled')
|
||||
->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_START, $server))
|
||||
->disabled(fn (Server $server) => $server->isInConflictState() || !$this->status->isStartable())
|
||||
->action(fn (Server $server) => $this->dispatch('setServerState', uuid: $server->uuid, state: 'start'))
|
||||
->size(Size::ExtraLarge),
|
||||
Action::make('restart')
|
||||
->label(trans('server/console.power_actions.restart'))
|
||||
->color('gray')
|
||||
->icon('tabler-reload')
|
||||
->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_RESTART, $server))
|
||||
->disabled(fn (Server $server) => $server->isInConflictState() || !$this->status->isRestartable())
|
||||
->action(fn (Server $server) => $this->dispatch('setServerState', uuid: $server->uuid, state: 'restart'))
|
||||
->size(Size::ExtraLarge),
|
||||
Action::make('stop')
|
||||
->label(trans('server/console.power_actions.stop'))
|
||||
->color('danger')
|
||||
->icon('tabler-player-stop-filled')
|
||||
->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server))
|
||||
->visible(fn () => !$this->status->isKillable())
|
||||
->disabled(fn (Server $server) => $server->isInConflictState() || !$this->status->isStoppable())
|
||||
->action(fn (Server $server) => $this->dispatch('setServerState', uuid: $server->uuid, state: 'stop'))
|
||||
->size(Size::ExtraLarge),
|
||||
Action::make('kill')
|
||||
->label(trans('server/console.power_actions.kill'))
|
||||
->color('danger')
|
||||
->icon('tabler-alert-square')
|
||||
->tooltip(trans('server/console.power_actions.kill_tooltip'))
|
||||
->requiresConfirmation()
|
||||
->authorize(fn (Server $server) => auth()->user()->can(Permission::ACTION_CONTROL_STOP, $server))
|
||||
->visible(fn () => $this->status->isKillable())
|
||||
->disabled(fn (Server $server) => $server->isInConflictState() || !$this->status->isKillable())
|
||||
->action(fn (Server $server) => $this->dispatch('setServerState', uuid: $server->uuid, state: 'kill'))
|
||||
->size(Size::ExtraLarge),
|
||||
])
|
||||
->record(function () {
|
||||
/** @var Server $server */
|
||||
$server = Filament::getTenant();
|
||||
|
||||
return $server;
|
||||
})
|
||||
->buttonGroup(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
@php
|
||||
$actiongroup = \App\Filament\App\Resources\Servers\Pages\ListServers::getPowerActionGroup()->record($server);
|
||||
@endphp
|
||||
|
||||
<div wire:poll.15s
|
||||
class="relative cursor-pointer"
|
||||
x-on:click="window.location.href = '{{ \App\Filament\Server\Pages\Console::getUrl(panel: 'server', tenant: $server) }}'">
|
||||
@ -20,13 +24,13 @@
|
||||
({{ $server->formatResource(\App\Enums\ServerResourceType::Uptime) }})
|
||||
</span>
|
||||
</h2>
|
||||
<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">
|
||||
@foreach (\App\Filament\App\Resources\Servers\Pages\ListServers::getPowerActions(view: 'grid') as $action)
|
||||
{{ $action->record($server) }}
|
||||
@endforeach
|
||||
@if ($actiongroup->isVisible())
|
||||
<div class="end-0">
|
||||
<div class="flex-1 dark:bg-gray-800 dark:text-white rounded-b-lg overflow-hidden p-1" x-on:click.stop>
|
||||
{{ $actiongroup }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between text-center items-center gap-4">
|
||||
|
Loading…
x
Reference in New Issue
Block a user