Add some new options for ports

This commit is contained in:
Lance Pioch 2024-06-02 16:58:32 -04:00
parent 2e7c534a3b
commit bbe09ced1d

View File

@ -129,67 +129,17 @@ class CreateServer extends CreateRecord
->required() ->required()
->columnSpanFull(), ->columnSpanFull(),
Forms\Components\Select::make('allocation_id') Forms\Components\TagsInput::make('ports')
->preload() ->columnSpan(3)
->live() ->placeholder('Example: 25565, 8080, 1337-1340')
->prefixIcon('tabler-network') ->reorderable()
->label('Primary Allocation') ->splitKeys(['Tab', ' ', ','])
->columnSpan(2)
->disabled(fn (Forms\Get $get) => $get('node_id') === null)
->searchable(['ip', 'port', 'ip_alias'])
->afterStateUpdated(function (Forms\Set $set) {
$set('allocation_additional', null);
$set('allocation_additional.needstobeastringhere.extra_allocations', null);
})
->getOptionLabelFromRecordUsing(
fn (Allocation $allocation) => "$allocation->ip:$allocation->port" .
($allocation->ip_alias ? " ($allocation->ip_alias)" : '')
)
->placeholder(function (Forms\Get $get) {
$node = Node::find($get('node_id'));
if ($node?->allocations) {
return 'Select an Allocation';
}
return 'Create a New Allocation';
})
->relationship(
'allocation',
'ip',
fn (Builder $query, Forms\Get $get) => $query
->where('node_id', $get('node_id'))
->whereNull('server_id'),
)
->createOptionForm(fn (Forms\Get $get) => [
Forms\Components\TextInput::make('allocation_ip')
->datalist(Node::find($get('node_id'))?->ipAddresses() ?? [])
->label('IP Address')
->inlineLabel()
->ipv4()
->helperText("Usually your machine's public IP unless you are port forwarding.")
// ->selectablePlaceholder(false)
->required(),
Forms\Components\TextInput::make('allocation_alias')
->label('Alias')
->inlineLabel()
->default(null)
->datalist([
$get('name'),
$this->egg?->name,
])
->helperText('Optional display name to help you remember what these are.')
->required(false),
Forms\Components\TagsInput::make('allocation_ports')
->placeholder('Examples: 27015, 27017-27019')
->helperText(new HtmlString(' ->helperText(new HtmlString('
These are the ports that users can connect to this Server through. These are the ports that users can connect to this Server through.
<br /> <br />
You would have to port forward these on your home network. You would typically port forward these on your home network.
')) '))
->label('Ports') ->label('Ports')
->inlineLabel()
->live()
->afterStateUpdated(function ($state, Forms\Set $set) { ->afterStateUpdated(function ($state, Forms\Set $set) {
$ports = collect(); $ports = collect();
$update = false; $update = false;
@ -238,48 +188,38 @@ class CreateServer extends CreateRecord
$set('allocation_ports', $ports->all()); $set('allocation_ports', $ports->all());
} }
}) })
->splitKeys(['Tab', ' ', ',']) ->live(),
->required(),
])
->createOptionUsing(function (array $data, Forms\Get $get): int {
return collect(
resolve(AssignmentService::class)->handle(Node::find($get('node_id')), $data)
)->first();
})
->required(),
Forms\Components\Repeater::make('allocation_additional') Forms\Components\Select::make('primary_port')
->label('Additional Allocations')
->columnSpan(2)
->addActionLabel('Add Allocation')
->disabled(fn (Forms\Get $get) => $get('allocation_id') === null)
// ->addable() TODO disable when all allocations are taken
// ->addable() TODO disable until first additional allocation is selected
->simple(
Forms\Components\Select::make('extra_allocations')
->live() ->live()
->preload() ->helperText(fn (Forms\Get $get) => match (true) {
->disableOptionsWhenSelectedInSiblingRepeaterItems() !str_contains($get('startup'), '{{SERVER_PORT}}') => 'This is disabled because there is no primary server port in the startup command.',
->prefixIcon('tabler-network') empty($get('ports')) => 'This is disabled because you haven\'t entered any ports yet.',
->label('Additional Allocations') true => 'This port will take the place of {{SERVER_PORT}} in your startup command.',
->columnSpan(2) })
->disabled(fn (Forms\Get $get) => $get('../../node_id') === null) ->columnSpan(3)
->searchable(['ip', 'port', 'ip_alias']) ->selectablePlaceholder(false)
->getOptionLabelFromRecordUsing( ->disabled(fn (Forms\Get $get) => empty($get('ports')) || !str_contains($get('startup'), '{{SERVER_PORT}}'))
fn (Allocation $allocation) => "$allocation->ip:$allocation->port" . ->options(fn (Forms\Get $get) => $get('ports'))
($allocation->ip_alias ? " ($allocation->ip_alias)" : '') ->label('Primary Port'),
)
->placeholder('Select additional Allocations') Forms\Components\KeyValue::make('pts')
->disableOptionsWhenSelectedInSiblingRepeaterItems() // ->deletable(fn ($state) => empty($state) || dd('SERVER_PORT', array_keys($state), $state) || !in_array('SERVER_PORT', array_keys($state)))
->relationship( // ->addable(false)
'allocations', // ->editableKeys(false)
'ip', ->columnSpan(3)
fn (Builder $query, Forms\Get $get, Forms\Components\Select $component, $state) => $query ->keyLabel('Name')
->where('node_id', $get('../../node_id')) ->valueLabel('Port')
->whereNot('id', $get('../../allocation_id')) ->label('Ports')
->whereNull('server_id'), ->live(),
),
), Forms\Components\Placeholder::make('instructions')
->label(new HtmlString('Port Instructions:<br><br>
These are the ports that users can connect to this Server through.
<br>
You would typically port forward these on your home network.
'))
->columnSpan(3),
Forms\Components\Textarea::make('startup') Forms\Components\Textarea::make('startup')
->hintIcon('tabler-code') ->hintIcon('tabler-code')