Skip to content

Commit

Permalink
Add new resource view to create server
Browse files Browse the repository at this point in the history
  • Loading branch information
notAreYouScared authored and lancepioch committed May 7, 2024
1 parent 8af2198 commit 73cdd0c
Showing 1 changed file with 92 additions and 37 deletions.
129 changes: 92 additions & 37 deletions app/Filament/Resources/ServerResource/Pages/CreateServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,83 +481,138 @@ public function form(Form $form): Form
]),

Forms\Components\Section::make('Resource Management')
// ->hiddenOn('create')
->collapsed()
->icon('tabler-server-cog')
->iconColor('primary')
->columns(2)
->columnSpan(([
->columns([
'default' => 2,
'sm' => 4,
'md' => 4,
'lg' => 6,
]))
'lg' => 4,
])
->schema([
Forms\Components\ToggleButtons::make('unlimited_mem')
->label('Memory')
->afterStateUpdated(fn (Forms\Set $set) => $set('memory', 0))
->inlineLabel()->inline()
->live()
->formatStateUsing(fn (Forms\Get $get) => $get('memory') <= 0)
->options([
true => 'Unlimited',
false => 'Limited',
])
->colors([
true => 'primary',
false => 'warning',
])
->columnSpan(2),

Forms\Components\TextInput::make('memory')
->default(0)
->label('Allocated Memory')
->disabled(fn (Forms\Get $get) => $get('unlimited_mem'))
->label('Memory Limit')
->suffix('MB')
->required()
->inlineLabel()
->columnSpan(2)
->numeric(),

Forms\Components\TextInput::make('swap')
->default(0)
->label('Swap Memory')
->suffix('MB')
->helperText('0 disables swap and -1 allows unlimited swap')
->minValue(-1)
->required()
->numeric(),
Forms\Components\ToggleButtons::make('unlimited_disk')
->label('Disk Space')
->inlineLabel()->inline()
->live()
->afterStateUpdated(fn (Forms\Set $set) => $set('disk', 0))
->formatStateUsing(fn (Forms\Get $get) => $get('disk') <= 0)
->options([
true => 'Unlimited',
false => 'Limited',
])
->colors([
true => 'primary',
false => 'warning',
])
->columnSpan(2),

Forms\Components\TextInput::make('disk')
->default(0)
->disabled(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Space Limit')
->suffix('MB')
->required()
->inlineLabel()
->columnSpan(2)
->numeric(),

Forms\Components\ToggleButtons::make('unlimited_cpu')
->label('CPU')
->inlineLabel()->inline()
->afterStateUpdated(fn (Forms\Set $set) => $set('cpu', 0))
->live()
->formatStateUsing(fn (Forms\Get $get) => $get('cpu') <= 0)
->options([
true => 'Unlimited',
false => 'Limited',
])
->colors([
true => 'primary',
false => 'warning',
])
->columnSpan(2),

Forms\Components\TextInput::make('cpu')
->default(0)
->disabled(fn (Forms\Get $get) => $get('unlimited_cpu'))
->label('CPU Limit')
->suffix('%')
->required()
->inlineLabel()
->columnSpan(2)
->numeric(),

Forms\Components\TextInput::make('threads')
->hint('Advanced')
->hintColor('danger')
->helperText('Examples: 0, 0-1,3, or 0,1,3,4')
->label('CPU Pinning')
->suffixIcon('tabler-cpu')
->maxLength(191),

Forms\Components\TextInput::make('io')
Forms\Components\Hidden::make('io')
->helperText('The IO performance relative to other running containers')
->label('Block IO Proportion')
->required(),
// ->numeric()
// ->minValue(0)
// ->maxValue(1000)
// ->step(10)

Forms\Components\ToggleButtons::make('swap_support')
->label('Enable Swap Memory')
->columnSpan(2)
->inlineLabel()->inline()
->formatStateUsing(fn (Forms\Get $get) => $get('swap') <= 0)
->options([
'unlimited' => 'Unlimited',
'limited' => 'Limited',
'disabled' => 'Disabled',
])
->colors([
'unlimited' => 'primary',
'limited' => 'warning',
'disabled' => 'danger',
]),

Forms\Components\TextInput::make('swap')
->disabled(fn (Forms\Get $get) => $get('swap_support'))
->label('Swap Memory')
->suffix('MB')
->minValue(-1)
->columnSpan(2)
->inlineLabel()
->required()
->minValue(0)
->maxValue(1000)
->step(10)
->default(0)
->numeric(),

Forms\Components\ToggleButtons::make('oom_disabled')
->label('OOM Killer')
->inline()
->default(false)
->columnSpan(2)
->options([
false => 'Disabled',
true => 'Enabled',
])
->colors([
false => 'success',
true => 'danger',
])
->icons([
false => 'tabler-sword-off',
true => 'tabler-sword',
])
->required(),
]),
]),
]);
}
Expand Down

0 comments on commit 73cdd0c

Please sign in to comment.