Update these

This commit is contained in:
notCharles 2024-07-02 19:36:53 -04:00
parent ec0fa3c913
commit bebc410eda
3 changed files with 104 additions and 73 deletions

View File

@ -151,8 +151,8 @@ class CreateServer extends CreateRecord
->label('Notes'), ->label('Notes'),
]), ]),
Wizard\Step::make('Egg Configuration') Wizard\Step::make('Egg')
->label('Egg Configuration') ->label('Egg')
->icon('tabler-egg') ->icon('tabler-egg')
->completedIcon('tabler-check') ->completedIcon('tabler-check')
->columns([ ->columns([
@ -214,54 +214,6 @@ class CreateServer extends CreateRecord
->inline() ->inline()
->required(), ->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.
<br />
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') Forms\Components\Textarea::make('startup')
->hidden(fn () => !$this->egg) ->hidden(fn () => !$this->egg)
->hintIcon('tabler-code') ->hintIcon('tabler-code')
@ -361,8 +313,83 @@ class CreateServer extends CreateRecord
]), ]),
]), ]),
Wizard\Step::make('Environment Configuration') Wizard\Step::make('Allocation')
->label('Environment Configuration') ->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') ->icon('tabler-brand-docker')
->completedIcon('tabler-check') ->completedIcon('tabler-check')
->schema([ ->schema([

View File

@ -65,6 +65,25 @@ class EditServer extends EditRecord
Tabs\Tab::make('Information') Tabs\Tab::make('Information')
->icon('tabler-info-circle') ->icon('tabler-info-circle')
->schema([ ->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') Forms\Components\TextInput::make('name')
->prefixIcon('tabler-server') ->prefixIcon('tabler-server')
->label('Display Name') ->label('Display Name')
@ -101,26 +120,6 @@ class EditServer extends EditRecord
->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('Notes') ->label('Notes')
->columnSpanFull(), ->columnSpanFull(),

View File

@ -327,6 +327,8 @@ class Node extends Model
public function ipAddresses(): array public function ipAddresses(): array
{ {
cache()->forget("nodes.$this->id.ips"); // TODO REMOVE BEFORE COMMITTING
return cache()->remember("nodes.$this->id.ips", now()->addHour(), function () { return cache()->remember("nodes.$this->id.ips", now()->addHour(), function () {
$ips = collect(); $ips = collect();
if (is_ip($this->fqdn)) { if (is_ip($this->fqdn)) {
@ -342,7 +344,10 @@ class Node extends Model
// pass // 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();
}); });
} }
} }