diff --git a/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php index 31277fc4f..30bd28221 100644 --- a/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php @@ -2,7 +2,7 @@ namespace App\Filament\Admin\Resources\ServerResource\Pages; -use App\Enums\ServerState; +use AbdelhamidErrahmouni\FilamentMonacoEditor\MonacoEditor; use App\Enums\SuspendAction; use App\Filament\Admin\Resources\ServerResource; use App\Filament\Admin\Resources\ServerResource\RelationManagers\AllocationsRelationManager; @@ -51,6 +51,7 @@ use Filament\Forms\Get; use Filament\Forms\Set; use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; +use Filament\Support\Enums\Alignment; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Client\ConnectionException; use Illuminate\Support\Arr; @@ -135,7 +136,39 @@ class EditServer extends EditRecord 'sm' => 1, 'md' => 1, 'lg' => 1, - ]), + ]) + ->hintAction( + Action::make('view_install_log') + ->label(trans('admin/server.view_install_log')) + //->visible(fn (Server $server) => $server->isFailedInstall()) + ->modalHeading('') + ->modalSubmitAction(false) + ->modalFooterActionsAlignment(Alignment::Right) + ->modalCancelActionLabel(trans('filament::components/modal.actions.close.label')) + ->form([ + MonacoEditor::make('logs') + ->hiddenLabel() + ->placeholderText(trans('admin/server.no_log')) + ->formatStateUsing(function (Server $server, DaemonServerRepository $serverRepository) { + try { + return $serverRepository->setServer($server)->getInstallLogs(); + } catch (ConnectionException) { + Notification::make() + ->title(trans('admin/server.notifications.error_connecting', ['node' => $server->node->name])) + ->body(trans('admin/server.notifications.log_failed')) + ->color('warning') + ->warning() + ->send(); + } catch (Exception) { + return ''; + } + + return ''; + }) + ->language('shell') + ->view('filament.plugins.monaco-editor-logs'), + ]) + ), Textarea::make('description') ->label(trans('admin/server.description')) @@ -800,12 +833,12 @@ class EditServer extends EditRecord Action::make('toggleInstall') ->label(trans('admin/server.toggle_install')) ->disabled(fn (Server $server) => $server->isSuspended()) - ->modal(fn (Server $server) => $server->status === ServerState::InstallFailed) + ->modal(fn (Server $server) => $server->isFailedInstall()) ->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) { + if ($server->isFailedInstall()) { try { $reinstallService->handle($server); diff --git a/app/Models/Node.php b/app/Models/Node.php index 7c281047f..7c7c62d58 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Http; diff --git a/app/Models/Server.php b/app/Models/Server.php index a3fe9a398..0115b1bbf 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -231,7 +231,12 @@ class Server extends Model implements Validatable public function isInstalled(): bool { - return $this->status !== ServerState::Installing && $this->status !== ServerState::InstallFailed; + return $this->status !== ServerState::Installing && !$this->isFailedInstall(); + } + + public function isFailedInstall(): bool + { + return $this->status === ServerState::InstallFailed || $this->status === ServerState::ReinstallFailed; } public function isSuspended(): bool diff --git a/app/Repositories/Daemon/DaemonServerRepository.php b/app/Repositories/Daemon/DaemonServerRepository.php index 673673b98..551dc16fe 100644 --- a/app/Repositories/Daemon/DaemonServerRepository.php +++ b/app/Repositories/Daemon/DaemonServerRepository.php @@ -141,4 +141,12 @@ class DaemonServerRepository extends DaemonRepository 'jtis' => [md5($id . $this->server->uuid)], ]); } + + public function getInstallLogs(): string + { + return $this->getHttpClient() + ->get("/api/servers/{$this->server->uuid}/install-logs") + ->throw() + ->json('data'); + } } diff --git a/app/Services/Servers/ToggleInstallService.php b/app/Services/Servers/ToggleInstallService.php index 01ee6de41..770db8443 100644 --- a/app/Services/Servers/ToggleInstallService.php +++ b/app/Services/Servers/ToggleInstallService.php @@ -9,7 +9,7 @@ class ToggleInstallService { public function handle(Server $server): void { - if ($server->status === ServerState::InstallFailed) { + if ($server->isFailedInstall()) { abort(500, trans('exceptions.server.marked_as_failed')); } diff --git a/lang/en/admin/server.php b/lang/en/admin/server.php index 97340b67a..04f91aaad 100644 --- a/lang/en/admin/server.php +++ b/lang/en/admin/server.php @@ -64,6 +64,7 @@ return [ 'reinstall_modal_heading' => 'Are you sure you want to reinstall this server?', 'reinstall_modal_description' => '!! This can result in unrecoverable data loss !!', 'server_status' => 'Server Status', + 'view_install_log' => 'View install log', 'uuid' => 'UUID', 'node' => 'Node', 'short_uuid' => 'Short UUID', @@ -100,6 +101,7 @@ return [ 'create_allocation' => 'Create Allocation', 'add_allocation' => 'Add Allocation', 'view' => 'View', + 'no_log' => 'No Log Available', 'tabs' => [ 'information' => 'Information', 'egg_configuration' => 'Egg Configuration', @@ -129,5 +131,6 @@ return [ 'install_toggle_failed' => 'Could not toggle install status', 'reinstall_started' => 'Reinstall started', 'reinstall_failed' => 'Could not start reinstall', + 'log_failed' => 'Could not connect to Wings to retrieve server install log.', ], ]; diff --git a/resources/views/filament/plugins/monaco-editor-logs.blade.php b/resources/views/filament/plugins/monaco-editor-logs.blade.php new file mode 100644 index 000000000..cb5766359 --- /dev/null +++ b/resources/views/filament/plugins/monaco-editor-logs.blade.php @@ -0,0 +1,184 @@ +@script + +@endscript + + + + + + @if($getShowFullScreenToggle()) + + + + + + + + + + + + + + + + + + + + + + + + + @endif + + + + + + + + + +