Fix editing server resources

This commit is contained in:
notCharles 2024-05-07 21:44:44 -04:00
parent 94f583fef0
commit fe3bf88ea4

View File

@ -317,13 +317,17 @@ class EditServer extends EditRecord
'md' => 4, 'md' => 4,
'lg' => 4, 'lg' => 4,
]) ])
->columnSpanFull()
->schema([
Forms\Components\Grid::make()
->columns(4)
->columnSpanFull()
->schema([ ->schema([
Forms\Components\ToggleButtons::make('unlimited_mem') Forms\Components\ToggleButtons::make('unlimited_mem')
->label('Memory') ->label('Memory')->inlineLabel()->inline()
->afterStateUpdated(fn (Forms\Set $set) => $set('memory', 0)) ->afterStateUpdated(fn (Forms\Set $set) => $set('memory', 0))
->inlineLabel()->inline() ->formatStateUsing(fn (Forms\Get $get) => $get('memory') == 0)
->live() ->live()
->formatStateUsing(fn (Forms\Get $get) => $get('memory') <= 0)
->options([ ->options([
true => 'Unlimited', true => 'Unlimited',
false => 'Limited', false => 'Limited',
@ -335,20 +339,24 @@ class EditServer extends EditRecord
->columnSpan(2), ->columnSpan(2),
Forms\Components\TextInput::make('memory') Forms\Components\TextInput::make('memory')
->disabled(fn (Forms\Get $get) => $get('unlimited_mem')) ->dehydratedWhenHidden()
->label('Memory Limit') ->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->label('Memory Limit')->inlineLabel()
->suffix('MB') ->suffix('MB')
->required() ->required()
->inlineLabel()
->columnSpan(2) ->columnSpan(2)
->numeric(), ->numeric(),
]),
Forms\Components\Grid::make()
->columns(4)
->columnSpanFull()
->schema([
Forms\Components\ToggleButtons::make('unlimited_disk') Forms\Components\ToggleButtons::make('unlimited_disk')
->label('Disk Space') ->label('Disk Space')->inlineLabel()->inline()
->inlineLabel()->inline()
->live() ->live()
->afterStateUpdated(fn (Forms\Set $set) => $set('disk', 0)) ->afterStateUpdated(fn (Forms\Set $set) => $set('disk', 0))
->formatStateUsing(fn (Forms\Get $get) => $get('disk') <= 0) ->formatStateUsing(fn (Forms\Get $get) => $get('disk') == 0)
->options([ ->options([
true => 'Unlimited', true => 'Unlimited',
false => 'Limited', false => 'Limited',
@ -360,20 +368,24 @@ class EditServer extends EditRecord
->columnSpan(2), ->columnSpan(2),
Forms\Components\TextInput::make('disk') Forms\Components\TextInput::make('disk')
->disabled(fn (Forms\Get $get) => $get('unlimited_disk')) ->dehydratedWhenHidden()
->label('Disk Space Limit') ->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Space Limit')->inlineLabel()
->suffix('MB') ->suffix('MB')
->required() ->required()
->inlineLabel()
->columnSpan(2) ->columnSpan(2)
->numeric(), ->numeric(),
]),
Forms\Components\Grid::make()
->columns(4)
->columnSpanFull()
->schema([
Forms\Components\ToggleButtons::make('unlimited_cpu') Forms\Components\ToggleButtons::make('unlimited_cpu')
->label('CPU') ->label('CPU')->inlineLabel()->inline()
->inlineLabel()->inline()
->afterStateUpdated(fn (Forms\Set $set) => $set('cpu', 0)) ->afterStateUpdated(fn (Forms\Set $set) => $set('cpu', 0))
->formatStateUsing(fn (Forms\Get $get) => $get('cpu') == 0)
->live() ->live()
->formatStateUsing(fn (Forms\Get $get) => $get('cpu') <= 0)
->options([ ->options([
true => 'Unlimited', true => 'Unlimited',
false => 'Limited', false => 'Limited',
@ -385,28 +397,39 @@ class EditServer extends EditRecord
->columnSpan(2), ->columnSpan(2),
Forms\Components\TextInput::make('cpu') Forms\Components\TextInput::make('cpu')
->disabled(fn (Forms\Get $get) => $get('unlimited_cpu')) ->dehydratedWhenHidden()
->label('CPU Limit') ->hidden(fn (Forms\Get $get) => $get('unlimited_cpu'))
->label('CPU Limit')->inlineLabel()
->suffix('%') ->suffix('%')
->required() ->required()
->inlineLabel()
->columnSpan(2) ->columnSpan(2)
->numeric(), ->numeric(),
]),
Forms\Components\Hidden::make('io') Forms\Components\Grid::make()
->helperText('The IO performance relative to other running containers') ->columns(4)
->label('Block IO Proportion') ->columnSpanFull()
->required(), ->schema([
// ->numeric()
// ->minValue(0)
// ->maxValue(1000)
// ->step(10)
Forms\Components\ToggleButtons::make('swap_support') Forms\Components\ToggleButtons::make('swap_support')
->label('Enable Swap Memory') ->live()
->label('Enable Swap Memory')->inlineLabel()->inline()
->columnSpan(2) ->columnSpan(2)
->inlineLabel()->inline() ->afterStateUpdated(function ($state, Forms\Set $set) {
->formatStateUsing(fn (Forms\Get $get) => $get('swap') <= 0) $value = match ($state) {
'unlimited' => -1,
'disabled' => 0,
'limited' => 128,
};
$set('swap', $value);
})
->formatStateUsing(function (Forms\Get $get) {
return match (true) {
$get('swap') > 0 => 'limited',
$get('swap') == 0 => 'disabled',
$get('swap') < 0 => 'unlimited',
};
})
->options([ ->options([
'unlimited' => 'Unlimited', 'unlimited' => 'Unlimited',
'limited' => 'Limited', 'limited' => 'Limited',
@ -419,18 +442,25 @@ class EditServer extends EditRecord
]), ]),
Forms\Components\TextInput::make('swap') Forms\Components\TextInput::make('swap')
->disabled(fn (Forms\Get $get) => $get('swap_support')) ->dehydratedWhenHidden()
->label('Swap Memory') ->hidden(fn (Forms\Get $get) => match ($get('swap_support')) {
'disabled', 'unlimited', true => true,
'limited', false => false,
})
->label('Swap Memory')->inlineLabel()
->suffix('MB') ->suffix('MB')
->minValue(-1) ->minValue(-1)
->columnSpan(2) ->columnSpan(2)
->inlineLabel()
->required() ->required()
->numeric(), ->integer(),
]),
Forms\Components\Hidden::make('io')
->helperText('The IO performance relative to other running containers')
->label('Block IO Proportion'),
Forms\Components\ToggleButtons::make('oom_disabled') Forms\Components\ToggleButtons::make('oom_disabled')
->label('OOM Killer') ->label('OOM Killer')->inlineLabel()->inline()
->inline()
->columnSpan(2) ->columnSpan(2)
->options([ ->options([
false => 'Disabled', false => 'Disabled',
@ -453,6 +483,7 @@ class EditServer extends EditRecord
->requiresConfirmation(), ->requiresConfirmation(),
Actions\DeleteAction::make('Force Delete') Actions\DeleteAction::make('Force Delete')
->label('Force Delete') ->label('Force Delete')
->hidden()
->successRedirectUrl(route('filament.admin.resources.servers.index')) ->successRedirectUrl(route('filament.admin.resources.servers.index'))
->color('danger') ->color('danger')
->after(fn (Server $server) => resolve(ServerDeletionService::class)->withForce()->handle($server)) ->after(fn (Server $server) => resolve(ServerDeletionService::class)->withForce()->handle($server))