From bebc410eda8085b543daa735704c916cd76e1068 Mon Sep 17 00:00:00 2001 From: notCharles Date: Tue, 2 Jul 2024 19:36:53 -0400 Subject: [PATCH] Update these --- .../ServerResource/Pages/CreateServer.php | 131 +++++++++++------- .../ServerResource/Pages/EditServer.php | 39 +++--- app/Models/Node.php | 7 +- 3 files changed, 104 insertions(+), 73 deletions(-) diff --git a/app/Filament/Resources/ServerResource/Pages/CreateServer.php b/app/Filament/Resources/ServerResource/Pages/CreateServer.php index 8b759bbda..353372009 100644 --- a/app/Filament/Resources/ServerResource/Pages/CreateServer.php +++ b/app/Filament/Resources/ServerResource/Pages/CreateServer.php @@ -151,8 +151,8 @@ class CreateServer extends CreateRecord ->label('Notes'), ]), - Wizard\Step::make('Egg Configuration') - ->label('Egg Configuration') + Wizard\Step::make('Egg') + ->label('Egg') ->icon('tabler-egg') ->completedIcon('tabler-check') ->columns([ @@ -214,54 +214,6 @@ class CreateServer extends CreateRecord ->inline() ->required(), - Forms\Components\TagsInput::make('ports') - ->columnSpan(2) - ->placeholder('Example: 25565, 8080, 1337-1340') - ->splitKeys(['Tab', ' ', ',']) - ->hidden(fn () => !$this->egg) - ->helperText(new HtmlString(' - These are the ports that users can connect to this Server through. -
- You would typically port forward these on your home network. - ')) - ->label('Ports') - ->afterStateUpdated(self::ports(...)) - ->live(), - - Forms\Components\Repeater::make('assignments') - ->columnSpan(2) - ->defaultItems(fn () => count($this->eggDefaultPorts)) - ->label('Port Assignments') - ->helperText(function (Forms\Get $get) { - if (empty($this->eggDefaultPorts)) { - return "This egg doesn't have any ports defined."; - } - - if (empty($get('ports'))) { - return 'You must add ports to assign them!'; - } - - return ''; - }) - ->live() - ->addable(false) - ->deletable(false) - ->reorderable(false) - ->hidden(fn () => !$this->egg) - ->simple( - Forms\Components\Select::make('port') - ->live() - ->disabled(fn (Forms\Get $get) => empty($get('../../ports')) || empty($get('../../assignments'))) - ->prefix(function (Forms\Components\Component $component) { - $key = str($component->getStatePath())->beforeLast('.')->afterLast('.')->toString(); - - return $key; - }) - ->disableOptionsWhenSelectedInSiblingRepeaterItems() - ->options(fn (Forms\Get $get) => $this->ports) - ->required(), - ), - Forms\Components\Textarea::make('startup') ->hidden(fn () => !$this->egg) ->hintIcon('tabler-code') @@ -361,8 +313,83 @@ class CreateServer extends CreateRecord ]), ]), - Wizard\Step::make('Environment Configuration') - ->label('Environment Configuration') + Wizard\Step::make('Allocation') + ->label('Allocation') + ->icon('tabler-transfer-in') + ->completedIcon('tabler-check') + ->columns(4) + ->schema([ + Forms\Components\TagsInput::make('ports') + ->columnSpanFull() + ->hintIcon('tabler-question-mark') + ->hintIconTooltip('Ports are limited from 1025 to 65535') + ->placeholder('Example: 25565, 8080, 1337-1340') + ->splitKeys(['Tab', ' ', ',']) + ->helperText(new HtmlString(' + These are the ports that users can connect to this Server through. + You would typically port forward these on your home network. + ')) + ->label('Ports') + ->afterStateUpdated(self::ports(...)) + ->live(), + + Forms\Components\Repeater::make('ip') + ->columnSpan(2) + ->defaultItems(5) + ->label('IP Assignments') + ->live() + ->addable(false) + ->deletable(false) + ->reorderable(false) + ->hintIcon('tabler-question-mark') + ->hintIconTooltip('These are the IPs available on the selected Node.') + ->simple( + Forms\Components\Select::make('port') + ->live() + ->placeholder('Select an IP') +// ->afterStateUpdated() + ->options(fn () => $this->node?->ipAddresses()) + ->required(), + ), + + Forms\Components\Repeater::make('assignments') + ->columnSpan(2) + ->defaultItems(fn () => count($this->eggDefaultPorts)) + ->label('Port Assignments') + ->helperText(function (Forms\Get $get) { + if (empty($this->eggDefaultPorts)) { + return "This egg doesn't have any ports defined."; + } + + if (empty($get('ports'))) { + return 'You must add ports to assign them!'; + } + + return ''; + }) + ->live() + ->addable(false) + ->deletable(false) + ->reorderable(false) + ->simple( + Forms\Components\Select::make('port') + ->live() + ->placeholder('Select a Port') + ->disabled(fn (Forms\Get $get) => empty($get('../../ports')) || empty($get('../../assignments'))) + ->prefix(function (Forms\Components\Component $component) { + $key = str($component->getStatePath())->beforeLast('.')->afterLast('.')->toString(); + + return $key; + }) + ->disableOptionsWhenSelectedInSiblingRepeaterItems() + ->options(fn (Forms\Get $get) => $this->ports) + ->required(), + ), + + ]), + + Wizard\Step::make('Environment') + ->label('Environment') ->icon('tabler-brand-docker') ->completedIcon('tabler-check') ->schema([ diff --git a/app/Filament/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Resources/ServerResource/Pages/EditServer.php index 128900009..e32455b61 100644 --- a/app/Filament/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Resources/ServerResource/Pages/EditServer.php @@ -65,6 +65,25 @@ class EditServer extends EditRecord Tabs\Tab::make('Information') ->icon('tabler-info-circle') ->schema([ + Forms\Components\ToggleButtons::make('condition') + ->label('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\TextInput::make('name') ->prefixIcon('tabler-server') ->label('Display Name') @@ -101,26 +120,6 @@ class EditServer extends EditRecord ->preload() ->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') ->label('Notes') ->columnSpanFull(), diff --git a/app/Models/Node.php b/app/Models/Node.php index 83285ebb5..2fa08d06c 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -327,6 +327,8 @@ class Node extends Model public function ipAddresses(): array { + cache()->forget("nodes.$this->id.ips"); // TODO REMOVE BEFORE COMMITTING + return cache()->remember("nodes.$this->id.ips", now()->addHour(), function () { $ips = collect(); if (is_ip($this->fqdn)) { @@ -342,7 +344,10 @@ class Node extends Model // pass } - return $ips->all(); + return $ips + ->filter(fn ($ip) => preg_match('/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/', $ip)) + ->unique() + ->all(); }); } }