finish admin frontend

This commit is contained in:
Boy132 2025-09-04 15:10:20 +02:00
parent b966fe1efe
commit a59a84538c
5 changed files with 78 additions and 31 deletions

View File

@ -39,7 +39,6 @@ use Filament\Resources\Pages\CreateRecord;
use Filament\Support\Exceptions\Halt;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\HtmlString;
use LogicException;
@ -317,7 +316,7 @@ class CreateServer extends CreateRecord
->live()
->afterStateUpdated(function ($state, Set $set, Get $get, $old) {
$egg = Egg::query()->find($state);
$set('startup', Arr::first($egg->startup_commands, default: ''));
$set('startup', '');
$set('image', '');
$variables = $egg->variables ?? [];
@ -391,23 +390,44 @@ class CreateServer extends CreateRecord
])
->inline(),
Textarea::make('startup')
Select::make('select_startup')
->label(trans('admin/server.startup_name'))
->hidden(fn (Get $get) => $get('egg_id') === null)
->live()
->afterStateUpdated(fn (Set $set, $state) => $set('startup', $state))
->options(function ($state, Get $get, Set $set) {
$egg = Egg::query()->find($get('egg_id'));
$startups = $egg->startup_commands ?? [];
$currentStartup = $get('startup');
if (!$currentStartup && $startups) {
$currentStartup = collect($startups)->first();
$set('startup', $currentStartup);
$set('select_startup', $currentStartup);
}
return array_flip($startups) + ['' => 'Custom Startup'];
})
->selectablePlaceholder(false)
->columnSpanFull(),
TextInput::make('startup')
->label(trans('admin/server.startup_cmd'))
->hidden(fn (Get $get) => $get('egg_id') === null)
->required()
->live()
->rows(function ($state) {
return str($state)->explode("\n")->reduce(
fn (int $carry, $line) => $carry + floor(strlen($line) / 125),
1
);
->afterStateUpdated(function ($state, Get $get, Set $set) {
$egg = Egg::query()->find($get('egg_id'));
$startups = $egg->startup_commands ?? [];
if (in_array($state, $startups)) {
$set('select_startup', $state);
} else {
$set('select_startup', '');
}
})
->columnSpan([
'default' => 1,
'sm' => 4,
'md' => 4,
'lg' => 6,
]),
->placeholder(trans('admin/server.startup_placeholder'))
->columnSpanFull(),
Hidden::make('environment')->default([]),

View File

@ -593,26 +593,47 @@ class EditServer extends EditRecord
true => 'tabler-code-off',
])
->required(),
Hidden::make('previewing')
->default(false),
Textarea::make('startup')
Select::make('select_startup')
->label(trans('admin/server.startup_name'))
->live()
->afterStateUpdated(fn (Set $set, $state) => $set('startup', $state))
->options(function ($state, Get $get, Set $set) {
$egg = Egg::query()->find($get('egg_id'));
$startups = $egg->startup_commands ?? [];
$currentStartup = $get('startup');
if (!$currentStartup && $startups) {
$currentStartup = collect($startups)->first();
$set('startup', $currentStartup);
$set('select_startup', $currentStartup);
}
return array_flip($startups) + ['' => 'Custom Startup'];
})
->selectablePlaceholder(false)
->columnSpanFull(),
TextInput::make('startup')
->label(trans('admin/server.startup_cmd'))
->required()
->columnSpan(6)
->autosize()
->hintAction(PreviewStartupAction::make('preview')),
Textarea::make('default_startup')
->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->label(trans('admin/server.default_startup'))
->disabled()
->autosize()
->columnSpan(6)
->formatStateUsing(function ($state, Get $get) {
->live()
->afterStateUpdated(function ($state, Get $get, Set $set) {
$egg = Egg::query()->find($get('egg_id'));
$startups = $egg->startup_commands ?? [];
return Arr::first($egg->startup_commands);
}),
if (in_array($state, $startups)) {
$set('select_startup', $state);
} else {
$set('select_startup', '');
}
})
->placeholder(trans('admin/server.startup_placeholder'))
->columnSpanFull()
->hintAction(PreviewStartupAction::make('preview')),
Repeater::make('server_variables')
->hiddenLabel()

View File

@ -26,8 +26,10 @@ class PreviewStartupAction extends Action
$this->action(function (Get $get, Set $set, Server $server) {
$active = $get('previewing');
$startup = $get('startup');
$set('previewing', !$active);
$set('startup', $active ? $server->startup : fn (Server $server, StartupCommandService $service) => $service->handle($server));
$set('startup', $active ? $startup : fn (Server $server, StartupCommandService $service) => $service->handle($server, $startup));
});
}
}

View File

@ -9,8 +9,10 @@ class StartupCommandService
/**
* Generates a startup command for a given server instance.
*/
public function handle(Server $server, bool $hideAllValues = false): string
public function handle(Server $server, ?string $startup = null, bool $hideAllValues = false): string
{
$startup ??= $server->startup;
$find = ['{{SERVER_MEMORY}}', '{{SERVER_IP}}', '{{SERVER_PORT}}'];
$replace = [
(string) $server->memory,
@ -23,6 +25,6 @@ class StartupCommandService
$replace[] = ($variable->user_viewable && !$hideAllValues) ? ($variable->server_value ?? $variable->default_value) : '[hidden]';
}
return str_replace($find, $replace, $server->startup);
return str_replace($find, $replace, $startup);
}
}

View File

@ -25,7 +25,9 @@ return [
'already_primary' => 'Already Primary',
'make_primary' => 'Make Primary',
'startup_cmd' => 'Startup Command',
'startup_name' => 'Startup Name',
'default_startup' => 'Default Startup Command',
'startup_placeholder' => 'Enter a custom startup command',
'variables' => 'Variables',
'resource_limits' => 'Resource Limits',
'cpu' => 'CPU',