Merge branch 'feature/filament' of github.com:pelican-dev/panel into feature/filament

# Conflicts:
#	app/Filament/Resources/ServerResource.php
This commit is contained in:
Lance Pioch 2024-04-14 22:24:30 -04:00
commit 058371ba7d
2 changed files with 43 additions and 96 deletions

View File

@ -5,6 +5,7 @@ namespace App\Filament\Resources;
use App\Filament\Resources\DatabaseHostResource\Pages; use App\Filament\Resources\DatabaseHostResource\Pages;
use App\Models\DatabaseHost; use App\Models\DatabaseHost;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
@ -22,40 +23,45 @@ class DatabaseHostResource extends Resource
{ {
return $form return $form
->schema([ ->schema([
Forms\Components\TextInput::make('host') Section::make()->schema([
->helperText('The IP address or Domain name that should be used when attempting to connect to this MySQL host from this Panel to create new databases.') Forms\Components\TextInput::make('host')
->required() ->helperText('The IP address or Domain name that should be used when attempting to connect to this MySQL host from this Panel to create new databases.')
->live() ->required()
->debounce(500) ->live()
->afterStateUpdated(fn ($state, Forms\Set $set) => $set('name', $state)) ->debounce(500)
->maxLength(191), ->afterStateUpdated(fn ($state, Forms\Set $set) => $set('name', $state))
Forms\Components\TextInput::make('port') ->maxLength(191),
->helperText('The port that MySQL is running on for this host.') Forms\Components\TextInput::make('port')
->required() ->helperText('The port that MySQL is running on for this host.')
->numeric() ->required()
->default(3306) ->numeric()
->minValue(0) ->default(3306)
->maxValue(65535), ->minValue(0)
Forms\Components\TextInput::make('username') ->maxValue(65535),
->helperText('The username of an account that has enough permissions to create new users and databases on the system.') Forms\Components\TextInput::make('username')
->required() ->helperText('The username of an account that has enough permissions to create new users and databases on the system.')
->maxLength(191), ->required()
Forms\Components\TextInput::make('password') ->maxLength(191),
->helperText('The password for the database user.') Forms\Components\TextInput::make('password')
->password() ->helperText('The password for the database user.')
->revealable() ->password()
->maxLength(191) ->revealable()
->required(), ->maxLength(191)
Forms\Components\TextInput::make('name') ->required(),
->helperText('A short identifier used to distinguish this location from others. Must be between 1 and 60 characters, for example, us.nyc.lvl3.') Forms\Components\TextInput::make('name')
->required() ->helperText('A short identifier used to distinguish this location from others. Must be between 1 and 60 characters, for example, us.nyc.lvl3.')
->maxLength(60), ->required()
Forms\Components\Select::make('node_id') ->maxLength(60),
->searchable() Forms\Components\Select::make('node_id')
->preload() ->searchable()
->helperText('This setting only defaults to this database host when adding a database to a server on the selected node.') ->preload()
->label('Linked Node') ->helperText('This setting only defaults to this database host when adding a database to a server on the selected node.')
->relationship('node', 'name'), ->label('Linked Node')
->relationship('node', 'name'),
])->columns([
'default' => 1,
'lg' => 2,
]),
]); ]);
} }

View File

@ -7,7 +7,6 @@ use App\Models\Allocation;
use App\Models\Egg; use App\Models\Egg;
use App\Models\Node; use App\Models\Node;
use App\Models\Server; use App\Models\Server;
use App\Repositories\Daemon\DaemonServerRepository;
use App\Services\Allocations\AssignmentService; use App\Services\Allocations\AssignmentService;
use Closure; use Closure;
use Filament\Forms; use Filament\Forms;
@ -176,7 +175,9 @@ class ServerResource extends Resource
'ip', 'ip',
fn (Builder $query, Forms\Get $get, Forms\Components\Select $component, $state) => $query fn (Builder $query, Forms\Get $get, Forms\Components\Select $component, $state) => $query
->where('node_id', $get('../../node_id')) ->where('node_id', $get('../../node_id'))
->whereNotIn('id', collect(($repeater = $component->getParentRepeater())->getState()) ->whereNotIn(
'id',
collect(($repeater = $component->getParentRepeater())->getState())
->pluck( ->pluck(
(string) str($component->getStatePath()) (string) str($component->getStatePath())
->after("{$repeater->getStatePath()}.") ->after("{$repeater->getStatePath()}.")
@ -441,66 +442,6 @@ class ServerResource extends Resource
]) ])
->required(), ->required(),
]), ]),
Forms\Components\Textarea::make('startup')
->hintIcon('tabler-code')
->label('Startup Command')
->required()
->live()
->rows(function ($state) {
return str($state)->explode("\n")->reduce(
fn (int $carry, $line) => $carry + floor(strlen($line) / 125),
0
);
})
->columnSpanFull(),
Forms\Components\Hidden::make('environment')
->default([])
->columnSpanFull(),
Forms\Components\Section::make('Egg Variables')
->icon('tabler-eggs')
->iconColor('primary')
->collapsible()
->collapsed()
->schema([
Forms\Components\Placeholder::make('Select an egg first to show its variables!')
->hidden(fn (Forms\Get $get) => !empty($get('server_variables'))),
Forms\Components\Repeater::make('server_variables')
->relationship('serverVariables')
->grid(2)
->reorderable(false)
->addable(false)
->deletable(false)
->default([])
->hidden(fn ($state) => empty($state))
->schema([
Forms\Components\TextInput::make('variable_value')
->rules([
fn (Forms\Get $get): Closure => function (string $attribute, $value, Closure $fail) use ($get) {
$validator = Validator::make(['validatorkey' => $value], [
'validatorkey' => $get('rules'),
]);
if ($validator->fails()) {
$message = str($validator->errors()->first())->replace('validatorkey', $get('name'));
$fail($message);
}
},
])
->label(fn (Forms\Get $get) => $get('name'))
->hint(fn (Forms\Get $get) => $get('rules'))
->prefix(fn (Forms\Get $get) => '{{' . $get('env_variable') . '}}')
->helperText(fn (Forms\Get $get) => empty($get('description')) ? '—' : $get('description'))
->maxLength(191),
Forms\Components\Hidden::make('variable_id')->default(0),
])
->columnSpanFull(),
]),
]); ]);
} }