mirror of
https://github.com/pelican-dev/panel.git
synced 2025-09-21 10:34:48 +02:00
Add state cast for server condition (#1713)
This commit is contained in:
parent
3d2390dbcc
commit
932809fec5
@ -8,6 +8,7 @@ use App\Filament\Admin\Resources\Servers\RelationManagers\DatabasesRelationManag
|
|||||||
use App\Filament\Admin\Resources\Servers\ServerResource;
|
use App\Filament\Admin\Resources\Servers\ServerResource;
|
||||||
use App\Filament\Components\Actions\PreviewStartupAction;
|
use App\Filament\Components\Actions\PreviewStartupAction;
|
||||||
use App\Filament\Components\Forms\Fields\StartupVariable;
|
use App\Filament\Components\Forms\Fields\StartupVariable;
|
||||||
|
use App\Filament\Components\StateCasts\ServerConditionStateCast;
|
||||||
use App\Filament\Server\Pages\Console;
|
use App\Filament\Server\Pages\Console;
|
||||||
use App\Models\Allocation;
|
use App\Models\Allocation;
|
||||||
use App\Models\Egg;
|
use App\Models\Egg;
|
||||||
@ -135,6 +136,7 @@ class EditServer extends EditRecord
|
|||||||
->options(fn ($state) => [$state->value => $state->getLabel()])
|
->options(fn ($state) => [$state->value => $state->getLabel()])
|
||||||
->colors(fn ($state) => [$state->value => $state->getColor()])
|
->colors(fn ($state) => [$state->value => $state->getColor()])
|
||||||
->icons(fn ($state) => [$state->value => $state->getIcon()])
|
->icons(fn ($state) => [$state->value => $state->getIcon()])
|
||||||
|
->stateCast(new ServerConditionStateCast())
|
||||||
->columnSpan([
|
->columnSpan([
|
||||||
'default' => 2,
|
'default' => 2,
|
||||||
'sm' => 1,
|
'sm' => 1,
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Components\StateCasts;
|
||||||
|
|
||||||
|
use App\Enums\ContainerStatus;
|
||||||
|
use App\Enums\ServerState;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||||
|
|
||||||
|
class ServerConditionStateCast implements StateCast
|
||||||
|
{
|
||||||
|
public function get(mixed $state): ?BackedEnum
|
||||||
|
{
|
||||||
|
if (blank($state)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($state instanceof ServerState || $state instanceof ContainerStatus) {
|
||||||
|
return $state;
|
||||||
|
}
|
||||||
|
|
||||||
|
$serverState = ServerState::tryFrom($state);
|
||||||
|
if ($serverState) {
|
||||||
|
return $serverState;
|
||||||
|
}
|
||||||
|
|
||||||
|
$containerStatus = ContainerStatus::tryFrom($state);
|
||||||
|
if ($containerStatus) {
|
||||||
|
return $containerStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set(mixed $state): mixed
|
||||||
|
{
|
||||||
|
if (!($state instanceof BackedEnum)) {
|
||||||
|
return $state;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $state->value;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user