mirror of
https://github.com/pelican-dev/panel.git
synced 2025-07-03 07:21:08 +02:00
Simplify states and statuses and resolve #362
This commit is contained in:
parent
7986505b99
commit
958e8fac8a
@ -12,6 +12,7 @@ enum ContainerStatus: string
|
||||
case Paused = 'paused';
|
||||
case Dead = 'dead';
|
||||
case Removing = 'removing';
|
||||
case Offline = 'offline';
|
||||
|
||||
// HTTP Based
|
||||
case Missing = 'missing';
|
||||
@ -27,6 +28,7 @@ enum ContainerStatus: string
|
||||
self::Dead => 'tabler-heart-x',
|
||||
self::Removing => 'tabler-heart-down',
|
||||
self::Missing => 'tabler-heart-question',
|
||||
self::Offline => 'tabler-heart-bolt',
|
||||
};
|
||||
}
|
||||
|
||||
@ -41,6 +43,7 @@ enum ContainerStatus: string
|
||||
self::Dead => 'danger',
|
||||
self::Removing => 'warning',
|
||||
self::Missing => 'danger',
|
||||
self::Offline => 'gray',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -39,47 +39,19 @@ class EditServer extends EditRecord
|
||||
'lg' => 4,
|
||||
])
|
||||
->schema([
|
||||
Forms\Components\ToggleButtons::make('docker')
|
||||
->label('Container Status')->inline()->inlineLabel()
|
||||
->formatStateUsing(function ($state, Server $server) {
|
||||
if ($server->node_id === null) {
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/** @var DaemonServerRepository $service */
|
||||
$service = resolve(DaemonServerRepository::class);
|
||||
$details = $service->setServer($server)->getDetails();
|
||||
|
||||
return $details['state'] ?? 'unknown';
|
||||
})
|
||||
->options(fn ($state) => collect(ContainerStatus::cases())->filter(fn ($containerStatus) => $containerStatus->value === $state)->mapWithKeys(
|
||||
fn (ContainerStatus $state) => [$state->value => str($state->value)->replace('_', ' ')->ucwords()]
|
||||
Forms\Components\ToggleButtons::make('condition')
|
||||
->label('')
|
||||
->inline()
|
||||
->formatStateUsing(fn (Server $server) => $server->condition)
|
||||
->options(fn ($state) => collect(ContainerStatus::cases())->merge(ServerState::cases())
|
||||
->filter(fn ($condition) => $condition->value === $state)
|
||||
->mapWithKeys(fn ($state) => [$state->value => str($state->value)->replace('_', ' ')->ucwords()])
|
||||
)
|
||||
->colors(collect(ContainerStatus::cases())->merge(ServerState::cases())->mapWithKeys(
|
||||
fn ($status) => [$status->value => $status->color()]
|
||||
))
|
||||
->colors(collect(ContainerStatus::cases())->mapWithKeys(
|
||||
fn (ContainerStatus $status) => [$status->value => $status->color()]
|
||||
))
|
||||
->icons(collect(ContainerStatus::cases())->mapWithKeys(
|
||||
fn (ContainerStatus $status) => [$status->value => $status->icon()]
|
||||
))
|
||||
->columnSpan([
|
||||
'default' => 1,
|
||||
'sm' => 2,
|
||||
'md' => 2,
|
||||
'lg' => 2,
|
||||
]),
|
||||
|
||||
Forms\Components\ToggleButtons::make('status')
|
||||
->label('Server State')->inline()->inlineLabel()
|
||||
->helperText('')
|
||||
->formatStateUsing(fn ($state) => $state ?? ServerState::Normal)
|
||||
->options(fn ($state) => collect(ServerState::cases())->filter(fn ($serverState) => $serverState->value === $state)->mapWithKeys(
|
||||
fn (ServerState $state) => [$state->value => str($state->value)->replace('_', ' ')->ucwords()]
|
||||
))
|
||||
->colors(collect(ServerState::cases())->mapWithKeys(
|
||||
fn (ServerState $state) => [$state->value => $state->color()]
|
||||
))
|
||||
->icons(collect(ServerState::cases())->mapWithKeys(
|
||||
fn (ServerState $state) => [$state->value => $state->icon()]
|
||||
->icons(collect(ContainerStatus::cases())->merge(ServerState::cases())->mapWithKeys(
|
||||
fn ($status) => [$status->value => $status->icon()]
|
||||
))
|
||||
->columnSpan([
|
||||
'default' => 1,
|
||||
|
@ -29,28 +29,11 @@ class ListServers extends ListRecords
|
||||
Group::make('egg.name')->getDescriptionFromRecordUsing(fn (Server $server): string => str($server->egg->description)->limit(150)),
|
||||
])
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
Tables\Columns\TextColumn::make('condition')
|
||||
->default('unknown')
|
||||
->badge()
|
||||
->default(fn (Server $server) => $server->status ?? $server->retrieveStatus())
|
||||
->icon(fn ($state) => match ($state) {
|
||||
'node_fail' => 'tabler-server-off',
|
||||
'running' => 'tabler-heartbeat',
|
||||
'removing' => 'tabler-heart-x',
|
||||
'offline' => 'tabler-heart-off',
|
||||
'paused' => 'tabler-heart-pause',
|
||||
'installing' => 'tabler-heart-bolt',
|
||||
'suspended' => 'tabler-heart-cancel',
|
||||
default => 'tabler-heart-question',
|
||||
})
|
||||
->color(fn ($state): string => match ($state) {
|
||||
'running' => 'success',
|
||||
'installing', 'restarting' => 'primary',
|
||||
'paused', 'removing' => 'warning',
|
||||
'node_fail', 'install_failed', 'suspended' => 'danger',
|
||||
default => 'gray',
|
||||
}),
|
||||
|
||||
->icon(fn (Server $server) => $server->conditionIcon())
|
||||
->color(fn (Server $server) => $server->conditionColor()),
|
||||
Tables\Columns\TextColumn::make('uuid')
|
||||
->hidden()
|
||||
->label('UUID')
|
||||
|
@ -3,10 +3,12 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\EndpointCollection;
|
||||
use App\Enums\ContainerStatus;
|
||||
use App\Enums\ServerState;
|
||||
use App\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
use App\Models\Objects\Endpoint;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
@ -409,6 +411,35 @@ class Server extends Model
|
||||
return cache()->get("servers.$this->uuid.container.status") ?? 'missing';
|
||||
}
|
||||
|
||||
public function condition(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->status?->value ?? $this->retrieveStatus(),
|
||||
);
|
||||
}
|
||||
|
||||
public function conditionIcon(): string
|
||||
{
|
||||
if ($this->status === null) {
|
||||
$containerStatus = ContainerStatus::from($this->retrieveStatus());
|
||||
|
||||
return $containerStatus->icon();
|
||||
}
|
||||
|
||||
return $this->status->icon();
|
||||
}
|
||||
|
||||
public function conditionColor(): string
|
||||
{
|
||||
if ($this->status === null) {
|
||||
$containerStatus = ContainerStatus::from($this->retrieveStatus());
|
||||
|
||||
return $containerStatus->color();
|
||||
}
|
||||
|
||||
return $this->status->color();
|
||||
}
|
||||
|
||||
public function getPrimaryEndpoint(): ?Endpoint
|
||||
{
|
||||
$endpoint = $this->ports->first();
|
||||
|
Loading…
x
Reference in New Issue
Block a user