mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 04:04:45 +02:00
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:
parent
a47ad071c9
commit
a8c3082b79
@ -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'])
|
||||||
|
->placeholder(trans('admin/server.select_allocation')),
|
||||||
|
Select::make('allocation_additional')
|
||||||
|
->label(trans('admin/server.additional_allocations'))
|
||||||
|
->multiple()
|
||||||
|
->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]))
|
||||||
|
->searchable(['ip', 'port', 'ip_alias'])
|
||||||
|
->placeholder(trans('admin/server.select_additional')),
|
||||||
]),
|
]),
|
||||||
Select::make('newAdditionalAllocation')
|
|
||||||
->label('New Additional Allocations')
|
|
||||||
->options([
|
|
||||||
true => 'on',
|
|
||||||
false => 'off',
|
|
||||||
]),
|
|
||||||
])
|
|
||||||
->modalheading(trans('admin/server.transfer')),
|
|
||||||
])->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)
|
||||||
|
@ -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',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user