mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 20:24:44 +02:00
Add some refreshs & notifications to EditServer action buttons (#1174)
* add some refreshs & notifications to EditServer action buttons * reinstall server when trying to toggle failed state * don't show modal on normal toggle install * don't print raw exception on reinstall & suspension
This commit is contained in:
parent
2c00f90ba6
commit
630031e1c2
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Admin\Resources\ServerResource\Pages;
|
namespace App\Filament\Admin\Resources\ServerResource\Pages;
|
||||||
|
|
||||||
|
use App\Enums\ServerState;
|
||||||
use App\Enums\SuspendAction;
|
use App\Enums\SuspendAction;
|
||||||
use App\Filament\Admin\Resources\ServerResource;
|
use App\Filament\Admin\Resources\ServerResource;
|
||||||
use App\Filament\Admin\Resources\ServerResource\RelationManagers\AllocationsRelationManager;
|
use App\Filament\Admin\Resources\ServerResource\RelationManagers\AllocationsRelationManager;
|
||||||
@ -30,6 +31,7 @@ use Closure;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Components\Actions as FormActions;
|
||||||
use Filament\Forms\Components\Actions\Action;
|
use Filament\Forms\Components\Actions\Action;
|
||||||
use Filament\Forms\Components\CheckboxList;
|
use Filament\Forms\Components\CheckboxList;
|
||||||
use Filament\Forms\Components\Fieldset;
|
use Filament\Forms\Components\Fieldset;
|
||||||
@ -736,7 +738,7 @@ class EditServer extends EditRecord
|
|||||||
->deletable(false)
|
->deletable(false)
|
||||||
->addable(false)
|
->addable(false)
|
||||||
->columnSpan(4),
|
->columnSpan(4),
|
||||||
Forms\Components\Actions::make([
|
FormActions::make([
|
||||||
Action::make('createDatabase')
|
Action::make('createDatabase')
|
||||||
->authorize(fn () => auth()->user()->can('create database'))
|
->authorize(fn () => auth()->user()->can('create database'))
|
||||||
->disabled(fn () => DatabaseHost::query()->count() < 1)
|
->disabled(fn () => DatabaseHost::query()->count() < 1)
|
||||||
@ -804,14 +806,50 @@ class EditServer extends EditRecord
|
|||||||
Grid::make()
|
Grid::make()
|
||||||
->columnSpan(3)
|
->columnSpan(3)
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\Actions::make([
|
FormActions::make([
|
||||||
Action::make('toggleInstall')
|
Action::make('toggleInstall')
|
||||||
->label(trans('admin/server.toggle_install'))
|
->label(trans('admin/server.toggle_install'))
|
||||||
->disabled(fn (Server $server) => $server->isSuspended())
|
->disabled(fn (Server $server) => $server->isSuspended())
|
||||||
->action(function (ToggleInstallService $service, Server $server) {
|
->modal(fn (Server $server) => $server->status === ServerState::InstallFailed)
|
||||||
$service->handle($server);
|
->modalHeading(trans('admin/server.toggle_install_failed_header'))
|
||||||
|
->modalDescription(trans('admin/server.toggle_install_failed_desc'))
|
||||||
|
->modalSubmitActionLabel(trans('admin/server.reinstall'))
|
||||||
|
->action(function (ToggleInstallService $toggleService, ReinstallServerService $reinstallService, Server $server) {
|
||||||
|
if ($server->status === ServerState::InstallFailed) {
|
||||||
|
try {
|
||||||
|
$reinstallService->handle($server);
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title(trans('admin/server.notifications.reinstall_started'))
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
|
||||||
$this->refreshFormData(['status', 'docker']);
|
$this->refreshFormData(['status', 'docker']);
|
||||||
|
} catch (Exception) {
|
||||||
|
Notification::make()
|
||||||
|
->title(trans('admin/server.notifications.reinstall_failed'))
|
||||||
|
->body(trans('admin/server.error_connecting', ['node' => $server->node->name]))
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$toggleService->handle($server);
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title(trans('admin/server.notifications.install_toggled'))
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
$this->refreshFormData(['status', 'docker']);
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
Notification::make()
|
||||||
|
->title(trans('admin/server.notifications.install_toggle_failed'))
|
||||||
|
->body($exception->getMessage())
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
}
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
])->fullWidth(),
|
])->fullWidth(),
|
||||||
ToggleButtons::make('')
|
ToggleButtons::make('')
|
||||||
@ -820,7 +858,7 @@ class EditServer extends EditRecord
|
|||||||
Grid::make()
|
Grid::make()
|
||||||
->columnSpan(3)
|
->columnSpan(3)
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\Actions::make([
|
FormActions::make([
|
||||||
Action::make('toggleSuspend')
|
Action::make('toggleSuspend')
|
||||||
->label(trans('admin/server.suspend'))
|
->label(trans('admin/server.suspend'))
|
||||||
->color('warning')
|
->color('warning')
|
||||||
@ -828,12 +866,20 @@ class EditServer extends EditRecord
|
|||||||
->action(function (SuspensionService $suspensionService, Server $server) {
|
->action(function (SuspensionService $suspensionService, Server $server) {
|
||||||
try {
|
try {
|
||||||
$suspensionService->handle($server, SuspendAction::Suspend);
|
$suspensionService->handle($server, SuspendAction::Suspend);
|
||||||
} catch (\Exception $exception) {
|
|
||||||
Notification::make()->warning()->title(trans('admin/server.notifications.server_suspension'))->body($exception->getMessage())->send();
|
Notification::make()
|
||||||
}
|
->success()
|
||||||
Notification::make()->success()->title(trans('admin/server.notifications.server_suspended'))->send();
|
->title(trans('admin/server.notifications.server_suspended'))
|
||||||
|
->send();
|
||||||
|
|
||||||
$this->refreshFormData(['status', 'docker']);
|
$this->refreshFormData(['status', 'docker']);
|
||||||
|
} catch (Exception) {
|
||||||
|
Notification::make()
|
||||||
|
->warning()
|
||||||
|
->title(trans('admin/server.notifications.server_suspension'))
|
||||||
|
->body(trans('admin/server.error_connecting', ['node' => $server->node->name]))
|
||||||
|
->send();
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
Action::make('toggleUnsuspend')
|
Action::make('toggleUnsuspend')
|
||||||
->label(trans('admin/server.unsuspend'))
|
->label(trans('admin/server.unsuspend'))
|
||||||
@ -842,12 +888,20 @@ class EditServer extends EditRecord
|
|||||||
->action(function (SuspensionService $suspensionService, Server $server) {
|
->action(function (SuspensionService $suspensionService, Server $server) {
|
||||||
try {
|
try {
|
||||||
$suspensionService->handle($server, SuspendAction::Unsuspend);
|
$suspensionService->handle($server, SuspendAction::Unsuspend);
|
||||||
} catch (\Exception $exception) {
|
|
||||||
Notification::make()->warning()->title(trans('admin/server.notifications.server_suspension'))->body($exception->getMessage())->send();
|
Notification::make()
|
||||||
}
|
->success()
|
||||||
Notification::make()->success()->title(trans('admin/server.notifications.server_unsuspended'))->send();
|
->title(trans('admin/server.notifications.server_unsuspended'))
|
||||||
|
->send();
|
||||||
|
|
||||||
$this->refreshFormData(['status', 'docker']);
|
$this->refreshFormData(['status', 'docker']);
|
||||||
|
} catch (Exception) {
|
||||||
|
Notification::make()
|
||||||
|
->warning()
|
||||||
|
->title(trans('admin/server.notifications.server_suspension'))
|
||||||
|
->body(trans('admin/server.error_connecting', ['node' => $server->node->name]))
|
||||||
|
->send();
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
])->fullWidth(),
|
])->fullWidth(),
|
||||||
ToggleButtons::make('')
|
ToggleButtons::make('')
|
||||||
@ -860,7 +914,7 @@ class EditServer extends EditRecord
|
|||||||
Grid::make()
|
Grid::make()
|
||||||
->columnSpan(3)
|
->columnSpan(3)
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\Actions::make([
|
FormActions::make([
|
||||||
Action::make('transfer')
|
Action::make('transfer')
|
||||||
->label(trans('admin/server.transfer'))
|
->label(trans('admin/server.transfer'))
|
||||||
->disabled(fn (Server $server) => Node::count() <= 1 || $server->isInConflictState())
|
->disabled(fn (Server $server) => Node::count() <= 1 || $server->isInConflictState())
|
||||||
@ -914,7 +968,7 @@ class EditServer extends EditRecord
|
|||||||
Grid::make()
|
Grid::make()
|
||||||
->columnSpan(3)
|
->columnSpan(3)
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\Actions::make([
|
FormActions::make([
|
||||||
Action::make('reinstall')
|
Action::make('reinstall')
|
||||||
->label(trans('admin/server.reinstall'))
|
->label(trans('admin/server.reinstall'))
|
||||||
->color('danger')
|
->color('danger')
|
||||||
@ -922,7 +976,24 @@ class EditServer extends EditRecord
|
|||||||
->modalHeading(trans('admin/server.reinstall_modal_heading'))
|
->modalHeading(trans('admin/server.reinstall_modal_heading'))
|
||||||
->modalDescription(trans('admin/server.reinstall_modal_description'))
|
->modalDescription(trans('admin/server.reinstall_modal_description'))
|
||||||
->disabled(fn (Server $server) => $server->isSuspended())
|
->disabled(fn (Server $server) => $server->isSuspended())
|
||||||
->action(fn (ReinstallServerService $service, Server $server) => $service->handle($server)),
|
->action(function (ReinstallServerService $service, Server $server) {
|
||||||
|
try {
|
||||||
|
$service->handle($server);
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title(trans('admin/server.notifications.reinstall_started'))
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
$this->refreshFormData(['status', 'docker']);
|
||||||
|
} catch (Exception) {
|
||||||
|
Notification::make()
|
||||||
|
->title(trans('admin/server.notifications.reinstall_failed'))
|
||||||
|
->body(trans('admin/server.error_connecting', ['node' => $server->node->name]))
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
}
|
||||||
|
}),
|
||||||
])->fullWidth(),
|
])->fullWidth(),
|
||||||
ToggleButtons::make('')
|
ToggleButtons::make('')
|
||||||
->hint(trans('admin/server.reinstall_help')),
|
->hint(trans('admin/server.reinstall_help')),
|
||||||
|
@ -69,6 +69,8 @@ return [
|
|||||||
'short_uuid' => 'Short UUID',
|
'short_uuid' => 'Short UUID',
|
||||||
'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.',
|
||||||
|
'toggle_install_failed_header' => 'Server is in failed state',
|
||||||
|
'toggle_install_failed_desc' => 'Do you want to reinstall the server to fix this?',
|
||||||
'transfer' => 'Transfer',
|
'transfer' => 'Transfer',
|
||||||
'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!',
|
'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',
|
||||||
@ -122,5 +124,9 @@ return [
|
|||||||
'already_exists_body' => ':i is already with an allocation',
|
'already_exists_body' => ':i is already with an allocation',
|
||||||
'error_connecting' => 'Error connecting to :node',
|
'error_connecting' => 'Error connecting to :node',
|
||||||
'error_connecting_description' => 'The configuration could not be automatically synced on Wings, you will need to manually restart the server.',
|
'error_connecting_description' => 'The configuration could not be automatically synced on Wings, you will need to manually restart the server.',
|
||||||
|
'install_toggled' => 'Install status toggled',
|
||||||
|
'install_toggle_failed' => 'Could not toggle install status',
|
||||||
|
'reinstall_started' => 'Reinstall started',
|
||||||
|
'reinstall_failed' => 'Could not start reinstall',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user