mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 07:24:45 +02:00
add servers relationship to users
This commit is contained in:
parent
287c657e60
commit
32a3b8dd9b
@ -348,7 +348,8 @@ class ServerResource extends Resource
|
|||||||
->columnSpanFull(),
|
->columnSpanFull(),
|
||||||
|
|
||||||
Forms\Components\KeyValue::make('environment')
|
Forms\Components\KeyValue::make('environment')
|
||||||
->default([]),
|
->default([])
|
||||||
|
->columnSpanFull(),
|
||||||
|
|
||||||
Forms\Components\Section::make('Egg Variables')
|
Forms\Components\Section::make('Egg Variables')
|
||||||
->icon('tabler-eggs')
|
->icon('tabler-eggs')
|
||||||
|
@ -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