Files
panel-pelican-dev/app/Filament/Resources/NodeResource/Pages/EditNode.php

220 lines
11 KiB
PHP
Raw Normal View History

2024-03-24 01:48:03 -04:00
<?php
namespace App\Filament\Resources\NodeResource\Pages;
use App\Filament\Resources\NodeResource;
2024-05-11 15:25:37 -04:00
use App\Filament\Resources\NodeResource\Widgets\NodeMemoryChart;
use App\Filament\Resources\NodeResource\Widgets\NodeStorageChart;
2024-03-31 01:39:24 -04:00
use App\Models\Node;
2024-03-24 01:48:03 -04:00
use Filament\Actions;
2024-03-24 14:42:36 -04:00
use Filament\Forms;
2024-04-04 20:16:14 -04:00
use Filament\Forms\Components\Tabs;
2024-03-24 01:48:03 -04:00
use Filament\Resources\Pages\EditRecord;
2024-03-31 01:39:24 -04:00
use Illuminate\Support\HtmlString;
use Webbingbrasil\FilamentCopyActions\Forms\Actions\CopyAction;
2024-03-24 01:48:03 -04:00
class EditNode extends EditRecord
{
protected static string $resource = NodeResource::class;
2024-03-24 14:42:36 -04:00
public function form(Forms\Form $form): Forms\Form
{
2024-04-04 20:16:14 -04:00
return $form->schema([
Tabs::make('Tabs')
2024-04-16 18:47:12 -04:00
->columns([
'default' => 2,
'sm' => 3,
'md' => 3,
'lg' => 4,
])
2024-04-04 20:16:14 -04:00
->persistTabInQueryString()
->columnSpanFull()
->tabs([
Tabs\Tab::make('Basic Settings')
->icon('tabler-server')
2024-03-24 14:42:36 -04:00
->schema((new CreateNode())->form($form)->getComponents()),
2024-05-12 14:11:17 -04:00
Tabs\Tab::make('Advanced Settings')
->icon('tabler-server-cog')
->schema([
Forms\Components\TextInput::make('id')
->label('Node ID')
->disabled(),
Forms\Components\TextInput::make('uuid')
->label('Node UUID')
->hintAction(CopyAction::make())
->columnSpan(2)
->disabled(),
2024-05-12 14:30:35 -04:00
Forms\Components\TagsInput::make('tags')
->label('Tags')
->disabled()
->placeholder('Not Implemented')
2024-05-12 14:11:17 -04:00
->hintIcon('tabler-question-mark')
2024-05-12 14:30:35 -04:00
->hintIconTooltip('Not Implemented')
->columnSpan(1),
2024-05-12 14:11:17 -04:00
Forms\Components\ToggleButtons::make('public')
2024-05-12 14:30:35 -04:00
->label('Automatic Allocation')->inline()
2024-05-12 14:11:17 -04:00
->columnSpan(1)
->options([
true => 'Yes',
false => 'No',
])
->colors([
true => 'success',
false => 'danger',
]),
Forms\Components\ToggleButtons::make('maintenance_mode')
->label('Maintenance Mode')->inline()
->columnSpan(1)
->hinticon('tabler-question-mark')
->hintIconTooltip("If the node is marked 'Under Maintenance' users won't be able to access servers that are on this node.")
->options([
true => 'Enable',
false => 'Disable',
])
->colors([
true => 'danger',
false => 'success',
]),
2024-05-12 14:30:35 -04:00
Forms\Components\TextInput::make('upload_size')
->label('Upload Limit')
->hintIcon('tabler-question-mark')
->hintIconTooltip('Enter the maximum size of files that can be uploaded through the web-based file manager.')
->columnStart(4)->columnSpan(1)
->numeric()->required()
->minValue(1)
->maxValue(1024)
->suffix('MiB'),
2024-05-12 14:11:17 -04:00
Forms\Components\Grid::make()
->columns(6)
->columnSpanFull()
->schema([
Forms\Components\ToggleButtons::make('unlimited_mem')
->label('Memory')->inlineLabel()->inline()
->afterStateUpdated(fn (Forms\Set $set) => $set('memory', 0))
2024-05-14 10:53:28 +02:00
->afterStateUpdated(fn (Forms\Set $set) => $set('memory_overallocate', 0))
2024-05-12 14:11:17 -04:00
->formatStateUsing(fn (Forms\Get $get) => $get('memory') == 0)
->live()
->options([
true => 'Unlimited',
false => 'Limited',
])
->colors([
true => 'primary',
false => 'warning',
])
->columnSpan(2),
Forms\Components\TextInput::make('memory')
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->label('Memory Limit')->inlineLabel()
->suffix('MiB')
->required()
->columnSpan(2)
2024-05-14 10:53:04 +02:00
->numeric()
->minValue(0),
2024-05-12 14:11:17 -04:00
Forms\Components\TextInput::make('memory_overallocate')
->dehydratedWhenHidden()
->label('Overallocate')->inlineLabel()
->required()
->hidden(fn (Forms\Get $get) => $get('unlimited_mem'))
->hintIcon('tabler-question-mark')
->hintIconTooltip('The % allowable to go over the set limit.')
->columnSpan(2)
->numeric()
2024-05-14 10:53:04 +02:00
->minValue(-1)
2024-05-12 14:11:17 -04:00
->maxValue(100)
->suffix('%'),
]),
Forms\Components\Grid::make()
->columns(6)
->columnSpanFull()
->schema([
Forms\Components\ToggleButtons::make('unlimited_disk')
->label('Disk')->inlineLabel()->inline()
->live()
->afterStateUpdated(fn (Forms\Set $set) => $set('disk', 0))
2024-05-14 10:53:28 +02:00
->afterStateUpdated(fn (Forms\Set $set) => $set('disk_overallocate', 0))
2024-05-12 14:11:17 -04:00
->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')
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Disk Limit')->inlineLabel()
2024-05-14 10:41:06 +02:00
->suffix('MiB')
2024-05-12 14:11:17 -04:00
->required()
->columnSpan(2)
2024-05-14 10:53:04 +02:00
->numeric()
->minValue(0),
2024-05-12 14:11:17 -04:00
Forms\Components\TextInput::make('disk_overallocate')
->dehydratedWhenHidden()
->hidden(fn (Forms\Get $get) => $get('unlimited_disk'))
->label('Overallocate')->inlineLabel()
->hintIcon('tabler-question-mark')
->hintIconTooltip('The % allowable to go over the set limit.')
->columnSpan(2)
->required()
->numeric()
2024-05-14 10:53:04 +02:00
->minValue(-1)
2024-05-12 14:11:17 -04:00
->maxValue(100)
->suffix('%'),
]),
]),
Tabs\Tab::make('Configuration File')
2024-04-04 20:16:14 -04:00
->icon('tabler-code')
2024-03-24 14:42:36 -04:00
->schema([
2024-03-31 01:39:24 -04:00
Forms\Components\Placeholder::make('instructions')
->columnSpanFull()
->content(new HtmlString('
2024-04-11 00:45:33 -04:00
Save this file to your <span title="usually /etc/pelican/">daemon\'s root directory</span>, named <code>config.yml</code>
2024-03-31 01:39:24 -04:00
')),
Forms\Components\Textarea::make('config')
2024-04-11 00:45:33 -04:00
->label('/etc/pelican/config.yml')
2024-03-31 01:39:24 -04:00
->disabled()
->rows(19)
->hintAction(CopyAction::make())
->columnSpanFull(),
2024-03-24 14:42:36 -04:00
]),
2024-04-13 16:30:20 +03:00
]),
2024-04-04 20:16:14 -04:00
]);
2024-03-24 14:42:36 -04:00
}
2024-03-31 01:39:24 -04:00
protected function mutateFormDataBeforeFill(array $data): array
{
$node = Node::findOrFail($data['id']);
$data['config'] = $node->getYamlConfiguration();
return $data;
}
2024-05-13 19:58:01 -04:00
protected function getFormActions(): array
2024-03-24 14:42:36 -04:00
{
2024-05-13 19:58:01 -04:00
return [];
2024-03-24 14:42:36 -04:00
}
2024-03-24 01:48:03 -04:00
protected function getHeaderActions(): array
{
return [
2024-05-10 17:57:42 -04:00
Actions\DeleteAction::make()
->disabled(fn (Node $node) => $node->servers()->count() > 0)
->label(fn (Node $node) => $node->servers()->count() > 0 ? 'Node Has Servers' : 'Delete'),
2024-05-13 19:58:01 -04:00
$this->getSaveFormAction()->formId('form'),
2024-03-24 01:48:03 -04:00
];
}
2024-05-11 15:25:37 -04:00
protected function getFooterWidgets(): array
{
return [
NodeStorageChart::class,
NodeMemoryChart::class,
];
}
2024-03-24 01:48:03 -04:00
}