From a6326f64fb38400ae4cd746c967766d4cec9488c Mon Sep 17 00:00:00 2001 From: Boy132 Date: Mon, 5 May 2025 13:00:34 +0200 Subject: [PATCH] Add back `behind_proxy` to ui (#1263) * add back `behind_proxy` to ui * combine `scheme` and `behind_proxy` into one component * remove debug stuff * update translations * make bulky --- .../NodeResource/Pages/CreateNode.php | 29 +++++++++++++------ .../Resources/NodeResource/Pages/EditNode.php | 19 ++++++++++-- app/Models/Node.php | 2 +- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/Filament/Admin/Resources/NodeResource/Pages/CreateNode.php b/app/Filament/Admin/Resources/NodeResource/Pages/CreateNode.php index 302ac18cb..65c4dd16e 100644 --- a/app/Filament/Admin/Resources/NodeResource/Pages/CreateNode.php +++ b/app/Filament/Admin/Resources/NodeResource/Pages/CreateNode.php @@ -7,6 +7,7 @@ use App\Models\Node; use Filament\Forms; use Filament\Forms\Components\Actions\Action; use Filament\Forms\Components\Grid; +use Filament\Forms\Components\Hidden; use Filament\Forms\Components\TagsInput; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\ToggleButtons; @@ -149,14 +150,15 @@ class CreateNode extends CreateRecord ->required() ->maxLength(100), - ToggleButtons::make('scheme') + Hidden::make('scheme') + ->default(fn () => request()->isSecure() ? 'https' : 'http'), + + Hidden::make('behind_proxy') + ->default(false), + + ToggleButtons::make('connection') ->label(trans('admin/node.ssl')) - ->columnSpan([ - 'default' => 1, - 'sm' => 1, - 'md' => 1, - 'lg' => 1, - ]) + ->columnSpan(1) ->inline() ->helperText(function (Get $get) { if (request()->isSecure()) { @@ -169,20 +171,29 @@ class CreateNode extends CreateRecord return ''; }) - ->disableOptionWhen(fn (string $value): bool => $value === 'http' && request()->isSecure()) + ->disableOptionWhen(fn (string $value) => $value === 'http' && request()->isSecure()) ->options([ 'http' => 'HTTP', 'https' => 'HTTPS (SSL)', + 'https_proxy' => 'HTTPS with (reverse) proxy', ]) ->colors([ 'http' => 'warning', 'https' => 'success', + 'https_proxy' => 'success', ]) ->icons([ 'http' => 'tabler-lock-open-off', 'https' => 'tabler-lock', + 'https_proxy' => 'tabler-shield-lock', ]) - ->default(fn () => request()->isSecure() ? 'https' : 'http'), + ->default(fn () => request()->isSecure() ? 'https' : 'http') + ->live() + ->dehydrated(false) + ->afterStateUpdated(function ($state, Set $set) { + $set('scheme', $state === 'http' ? 'http' : 'https'); + $set('behind_proxy', $state === 'https_proxy'); + }), ]), Step::make('advanced') ->label(trans('admin/node.tabs.advanced_settings')) diff --git a/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php b/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php index 78d5eafdd..c93ad412b 100644 --- a/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php +++ b/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php @@ -14,6 +14,7 @@ use Filament\Forms; use Filament\Forms\Components\Actions as FormActions; use Filament\Forms\Components\Fieldset; use Filament\Forms\Components\Grid; +use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Placeholder; use Filament\Forms\Components\Tabs; use Filament\Forms\Components\Tabs\Tab; @@ -199,7 +200,9 @@ class EditNode extends EditRecord ]) ->required() ->maxLength(100), - ToggleButtons::make('scheme') + Hidden::make('scheme'), + Hidden::make('behind_proxy'), + ToggleButtons::make('connection') ->label(trans('admin/node.ssl')) ->columnSpan(1) ->inline() @@ -214,20 +217,30 @@ class EditNode extends EditRecord return ''; }) - ->disableOptionWhen(fn (string $value): bool => $value === 'http' && request()->isSecure()) + ->disableOptionWhen(fn (string $value) => $value === 'http' && request()->isSecure()) ->options([ 'http' => 'HTTP', 'https' => 'HTTPS (SSL)', + 'https_proxy' => 'HTTPS with (reverse) proxy', ]) ->colors([ 'http' => 'warning', 'https' => 'success', + 'https_proxy' => 'success', ]) ->icons([ 'http' => 'tabler-lock-open-off', 'https' => 'tabler-lock', + 'https_proxy' => 'tabler-shield-lock', ]) - ->default(fn () => request()->isSecure() ? 'https' : 'http'), ]), + ->formatStateUsing(fn (Get $get) => $get('scheme') === 'http' ? 'http' : ($get('behind_proxy') ? 'https_proxy' : 'https')) + ->live() + ->dehydrated(false) + ->afterStateUpdated(function ($state, Set $set) { + $set('scheme', $state === 'http' ? 'http' : 'https'); + $set('behind_proxy', $state === 'https_proxy'); + }), + ]), Tab::make('adv') ->label(trans('admin/node.tabs.advanced_settings')) ->columns([ diff --git a/app/Models/Node.php b/app/Models/Node.php index c0e07ab48..98ff118c8 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -216,7 +216,7 @@ class Node extends Model implements Validatable ], ], 'allowed_mounts' => $this->mounts->pluck('source')->toArray(), - 'remote' => route('filament.app.resources...index'), + 'remote' => config('app.url'), ]; }