From 26ccc4afb4e5a92ed25dd64b340f9f03c9968b7e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 5 Feb 2024 15:13:39 +0100 Subject: [PATCH] Refactor server validation and installation logic --- app/Livewire/Server/ValidateAndInstall.php | 21 +++-- .../server/validate-and-install.blade.php | 82 +++++++++++++------ 2 files changed, 70 insertions(+), 33 deletions(-) diff --git a/app/Livewire/Server/ValidateAndInstall.php b/app/Livewire/Server/ValidateAndInstall.php index c93f51735..e5d2a4b39 100644 --- a/app/Livewire/Server/ValidateAndInstall.php +++ b/app/Livewire/Server/ValidateAndInstall.php @@ -17,16 +17,22 @@ class ValidateAndInstall extends Component public $docker_version = null; public $error = null; - protected $listeners = ['validateServer', 'validateDockerEngine']; + protected $listeners = ['validateServer' => 'init', 'validateDockerEngine', 'validateServerNow' => 'validateServer']; - public function validateServer(bool $install = true) + public function init(bool $install = true) { $this->install = $install; $this->uptime = null; $this->supported_os_type = null; $this->docker_installed = null; $this->docker_version = null; + $this->error = null; + $this->number_of_tries = 0; + $this->dispatch('validateServerNow'); + } + public function validateServer() + { try { $this->validateConnection(); $this->validateOS(); @@ -46,7 +52,7 @@ public function validateConnection() { $this->uptime = $this->server->validateConnection(); if (!$this->uptime) { - $this->dispatch('error', 'Server is not reachable.', 'Please validate your configuration and connection.

Check this documentation for further help.'); + $this->error = 'Server is not reachable. Please validate your configuration and connection.

Check this documentation for further help.'; return; } } @@ -54,7 +60,7 @@ public function validateOS() { $this->supported_os_type = $this->server->validateOS(); if (!$this->supported_os_type) { - $this->dispatch('error', 'Server OS type is not supported.', 'Please install Docker manually before continuing: documentation.'); + $this->error = 'Server OS type is not supported. Please install Docker manually before continuing: documentation.'; return; } } @@ -66,16 +72,15 @@ public function validateDockerEngine() ray($this->number_of_tries, $this->max_tries); if ($this->number_of_tries == $this->max_tries) { $this->error = 'Docker Engine could not be installed. Please install Docker manually before continuing: documentation.'; - return; + return; } else { $activity = $this->server->installDocker(); $this->number_of_tries++; $this->dispatch('newActivityMonitor', $activity->id, 'validateDockerEngine'); return; - } } else { - $this->dispatch('error', 'Docker Engine is not installed.', 'Please install Docker manually before continuing: documentation.'); + $this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: documentation.'; return; } } else { @@ -89,7 +94,7 @@ public function validateDockerVersion() $this->dispatch('serverInstalled'); $this->dispatch('success', 'Server validated successfully.'); } else { - $this->dispatch('error', 'Docker Engine version is not 22+.', 'Please install Docker manually before continuing: documentation.'); + $this->error = 'Docker Engine version is not 22+. Please install Docker manually before continuing: documentation.'; return; } } diff --git a/resources/views/livewire/server/validate-and-install.blade.php b/resources/views/livewire/server/validate-and-install.blade.php index 08cefd97d..9eaa33d9b 100644 --- a/resources/views/livewire/server/validate-and-install.blade.php +++ b/resources/views/livewire/server/validate-and-install.blade.php @@ -11,31 +11,63 @@ @else -
+ @if ($error) +
Server is reachable: + +
+ @else +
+ @endif @endif - @isset($supported_os_type) -
Supported OS type: - - - - -
- @endisset - @if ($docker_installed) -
Docker is installed: - - - - -
+ @if ($uptime) + @if ($supported_os_type) +
Supported OS type: + + + + +
+ @else + @if ($error) +
Server is reachable: + +
+ @else +
+ @endif + @endif + @endif + @if ($uptime && $supported_os_type) + @if ($docker_installed) +
Docker is installed: + + + + +
+ @else + @if ($error) +
Docker is installed: + +
+ @else +
+ @endif + @endif @endif @isset($docker_version)
Minimum Docker version installed:
@endisset - + @isset($error)
{!! $error !!}
@endisset