From 182087cf1bd611e505f37791272e420a59a21ecf Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 18 Sep 2024 21:18:47 +0200 Subject: [PATCH 1/2] a few changes here and there --- app/Actions/Database/StopDatabase.php | 7 +- app/Jobs/DeleteResourceJob.php | 9 +- app/Livewire/Project/Application/Heading.php | 2 +- app/Livewire/Project/Service/Navbar.php | 6 +- app/Livewire/Project/Shared/Danger.php | 35 +- .../components/modal-confirmation.blade.php | 319 ++++++++++-------- .../livewire/project/shared/danger.blade.php | 22 +- 7 files changed, 218 insertions(+), 182 deletions(-) diff --git a/app/Actions/Database/StopDatabase.php b/app/Actions/Database/StopDatabase.php index f90851c93..0f074bea9 100644 --- a/app/Actions/Database/StopDatabase.php +++ b/app/Actions/Database/StopDatabase.php @@ -2,6 +2,7 @@ namespace App\Actions\Database; +use App\Actions\Server\CleanupDocker; use App\Models\StandaloneClickhouse; use App\Models\StandaloneDragonfly; use App\Models\StandaloneKeydb; @@ -12,7 +13,6 @@ use App\Models\StandalonePostgresql; use App\Models\StandaloneRedis; use Illuminate\Support\Facades\Process; use Lorisleiva\Actions\Concerns\AsAction; -use App\Actions\Server\CleanupDocker; class StopDatabase { @@ -21,13 +21,12 @@ class StopDatabase public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, bool $isDeleteOperation = false, bool $dockerCleanup = true) { $server = $database->destination->server; - if (!$server->isFunctional()) { + if (! $server->isFunctional()) { return 'Server is not functional'; } $this->stopContainer($database, $database->uuid, 300); - if (!$isDeleteOperation) { - $this->deleteConnectedNetworks($database->uuid, $server); //Probably not needed as DBs do not have a network normally + if (! $isDeleteOperation) { if ($dockerCleanup) { CleanupDocker::run($server, true); } diff --git a/app/Jobs/DeleteResourceJob.php b/app/Jobs/DeleteResourceJob.php index 8f7dd806a..37300593e 100644 --- a/app/Jobs/DeleteResourceJob.php +++ b/app/Jobs/DeleteResourceJob.php @@ -4,9 +4,9 @@ namespace App\Jobs; use App\Actions\Application\StopApplication; use App\Actions\Database\StopDatabase; +use App\Actions\Server\CleanupDocker; use App\Actions\Service\DeleteService; use App\Actions\Service\StopService; -use App\Actions\Server\CleanupDocker; use App\Models\Application; use App\Models\Service; use App\Models\StandaloneClickhouse; @@ -35,8 +35,7 @@ class DeleteResourceJob implements ShouldBeEncrypted, ShouldQueue public bool $deleteVolumes, public bool $dockerCleanup, public bool $deleteConnectedNetworks - ) { - } + ) {} public function handle() { @@ -84,11 +83,11 @@ class DeleteResourceJob implements ShouldBeEncrypted, ShouldQueue CleanupDocker::run($server, true); } - if ($this->deleteConnectedNetworks) { + if ($this->deleteConnectedNetworks && ! $isDatabase) { $this->resource?->delete_connected_networks($this->resource->uuid); } } catch (\Throwable $e) { - send_internal_notification('ContainerStoppingJob failed with: ' . $e->getMessage()); + send_internal_notification('ContainerStoppingJob failed with: '.$e->getMessage()); throw $e; } finally { $this->resource->forceDelete(); diff --git a/app/Livewire/Project/Application/Heading.php b/app/Livewire/Project/Application/Heading.php index 4677ff7a2..f84b49c3f 100644 --- a/app/Livewire/Project/Application/Heading.php +++ b/app/Livewire/Project/Application/Heading.php @@ -143,7 +143,7 @@ class Heading extends Component return view('livewire.project.application.heading', [ 'checkboxes' => [ ['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images (the next deployment will take longer as the images have to be pulled again)'], - ] + ], ]); } } diff --git a/app/Livewire/Project/Service/Navbar.php b/app/Livewire/Project/Service/Navbar.php index 51f38d2db..2e3002852 100644 --- a/app/Livewire/Project/Service/Navbar.php +++ b/app/Livewire/Project/Service/Navbar.php @@ -21,6 +21,7 @@ class Navbar extends Component public $isDeploymentProgress = false; public $docker_cleanup = true; + public $title = 'Configuration'; public function mount() @@ -119,9 +120,8 @@ class Navbar extends Component { return view('livewire.project.service.navbar', [ 'checkboxes' => [ - ['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images (the next deployment will take longer as the images have to be pulled again)'], - ] + ['id' => 'docker_cleanup', 'label' => 'Cleanup docker build cache and unused images (next deployment could take longer).'], + ], ]); } - } diff --git a/app/Livewire/Project/Shared/Danger.php b/app/Livewire/Project/Shared/Danger.php index 609d61698..f437b910e 100644 --- a/app/Livewire/Project/Shared/Danger.php +++ b/app/Livewire/Project/Shared/Danger.php @@ -4,24 +4,33 @@ namespace App\Livewire\Project\Shared; use App\Jobs\DeleteResourceJob; use App\Models\Service; -use App\Models\ServiceDatabase; use App\Models\ServiceApplication; +use App\Models\ServiceDatabase; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Hash; use Livewire\Component; use Visus\Cuid2\Cuid2; -use Illuminate\Support\Facades\Hash; -use Illuminate\Support\Facades\Auth; class Danger extends Component { public $resource; + public $resourceName; + public $projectUuid; + public $environmentName; + public bool $delete_configurations = true; + public bool $delete_volumes = true; + public bool $docker_cleanup = true; + public bool $delete_connected_networks = true; + public ?string $modalId = null; + public string $resourceDomain = ''; public function mount() @@ -42,11 +51,13 @@ class Danger extends Component if ($this->resource === null) { $this->resourceName = 'Unknown Resource'; + return; } - if (!method_exists($this->resource, 'type')) { + if (! method_exists($this->resource, 'type')) { $this->resourceName = 'Unknown Resource'; + return; } @@ -80,13 +91,15 @@ class Danger extends Component public function delete($password) { - if (!Hash::check($password, Auth::user()->password)) { + if (! Hash::check($password, Auth::user()->password)) { $this->addError('password', 'The provided password is incorrect.'); + return; } - if (!$this->resource) { + if (! $this->resource) { $this->addError('resource', 'Resource not found.'); + return; } @@ -113,14 +126,14 @@ class Danger extends Component { return view('livewire.project.shared.danger', [ 'checkboxes' => [ - ['id' => 'delete_volumes', 'label' => 'All associated volumes with this resource will be permanently deleted'], - ['id' => 'delete_connected_networks', 'label' => 'All connected networks with this resource will be permanently deleted (predefined networks will not be deleted)'], - ['id' => 'delete_configurations', 'label' => 'All configuration files will be permanently deleted form the server'], - ['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images'], + ['id' => 'delete_volumes', 'label' => 'All associated volumes with this resource will be permanently deleted.'], + ['id' => 'delete_connected_networks', 'label' => 'All connected networks with this resource will be permanently deleted (except the predefined networks).'], + ['id' => 'delete_configurations', 'label' => 'All configuration files will be permanently deleted form the server.'], + ['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images.'], // ['id' => 'delete_associated_backups_locally', 'label' => 'All backups associated with this Ressource will be permanently deleted from local storage.'], // ['id' => 'delete_associated_backups_s3', 'label' => 'All backups associated with this Ressource will be permanently deleted from the selected S3 Storage.'], // ['id' => 'delete_associated_backups_sftp', 'label' => 'All backups associated with this Ressource will be permanently deleted from the selected SFTP Storage.'] - ] + ], ]); } } diff --git a/resources/views/components/modal-confirmation.blade.php b/resources/views/components/modal-confirmation.blade.php index e31284e7c..249820e9a 100644 --- a/resources/views/components/modal-confirmation.blade.php +++ b/resources/views/components/modal-confirmation.blade.php @@ -1,25 +1,25 @@ @props([ -'title' => 'Are you sure?', -'isErrorButton' => false, -'buttonTitle' => 'Confirm Action', -'buttonFullWidth' => false, -'customButton' => null, -'disabled' => false, -'submitAction' => 'delete', -'content' => null, -'checkboxes' => [], -'actions' => [], -'confirmWithText' => true, -'confirmationText' => 'Confirm Deletion', -'confirmationLabel' => 'Please confirm the execution of the actions by entering the Name below', -'shortConfirmationLabel' => 'Name', -'confirmWithPassword' => true, -'step1ButtonText' => 'Continue Deletion', -'step2ButtonText' => 'Delete Permanently', -'step3ButtonText' => 'Confirm Permanent Deletion', -'dispatchEvent' => false, -'dispatchEventType' => 'success', -'dispatchEventMessage' => '', + 'title' => 'Are you sure?', + 'isErrorButton' => false, + 'buttonTitle' => 'Confirm Action', + 'buttonFullWidth' => false, + 'customButton' => null, + 'disabled' => false, + 'submitAction' => 'delete', + 'content' => null, + 'checkboxes' => [], + 'actions' => [], + 'confirmWithText' => true, + 'confirmationText' => 'Confirm Deletion', + 'confirmationLabel' => 'Please confirm the execution of the actions by entering the NAME below', + 'shortConfirmationLabel' => 'Name', + 'confirmWithPassword' => true, + 'step1ButtonText' => 'Continue', + 'step2ButtonText' => 'Confirm', + 'step3ButtonText' => 'Delete Permanently', + 'dispatchEvent' => false, + 'dispatchEventType' => 'success', + 'dispatchEventMessage' => '', ])
+}" @keydown.escape.window="modalOpen = false; resetModal()" :class="{ 'z-40': modalOpen }" + class="relative w-auto h-auto"> @if ($customButton) - @if ($buttonFullWidth) - - {{ $customButton }} - + @if ($buttonFullWidth) + + {{ $customButton }} + + @else + + {{ $customButton }} + + @endif @else - - {{ $customButton }} - - @endif - @else - @if ($content) -
- {{ $content }} -
- @else - @if ($disabled) - @if ($buttonFullWidth) - - {{ $buttonTitle }} - - @else - - {{ $buttonTitle }} - - @endif - @elseif ($isErrorButton) - @if ($buttonFullWidth) - - {{ $buttonTitle }} - - @else - - {{ $buttonTitle }} - - @endif - @else - @if ($buttonFullWidth) - - {{ $buttonTitle }} - - @else - - {{ $buttonTitle }} - - @endif - @endif - @endif + @if ($content) +
+ {{ $content }} +
+ @else + @if ($disabled) + @if ($buttonFullWidth) + + {{ $buttonTitle }} + + @else + + {{ $buttonTitle }} + + @endif + @elseif ($isErrorButton) + @if ($buttonFullWidth) + + {{ $buttonTitle }} + + @else + + {{ $buttonTitle }} + + @endif + @else + @if ($buttonFullWidth) + + {{ $buttonTitle }} + + @else + + {{ $buttonTitle }} + + @endif + @endif + @endif @endif