mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 10:54:46 +02:00
Merge branch 'feature/filament' of github.com:pelican-dev/panel into feature/filament
# Conflicts: # app/Filament/Resources/ServerResource.php
This commit is contained in:
commit
bfe8fc66ce
@ -445,6 +445,66 @@ 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\KeyValue::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(),
|
||||||
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
namespace App\Filament\Resources;
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
use App\Filament\Resources\UserResource\Pages;
|
use App\Filament\Resources\UserResource\Pages;
|
||||||
|
use App\Filament\Resources\UserResource\RelationManagers;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
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;
|
||||||
@ -23,54 +25,56 @@ class UserResource extends Resource
|
|||||||
{
|
{
|
||||||
return $form
|
return $form
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\TextInput::make('username')->required()->maxLength(191),
|
Section::make()->schema([
|
||||||
Forms\Components\TextInput::make('email')->email()->required()->maxLength(191),
|
Forms\Components\TextInput::make('username')->required()->maxLength(191),
|
||||||
|
Forms\Components\TextInput::make('email')->email()->required()->maxLength(191),
|
||||||
|
|
||||||
Forms\Components\TextInput::make('name_first')
|
Forms\Components\TextInput::make('name_first')
|
||||||
->maxLength(191)
|
->maxLength(191)
|
||||||
->hidden(fn (string $operation): bool => $operation === 'create')
|
->hidden(fn (string $operation): bool => $operation === 'create')
|
||||||
->label('First Name'),
|
->label('First Name'),
|
||||||
Forms\Components\TextInput::make('name_last')
|
Forms\Components\TextInput::make('name_last')
|
||||||
->maxLength(191)
|
->maxLength(191)
|
||||||
->hidden(fn (string $operation): bool => $operation === 'create')
|
->hidden(fn (string $operation): bool => $operation === 'create')
|
||||||
->label('Last Name'),
|
->label('Last Name'),
|
||||||
|
|
||||||
Forms\Components\TextInput::make('password')
|
Forms\Components\TextInput::make('password')
|
||||||
->dehydrateStateUsing(fn (string $state): string => Hash::make($state))
|
->dehydrateStateUsing(fn (string $state): string => Hash::make($state))
|
||||||
->dehydrated(fn (?string $state): bool => filled($state))
|
->dehydrated(fn (?string $state): bool => filled($state))
|
||||||
->required(fn (string $operation): bool => $operation === 'create')
|
->required(fn (string $operation): bool => $operation === 'create')
|
||||||
->password(),
|
->password(),
|
||||||
|
|
||||||
Forms\Components\ToggleButtons::make('root_admin')
|
Forms\Components\ToggleButtons::make('root_admin')
|
||||||
->label('Administrator (Root)')
|
->label('Administrator (Root)')
|
||||||
->options([
|
->options([
|
||||||
false => 'No',
|
false => 'No',
|
||||||
true => 'Admin',
|
true => 'Admin',
|
||||||
])
|
])
|
||||||
->colors([
|
->colors([
|
||||||
false => 'primary',
|
false => 'primary',
|
||||||
true => 'danger',
|
true => 'danger',
|
||||||
])
|
])
|
||||||
->disableOptionWhen(function (string $operation, $value, User $user) {
|
->disableOptionWhen(function (string $operation, $value, User $user) {
|
||||||
if ($operation !== 'edit' || $value) {
|
if ($operation !== 'edit' || $value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $user->isLastRootAdmin();
|
return $user->isLastRootAdmin();
|
||||||
})
|
})
|
||||||
->hint(fn (User $user) => $user->isLastRootAdmin() ? 'This is the last root administrator!' : '')
|
->hint(fn (User $user) => $user->isLastRootAdmin() ? 'This is the last root administrator!' : '')
|
||||||
->helperText(fn (User $user) => $user->isLastRootAdmin() ? 'You must have at least one root administrator in your system.' : '')
|
->helperText(fn (User $user) => $user->isLastRootAdmin() ? 'You must have at least one root administrator in your system.' : '')
|
||||||
->hintColor('warning')
|
->hintColor('warning')
|
||||||
->inline()
|
->inline()
|
||||||
->required()
|
->required()
|
||||||
->default(false),
|
->default(false),
|
||||||
|
|
||||||
Forms\Components\Hidden::make('skipValidation')->default(true),
|
Forms\Components\Hidden::make('skipValidation')->default(true),
|
||||||
Forms\Components\Select::make('language')
|
Forms\Components\Select::make('language')
|
||||||
->required()
|
->required()
|
||||||
->hidden()
|
->hidden()
|
||||||
->default('en')
|
->default('en')
|
||||||
->options(fn (User $user) => $user->getAvailableLanguages()),
|
->options(fn (User $user) => $user->getAvailableLanguages()),
|
||||||
|
])->columns(2),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +134,7 @@ class UserResource extends Resource
|
|||||||
public static function getRelations(): array
|
public static function getRelations(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
//
|
RelationManagers\ServersRelationManager::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\UserResource\RelationManagers;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
|
|
||||||
|
class ServersRelationManager extends RelationManager
|
||||||
|
{
|
||||||
|
protected static string $relationship = 'servers';
|
||||||
|
|
||||||
|
public function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->searchable(false)
|
||||||
|
->columns([
|
||||||
|
Tables\Columns\TextColumn::make('uuid')
|
||||||
|
->hidden()
|
||||||
|
->label('UUID')
|
||||||
|
->searchable(),
|
||||||
|
Tables\Columns\TextColumn::make('name')
|
||||||
|
->icon('tabler-brand-docker')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('node.name')
|
||||||
|
->icon('tabler-server-2')
|
||||||
|
->url(fn (Server $server): string => route('filament.admin.resources.nodes.edit', ['record' => $server->node]))
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('egg.name')
|
||||||
|
->icon('tabler-egg')
|
||||||
|
->url(fn (Server $server): string => route('filament.admin.resources.eggs.edit', ['record' => $server->egg]))
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\SelectColumn::make('allocation.id')
|
||||||
|
->label('Primary Allocation')
|
||||||
|
->options(fn ($state, Server $server) => [$server->allocation->id => $server->allocation->address])
|
||||||
|
->selectablePlaceholder(false)
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('image')->hidden(),
|
||||||
|
Tables\Columns\TextColumn::make('databases_count')
|
||||||
|
->counts('databases')
|
||||||
|
->label('Databases')
|
||||||
|
->icon('tabler-database')
|
||||||
|
->numeric()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('backups_count')
|
||||||
|
->counts('backups')
|
||||||
|
->label('Backups')
|
||||||
|
->icon('tabler-file-download')
|
||||||
|
->numeric()
|
||||||
|
->sortable(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user