mirror of
https://github.com/pelican-dev/panel.git
synced 2025-12-08 16:30:16 +01:00
Fix Egg select_startup default & update state (#1933)
This commit is contained in:
parent
cdccca8fa2
commit
78ab098d02
@ -413,6 +413,7 @@ class CreateServer extends CreateRecord
|
||||
Select::make('select_startup')
|
||||
->label(trans('admin/server.startup_cmd'))
|
||||
->hidden(fn (Get $get) => $get('egg_id') === null)
|
||||
->required()
|
||||
->live()
|
||||
->afterStateUpdated(fn (Set $set, $state) => $set('startup', $state))
|
||||
->options(function ($state, Get $get, Set $set) {
|
||||
@ -426,7 +427,7 @@ class CreateServer extends CreateRecord
|
||||
$set('select_startup', $currentStartup);
|
||||
}
|
||||
|
||||
return array_flip($startups) + ['' => 'Custom Startup'];
|
||||
return array_flip($startups) + ['custom' => 'Custom Startup'];
|
||||
})
|
||||
->selectablePlaceholder(false)
|
||||
->columnSpanFull(),
|
||||
@ -444,7 +445,7 @@ class CreateServer extends CreateRecord
|
||||
if (in_array($state, $startups)) {
|
||||
$set('select_startup', $state);
|
||||
} else {
|
||||
$set('select_startup', '');
|
||||
$set('select_startup', 'custom');
|
||||
}
|
||||
})
|
||||
->placeholder(trans('admin/server.startup_placeholder'))
|
||||
|
||||
@ -797,6 +797,7 @@ class EditServer extends EditRecord
|
||||
|
||||
Select::make('select_startup')
|
||||
->label(trans('admin/server.startup_cmd'))
|
||||
->required()
|
||||
->live()
|
||||
->afterStateUpdated(function (Set $set, $state) {
|
||||
$set('startup', $state);
|
||||
@ -813,7 +814,22 @@ class EditServer extends EditRecord
|
||||
$set('select_startup', $currentStartup);
|
||||
}
|
||||
|
||||
return array_flip($startups) + ['' => 'Custom Startup'];
|
||||
return array_flip($startups) + ['custom' => 'Custom Startup'];
|
||||
})
|
||||
->formatStateUsing(function (Server $server) {
|
||||
$startups = $server->egg->startup_commands;
|
||||
|
||||
$currentStartup = $server->startup;
|
||||
$matchingStartup = collect($startups)
|
||||
->filter(fn ($value, $key) => $value === $currentStartup)
|
||||
->keys()
|
||||
->first();
|
||||
|
||||
if (!$matchingStartup) {
|
||||
return 'custom';
|
||||
}
|
||||
|
||||
return $matchingStartup;
|
||||
})
|
||||
->selectablePlaceholder(false)
|
||||
->columnSpanFull()
|
||||
@ -831,7 +847,7 @@ class EditServer extends EditRecord
|
||||
if (in_array($state, $startups)) {
|
||||
$set('select_startup', $state);
|
||||
} else {
|
||||
$set('select_startup', '');
|
||||
$set('select_startup', 'custom');
|
||||
}
|
||||
})
|
||||
->placeholder(trans('admin/server.startup_placeholder'))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user