Add UI for server transfers (#1119)

* add ui for server transfers

* disable transfer button when server is in conflict state
This commit is contained in:
Boy132 2025-03-23 22:02:22 +01:00 committed by GitHub
parent a47ad071c9
commit a8c3082b79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 25 deletions

View File

@ -8,10 +8,12 @@ use App\Filament\Admin\Resources\ServerResource\RelationManagers\AllocationsRela
use App\Filament\Components\Forms\Actions\PreviewStartupAction; use App\Filament\Components\Forms\Actions\PreviewStartupAction;
use App\Filament\Components\Forms\Actions\RotateDatabasePasswordAction; use App\Filament\Components\Forms\Actions\RotateDatabasePasswordAction;
use App\Filament\Server\Pages\Console; use App\Filament\Server\Pages\Console;
use App\Models\Allocation;
use App\Models\Database; use App\Models\Database;
use App\Models\DatabaseHost; use App\Models\DatabaseHost;
use App\Models\Egg; use App\Models\Egg;
use App\Models\Mount; use App\Models\Mount;
use App\Models\Node;
use App\Models\Server; use App\Models\Server;
use App\Models\ServerVariable; use App\Models\ServerVariable;
use App\Models\User; use App\Models\User;
@ -52,6 +54,7 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Client\ConnectionException; use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Support\HtmlString;
use LogicException; use LogicException;
use Webbingbrasil\FilamentCopyActions\Forms\Actions\CopyAction; use Webbingbrasil\FilamentCopyActions\Forms\Actions\CopyAction;
@ -858,34 +861,53 @@ class EditServer extends EditRecord
Forms\Components\Actions::make([ Forms\Components\Actions::make([
Action::make('transfer') Action::make('transfer')
->label(trans('admin/server.transfer')) ->label(trans('admin/server.transfer'))
// ->action(fn (TransferServerService $transfer, Server $server) => $transfer->handle($server, [])) ->disabled(fn (Server $server) => Node::count() <= 1 || $server->isInConflictState())
->disabled() //TODO! ->modalheading(trans('admin/server.transfer'))
->form([ //TODO! ->action(function (TransferServerService $transfer, Server $server, $data) {
Select::make('newNode') try {
->label('New Node') $transfer->handle($server, $data);
Notification::make()
->title('Transfer started')
->success()
->send();
} catch (Exception $exception) {
Notification::make()
->title('Transfer failed')
->body($exception->getMessage())
->danger()
->send();
}
})
->form([
Select::make('node_id')
->label(trans('admin/server.node'))
->prefixIcon('tabler-server-2')
->selectablePlaceholder(false)
->default(fn (Server $server) => Node::whereNot('id', $server->node->id)->first()?->id)
->required() ->required()
->options([ ->live()
true => 'on', ->options(fn (Server $server) => Node::whereNot('id', $server->node->id)->pluck('name', 'id')->all()),
false => 'off', Select::make('allocation_id')
]), ->label(trans('admin/server.primary_allocation'))
Select::make('newMainAllocation')
->label('New Main Allocation')
->required() ->required()
->options([ ->prefixIcon('tabler-network')
true => 'on', ->disabled(fn (Get $get) => !$get('node_id'))
false => 'off', ->options(fn (Get $get) => Allocation::where('node_id', $get('node_id'))->whereNull('server_id')->get()->mapWithKeys(fn (Allocation $allocation) => [$allocation->id => $allocation->address]))
]), ->searchable(['ip', 'port', 'ip_alias'])
Select::make('newAdditionalAllocation') ->placeholder(trans('admin/server.select_allocation')),
->label('New Additional Allocations') Select::make('allocation_additional')
->options([ ->label(trans('admin/server.additional_allocations'))
true => 'on', ->multiple()
false => 'off', ->prefixIcon('tabler-network')
]), ->disabled(fn (Get $get) => !$get('node_id'))
]) ->options(fn (Get $get) => Allocation::where('node_id', $get('node_id'))->whereNull('server_id')->when($get('allocation_id'), fn ($query) => $query->whereNot('id', $get('allocation_id')))->get()->mapWithKeys(fn (Allocation $allocation) => [$allocation->id => $allocation->address]))
->modalheading(trans('admin/server.transfer')), ->searchable(['ip', 'port', 'ip_alias'])
->placeholder(trans('admin/server.select_additional')),
]),
])->fullWidth(), ])->fullWidth(),
ToggleButtons::make('') ToggleButtons::make('')
->hint(trans('admin/server.transfer_help')), ->hint(new HtmlString(trans('admin/server.transfer_help'))),
]), ]),
Grid::make() Grid::make()
->columnSpan(3) ->columnSpan(3)

View File

@ -70,7 +70,7 @@ return [
'toggle_install' => 'Toggle Install Status', 'toggle_install' => 'Toggle Install Status',
'toggle_install_help' => 'If you need to change the install status from uninstalled to installed, or vice versa, you may do so with this button.', 'toggle_install_help' => 'If you need to change the install status from uninstalled to installed, or vice versa, you may do so with this button.',
'transfer' => 'Transfer', 'transfer' => 'Transfer',
'transfer_help' => 'Transfer this server to another node connected to this panel. Warning! This feature has not been fully tested and may have bugs.', 'transfer_help' => 'Transfer this server to another node connected to this panel.<br/><b>Warning!</b> This feature is still experimental. Consider manually making a backup first to avoid data loss!',
'condition' => 'Condition', 'condition' => 'Condition',
'suspend_all' => 'Suspend All Servers', 'suspend_all' => 'Suspend All Servers',
'unsuspend_all' => 'Unsuspend All Servers', 'unsuspend_all' => 'Unsuspend All Servers',