From 1337767049300a652a924317f24916e4fdf8cf90 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Mon, 2 Dec 2024 22:27:35 +0100 Subject: [PATCH] Small changes for new client area (#751) * add placeholder to allocation notes * add button to open server in admin area * use new client area for "console" button on EditServer * hide schedule presets on view * use arrow functions for auth checks * add placeholder to schedules last run * change icon of "open in admin" * fix parentheses --- .../Resources/ServerResource/Pages/EditServer.php | 3 ++- app/Filament/Server/Pages/Settings.php | 6 +++--- app/Filament/Server/Pages/Startup.php | 4 ++-- .../AllocationResource/Pages/ListAllocations.php | 3 ++- .../Server/Resources/FileResource/Pages/EditFiles.php | 2 +- app/Filament/Server/Resources/ScheduleResource.php | 1 + .../Resources/ScheduleResource/Pages/ListSchedules.php | 1 + app/Providers/Filament/ServerPanelProvider.php | 9 +++++++++ 8 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/Filament/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Resources/ServerResource/Pages/EditServer.php index 172c1ebf45..126d098e7f 100644 --- a/app/Filament/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Resources/ServerResource/Pages/EditServer.php @@ -6,6 +6,7 @@ use App\Enums\ServerState; use App\Filament\Resources\ServerResource; use App\Filament\Resources\ServerResource\RelationManagers\AllocationsRelationManager; +use App\Filament\Server\Pages\Console; use App\Models\Database; use App\Models\DatabaseHost; use App\Models\Egg; @@ -870,7 +871,7 @@ protected function getHeaderActions(): array Actions\Action::make('console') ->label('Console') ->icon('tabler-terminal') - ->url(fn (Server $server) => "/server/$server->uuid_short"), + ->url(fn (Server $server) => Console::getUrl(panel: 'server', tenant: $server)), $this->getSaveFormAction()->formId('form'), ]; diff --git a/app/Filament/Server/Pages/Settings.php b/app/Filament/Server/Pages/Settings.php index c4d01a09f5..758676fe35 100644 --- a/app/Filament/Server/Pages/Settings.php +++ b/app/Filament/Server/Pages/Settings.php @@ -53,7 +53,7 @@ public function form(Form $form): Form ->schema([ TextInput::make('name') ->label('Server Name') - ->disabled(!auth()->user()->can(Permission::ACTION_SETTINGS_RENAME, $server)) + ->disabled(fn () => !auth()->user()->can(Permission::ACTION_SETTINGS_RENAME, $server)) ->required() ->columnSpan([ 'default' => 1, @@ -66,7 +66,7 @@ public function form(Form $form): Form Textarea::make('description') ->label('Server Description') ->hidden(!config('panel.editable_server_descriptions')) - ->disabled(!auth()->user()->can(Permission::ACTION_SETTINGS_RENAME, $server)) + ->disabled(fn () => !auth()->user()->can(Permission::ACTION_SETTINGS_RENAME, $server)) ->columnSpan([ 'default' => 1, 'sm' => 2, @@ -168,7 +168,7 @@ public function form(Form $form): Form ->footerActions([ Action::make('reinstall') ->color('danger') - ->disabled(!auth()->user()->can(Permission::ACTION_SETTINGS_REINSTALL, $server)) + ->disabled(fn () => !auth()->user()->can(Permission::ACTION_SETTINGS_REINSTALL, $server)) ->label('Reinstall') ->requiresConfirmation() ->modalHeading('Are you sure you want to reinstall the server?') diff --git a/app/Filament/Server/Pages/Startup.php b/app/Filament/Server/Pages/Startup.php index 943a9a4d9b..4aa8dd0de5 100644 --- a/app/Filament/Server/Pages/Startup.php +++ b/app/Filament/Server/Pages/Startup.php @@ -62,7 +62,7 @@ public function form(Form $form): Form ->label('Docker Image') ->live() ->visible(fn (Server $server) => in_array($server->image, $server->egg->docker_images)) - ->disabled(!auth()->user()->can(Permission::ACTION_STARTUP_DOCKER_IMAGE, $server)) + ->disabled(fn () => !auth()->user()->can(Permission::ACTION_STARTUP_DOCKER_IMAGE, $server)) ->afterStateUpdated(function ($state, Server $server) { $original = $server->image; $server->forceFill(['image' => $state])->saveOrFail(); @@ -97,7 +97,7 @@ public function form(Form $form): Form ->label('') ->relationship('viewableServerVariables') ->grid() - ->disabled(!auth()->user()->can(Permission::ACTION_STARTUP_UPDATE, $server)) + ->disabled(fn () => !auth()->user()->can(Permission::ACTION_STARTUP_UPDATE, $server)) ->reorderable(false)->addable(false)->deletable(false) ->schema(function () { $text = TextInput::make('variable_value') diff --git a/app/Filament/Server/Resources/AllocationResource/Pages/ListAllocations.php b/app/Filament/Server/Resources/AllocationResource/Pages/ListAllocations.php index 0ca5154048..a7ed76d99b 100644 --- a/app/Filament/Server/Resources/AllocationResource/Pages/ListAllocations.php +++ b/app/Filament/Server/Resources/AllocationResource/Pages/ListAllocations.php @@ -36,7 +36,8 @@ public function table(Table $table): Table TextColumn::make('port'), TextInputColumn::make('notes') ->disabled(fn () => !auth()->user()->can(Permission::ACTION_ALLOCATION_UPDATE, $server)) - ->label('Notes'), + ->label('Notes') + ->placeholder('No Notes'), IconColumn::make('primary') ->icon(fn ($state) => match ($state) { true => 'tabler-star-filled', diff --git a/app/Filament/Server/Resources/FileResource/Pages/EditFiles.php b/app/Filament/Server/Resources/FileResource/Pages/EditFiles.php index 2d7b9a8629..b6c2cd440b 100644 --- a/app/Filament/Server/Resources/FileResource/Pages/EditFiles.php +++ b/app/Filament/Server/Resources/FileResource/Pages/EditFiles.php @@ -70,7 +70,7 @@ public function form(Form $form): Form ->footerActions([ Action::make('save') ->label('Save Changes') - ->authorize(auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server)) + ->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server)) ->icon('tabler-device-floppy') ->keyBindings('mod+s') ->action(function () use ($server) { diff --git a/app/Filament/Server/Resources/ScheduleResource.php b/app/Filament/Server/Resources/ScheduleResource.php index 470fc5ada8..5cec5f2750 100644 --- a/app/Filament/Server/Resources/ScheduleResource.php +++ b/app/Filament/Server/Resources/ScheduleResource.php @@ -111,6 +111,7 @@ public static function form(Form $form): Form ->default('*') ->required(), Section::make('Presets') + ->hiddenOn('view') ->schema([ Actions::make([ Action::make('hourly') diff --git a/app/Filament/Server/Resources/ScheduleResource/Pages/ListSchedules.php b/app/Filament/Server/Resources/ScheduleResource/Pages/ListSchedules.php index 4f53bb3d8b..078488158b 100644 --- a/app/Filament/Server/Resources/ScheduleResource/Pages/ListSchedules.php +++ b/app/Filament/Server/Resources/ScheduleResource/Pages/ListSchedules.php @@ -33,6 +33,7 @@ public function table(Table $table): Table ->sortable(), DateTimeColumn::make('last_run_at') ->label('Last run') + ->placeholder('Never') ->since() ->sortable(), DateTimeColumn::make('next_run_at') diff --git a/app/Providers/Filament/ServerPanelProvider.php b/app/Providers/Filament/ServerPanelProvider.php index f1b946f18c..af815a89b3 100644 --- a/app/Providers/Filament/ServerPanelProvider.php +++ b/app/Providers/Filament/ServerPanelProvider.php @@ -4,6 +4,7 @@ use App\Filament\App\Resources\ServerResource\Pages\ListServers; use App\Filament\Pages\Auth\Login; +use App\Filament\Resources\ServerResource\Pages\EditServer; use App\Filament\Resources\UserResource\Pages\EditProfile; use App\Http\Middleware\Activity\ServerSubject; use App\Models\Server; @@ -12,6 +13,7 @@ use Filament\Http\Middleware\DisableBladeIconComponents; use Filament\Http\Middleware\DispatchServingFilamentEvent; use Filament\Navigation\MenuItem; +use Filament\Navigation\NavigationItem; use Filament\Panel; use Filament\PanelProvider; use Filament\Support\Enums\MaxWidth; @@ -54,6 +56,13 @@ public function panel(Panel $panel): Panel ->sort(5) ->visible(fn (): bool => auth()->user()->canAccessPanel(Filament::getPanel('admin'))), ]) + ->navigationItems([ + NavigationItem::make('Open in Admin') + ->url(fn () => EditServer::getUrl(['record' => Filament::getTenant()], panel: 'admin', tenant: null), true) + ->visible(fn () => auth()->user()->can('view server', Filament::getTenant())) + ->icon('tabler-arrow-back') + ->sort(99), + ]) ->discoverResources(in: app_path('Filament/Server/Resources'), for: 'App\\Filament\\Server\\Resources') ->discoverPages(in: app_path('Filament/Server/Pages'), for: 'App\\Filament\\Server\\Pages') ->discoverWidgets(in: app_path('Filament/Server/Widgets'), for: 'App\\Filament\\Server\\Widgets')