mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 12:14:45 +02:00
* Simplify states and statuses and resolve #362 # Conflicts: # app/Models/Server.php * Move Random button... Moves button to the info tab --------- Co-authored-by: notCharles <charles@pelican.dev>
This commit is contained in:
parent
cf37994c3b
commit
efb834c8f7
@ -12,6 +12,7 @@ enum ContainerStatus: string
|
|||||||
case Paused = 'paused';
|
case Paused = 'paused';
|
||||||
case Dead = 'dead';
|
case Dead = 'dead';
|
||||||
case Removing = 'removing';
|
case Removing = 'removing';
|
||||||
|
case Offline = 'offline';
|
||||||
|
|
||||||
// HTTP Based
|
// HTTP Based
|
||||||
case Missing = 'missing';
|
case Missing = 'missing';
|
||||||
@ -27,6 +28,7 @@ enum ContainerStatus: string
|
|||||||
self::Dead => 'tabler-heart-x',
|
self::Dead => 'tabler-heart-x',
|
||||||
self::Removing => 'tabler-heart-down',
|
self::Removing => 'tabler-heart-down',
|
||||||
self::Missing => 'tabler-heart-question',
|
self::Missing => 'tabler-heart-question',
|
||||||
|
self::Offline => 'tabler-heart-bolt',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +43,7 @@ enum ContainerStatus: string
|
|||||||
self::Dead => 'danger',
|
self::Dead => 'danger',
|
||||||
self::Removing => 'warning',
|
self::Removing => 'warning',
|
||||||
self::Missing => 'danger',
|
self::Missing => 'danger',
|
||||||
|
self::Offline => 'gray',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ use App\Enums\ServerState;
|
|||||||
use App\Models\Egg;
|
use App\Models\Egg;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\ServerVariable;
|
use App\Models\ServerVariable;
|
||||||
use App\Repositories\Daemon\DaemonServerRepository;
|
|
||||||
use App\Services\Servers\ServerDeletionService;
|
use App\Services\Servers\ServerDeletionService;
|
||||||
use Filament\Forms\Components\Tabs;
|
use Filament\Forms\Components\Tabs;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
@ -44,55 +43,6 @@ class EditServer extends EditRecord
|
|||||||
'lg' => 4,
|
'lg' => 4,
|
||||||
])
|
])
|
||||||
->schema([
|
->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()]
|
|
||||||
))
|
|
||||||
->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()]
|
|
||||||
))
|
|
||||||
->columnSpan([
|
|
||||||
'default' => 1,
|
|
||||||
'sm' => 2,
|
|
||||||
'md' => 2,
|
|
||||||
'lg' => 2,
|
|
||||||
]),
|
|
||||||
|
|
||||||
Tabs::make('Tabs')
|
Tabs::make('Tabs')
|
||||||
->persistTabInQueryString()
|
->persistTabInQueryString()
|
||||||
->columnSpan(6)
|
->columnSpan(6)
|
||||||
@ -121,7 +71,7 @@ class EditServer extends EditRecord
|
|||||||
}))
|
}))
|
||||||
->columnSpan([
|
->columnSpan([
|
||||||
'default' => 2,
|
'default' => 2,
|
||||||
'sm' => 2,
|
'sm' => 1,
|
||||||
'md' => 2,
|
'md' => 2,
|
||||||
'lg' => 3,
|
'lg' => 3,
|
||||||
])
|
])
|
||||||
@ -133,15 +83,35 @@ class EditServer extends EditRecord
|
|||||||
->label('Owner')
|
->label('Owner')
|
||||||
->columnSpan([
|
->columnSpan([
|
||||||
'default' => 2,
|
'default' => 2,
|
||||||
'sm' => 2,
|
'sm' => 1,
|
||||||
'md' => 2,
|
'md' => 2,
|
||||||
'lg' => 3,
|
'lg' => 2,
|
||||||
])
|
])
|
||||||
->relationship('user', 'username')
|
->relationship('user', 'username')
|
||||||
->searchable()
|
->searchable()
|
||||||
->preload()
|
->preload()
|
||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
|
Forms\Components\ToggleButtons::make('condition')
|
||||||
|
->label('Server Status')
|
||||||
|
->formatStateUsing(fn (Server $server) => $server->condition)
|
||||||
|
->options(fn ($state) => collect(array_merge(ContainerStatus::cases(), ServerState::cases()))
|
||||||
|
->filter(fn ($condition) => $condition->value === $state)
|
||||||
|
->mapWithKeys(fn ($state) => [$state->value => str($state->value)->replace('_', ' ')->ucwords()])
|
||||||
|
)
|
||||||
|
->colors(collect(array_merge(ContainerStatus::cases(), ServerState::cases()))->mapWithKeys(
|
||||||
|
fn ($status) => [$status->value => $status->color()]
|
||||||
|
))
|
||||||
|
->icons(collect(array_merge(ContainerStatus::cases(), ServerState::cases()))->mapWithKeys(
|
||||||
|
fn ($status) => [$status->value => $status->icon()]
|
||||||
|
))
|
||||||
|
->columnSpan([
|
||||||
|
'default' => 2,
|
||||||
|
'sm' => 1,
|
||||||
|
'md' => 1,
|
||||||
|
'lg' => 1,
|
||||||
|
]),
|
||||||
|
|
||||||
Forms\Components\Textarea::make('description')
|
Forms\Components\Textarea::make('description')
|
||||||
->label('Description')
|
->label('Description')
|
||||||
->columnSpanFull(),
|
->columnSpanFull(),
|
||||||
@ -150,7 +120,7 @@ class EditServer extends EditRecord
|
|||||||
->hintAction(CopyAction::make())
|
->hintAction(CopyAction::make())
|
||||||
->columnSpan([
|
->columnSpan([
|
||||||
'default' => 2,
|
'default' => 2,
|
||||||
'sm' => 2,
|
'sm' => 1,
|
||||||
'md' => 2,
|
'md' => 2,
|
||||||
'lg' => 3,
|
'lg' => 3,
|
||||||
])
|
])
|
||||||
@ -160,7 +130,7 @@ class EditServer extends EditRecord
|
|||||||
->hintAction(CopyAction::make())
|
->hintAction(CopyAction::make())
|
||||||
->columnSpan([
|
->columnSpan([
|
||||||
'default' => 2,
|
'default' => 2,
|
||||||
'sm' => 2,
|
'sm' => 1,
|
||||||
'md' => 2,
|
'md' => 2,
|
||||||
'lg' => 3,
|
'lg' => 3,
|
||||||
])
|
])
|
||||||
@ -169,7 +139,7 @@ class EditServer extends EditRecord
|
|||||||
->label('External ID')
|
->label('External ID')
|
||||||
->columnSpan([
|
->columnSpan([
|
||||||
'default' => 2,
|
'default' => 2,
|
||||||
'sm' => 2,
|
'sm' => 1,
|
||||||
'md' => 2,
|
'md' => 2,
|
||||||
'lg' => 3,
|
'lg' => 3,
|
||||||
])
|
])
|
||||||
@ -179,7 +149,7 @@ class EditServer extends EditRecord
|
|||||||
->relationship('node', 'name')
|
->relationship('node', 'name')
|
||||||
->columnSpan([
|
->columnSpan([
|
||||||
'default' => 2,
|
'default' => 2,
|
||||||
'sm' => 2,
|
'sm' => 1,
|
||||||
'md' => 2,
|
'md' => 2,
|
||||||
'lg' => 3,
|
'lg' => 3,
|
||||||
])
|
])
|
||||||
|
@ -26,28 +26,11 @@ class ListServers extends ListRecords
|
|||||||
Group::make('egg.name')->getDescriptionFromRecordUsing(fn (Server $server): string => str($server->egg->description)->limit(150)),
|
Group::make('egg.name')->getDescriptionFromRecordUsing(fn (Server $server): string => str($server->egg->description)->limit(150)),
|
||||||
])
|
])
|
||||||
->columns([
|
->columns([
|
||||||
Tables\Columns\TextColumn::make('status')
|
Tables\Columns\TextColumn::make('condition')
|
||||||
->default('unknown')
|
->default('unknown')
|
||||||
->badge()
|
->badge()
|
||||||
->default(fn (Server $server) => $server->status ?? $server->retrieveStatus())
|
->icon(fn (Server $server) => $server->conditionIcon())
|
||||||
->icon(fn ($state) => match ($state) {
|
->color(fn (Server $server) => $server->conditionColor()),
|
||||||
'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',
|
|
||||||
}),
|
|
||||||
|
|
||||||
Tables\Columns\TextColumn::make('uuid')
|
Tables\Columns\TextColumn::make('uuid')
|
||||||
->hidden()
|
->hidden()
|
||||||
->label('UUID')
|
->label('UUID')
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\ContainerStatus;
|
||||||
use App\Enums\ServerState;
|
use App\Enums\ServerState;
|
||||||
use App\Exceptions\Http\Connection\DaemonConnectionException;
|
use App\Exceptions\Http\Connection\DaemonConnectionException;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
@ -69,7 +71,6 @@ use App\Exceptions\Http\Server\ServerStateConflictException;
|
|||||||
* @property \App\Models\User $user
|
* @property \App\Models\User $user
|
||||||
* @property \Illuminate\Database\Eloquent\Collection|\App\Models\EggVariable[] $variables
|
* @property \Illuminate\Database\Eloquent\Collection|\App\Models\EggVariable[] $variables
|
||||||
* @property int|null $variables_count
|
* @property int|null $variables_count
|
||||||
*
|
|
||||||
* @method static \Database\Factories\ServerFactory factory(...$parameters)
|
* @method static \Database\Factories\ServerFactory factory(...$parameters)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Server newModelQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|Server newModelQuery()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Server newQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|Server newQuery()
|
||||||
@ -100,7 +101,17 @@ use App\Exceptions\Http\Server\ServerStateConflictException;
|
|||||||
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUpdatedAt($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUpdatedAt($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUuid($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUuid($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Server whereuuid_short($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Server whereuuid_short($value)
|
||||||
*
|
* @property array|null $docker_labels
|
||||||
|
* @property string|null $ports
|
||||||
|
* @property-read mixed $condition
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\EggVariable> $eggVariables
|
||||||
|
* @property-read int|null $egg_variables_count
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ServerVariable> $serverVariables
|
||||||
|
* @property-read int|null $server_variables_count
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|Server whereDockerLabels($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|Server whereInstalledAt($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|Server wherePorts($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUuidShort($value)
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
*/
|
*/
|
||||||
class Server extends Model
|
class Server extends Model
|
||||||
@ -410,4 +421,33 @@ class Server extends Model
|
|||||||
|
|
||||||
return cache()->get("servers.$this->uuid.container.status") ?? 'missing';
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user