Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix power buttons #799

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions app/Filament/Server/Pages/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Server\Pages;

use App\Enums\ContainerStatus;
use App\Filament\Server\Widgets\ServerConsole;
use App\Filament\Server\Widgets\ServerCpuChart;
use App\Filament\Server\Widgets\ServerMemoryChart;
Expand All @@ -12,6 +13,7 @@
use Filament\Facades\Filament;
use Filament\Pages\Page;
use Filament\Support\Enums\ActionSize;
use Livewire\Attributes\On;

class Console extends Page
{
Expand All @@ -21,6 +23,8 @@ class Console extends Page

protected static string $view = 'filament.server.pages.console';

public ContainerStatus $status = ContainerStatus::Missing;

public function getWidgetData(): array
{
return [
Expand Down Expand Up @@ -50,6 +54,16 @@ public function getColumns(): int|string|array
return 3;
}

#[On('powerChanged')]
public function powerChanged(string $state): void
{
$this->status = ContainerStatus::from($state);

$this->cachedHeaderActions = [];

$this->cacheHeaderActions();
}

protected function getHeaderActions(): array
{
/** @var Server $server */
Expand All @@ -60,17 +74,18 @@ protected function getHeaderActions(): array
->color('primary')
->size(ActionSize::ExtraLarge)
->action(fn () => $this->dispatch('setServerState', state: 'start'))
->disabled(fn () => $server->isInConflictState()),
->disabled(fn () => $server->isInConflictState() || in_array($this->status, [ContainerStatus::Running, ContainerStatus::Starting, ContainerStatus::Stopping, ContainerStatus::Restarting])),
Action::make('restart')
->color('gray')
->size(ActionSize::ExtraLarge)
->action(fn () => $this->dispatch('setServerState', state: 'restart'))
->disabled(fn () => $server->isInConflictState() || $server->retrieveStatus() == 'offline'),
->disabled(fn () => $server->isInConflictState() || $this->status !== ContainerStatus::Running),
Action::make('stop')
->color('danger')
->size(ActionSize::ExtraLarge)
->action(fn () => $this->dispatch('setServerState', state: 'stop'))
->disabled(fn () => $server->isInConflictState() || $server->retrieveStatus() == 'offline'),
->hidden(fn () => in_array($this->status, [ContainerStatus::Stopping, ContainerStatus::Restarting, ContainerStatus::Starting]))
->disabled(fn () => $server->isInConflictState() || in_array($this->status, [ContainerStatus::Starting, ContainerStatus::Stopping, ContainerStatus::Restarting, ContainerStatus::Exited, ContainerStatus::Offline])),
Action::make('kill')
->color('danger')
->requiresConfirmation()
Expand All @@ -79,7 +94,8 @@ protected function getHeaderActions(): array
->modalSubmitActionLabel('Kill Server')
->size(ActionSize::ExtraLarge)
->action(fn () => $this->dispatch('setServerState', state: 'kill'))
->disabled(fn () => $server->isInConflictState() || $server->retrieveStatus() == 'offline'),
->hidden(fn () => $server->isInConflictState() || in_array($this->status, [ContainerStatus::Running, ContainerStatus::Restarting, ContainerStatus::Offline, ContainerStatus::Removing, ContainerStatus::Dead, ContainerStatus::Exited, ContainerStatus::Created]))
->disabled(fn () => $server->isInConflictState() || $this->status === ContainerStatus::Offline),
];
}
}
2 changes: 2 additions & 0 deletions resources/views/filament/components/server-console.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class="w-full focus:outline-none focus:ring-0 border-none"
break;
case 'status':
handlePowerChangeEvent(args[0]);

$wire.dispatch('powerChanged', {state: args[0]})
break;
case 'transfer status':
handleTransferStatus(args[0]);
Expand Down
Loading