From 770ce2d327306b7037567ddf5c0700800993773c Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Wed, 31 Dec 2025 11:44:08 +0100 Subject: [PATCH] Refactor application general settings view for improved readability and maintainability - Adjusted indentation and formatting for better code clarity. - Simplified conditional statements and removed unnecessary null checks. - Enhanced user interface elements for Docker Compose and Dockerfile configurations. - Improved handling of deployment commands and network settings. - Updated helper texts for better user guidance. --- app/Livewire/Project/Application/General.php | 7 +- app/Models/Application.php | 14 +- .../project/application/general.blade.php | 597 +++++++++--------- 3 files changed, 324 insertions(+), 294 deletions(-) diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index 44bee6f57..dffe1ec67 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -558,8 +558,11 @@ public function loadComposeFile($isInit = false, $showToast = true, ?string $res $this->dispatch('refreshStorages'); $this->dispatch('refreshEnvs'); } catch (\Throwable $e) { - $this->application->docker_compose_location = $this->initialDockerComposeLocation; - $this->application->save(); + // Refresh model to get restored values from Application::loadComposeFile + $this->application->refresh(); + // Sync restored values back to component properties for UI update + + $this->syncData(); return handleError($e, $this); } finally { diff --git a/app/Models/Application.php b/app/Models/Application.php index 5006d0ff8..40e41c2a7 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -1584,6 +1584,11 @@ public function loadComposeFile($isInit = false, ?string $restoreBaseDirectory = try { $composeFileContent = instant_remote_process($commands, $this->destination->server); } catch (\Exception $e) { + // Restore original values on failure only + $this->docker_compose_location = $initialDockerComposeLocation; + $this->base_directory = $initialBaseDirectory; + $this->save(); + if (str($e->getMessage())->contains('No such file')) { throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile

Check if you used the right extension (.yaml or .yml) in the compose file name."); } @@ -1595,9 +1600,7 @@ public function loadComposeFile($isInit = false, ?string $restoreBaseDirectory = } throw new \RuntimeException($e->getMessage()); } finally { - $this->docker_compose_location = $initialDockerComposeLocation; - $this->base_directory = $initialBaseDirectory; - $this->save(); + // Cleanup only - restoration happens in catch block $commands = collect([ "rm -rf /tmp/{$uuid}", ]); @@ -1643,6 +1646,11 @@ public function loadComposeFile($isInit = false, ?string $restoreBaseDirectory = 'initialDockerComposeLocation' => $this->docker_compose_location, ]; } else { + // Restore original values before throwing + $this->docker_compose_location = $initialDockerComposeLocation; + $this->base_directory = $initialBaseDirectory; + $this->save(); + throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile

Check if you used the right extension (.yaml or .yml) in the compose file name."); } } diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php index 254f31ca6..cf9621462 100644 --- a/resources/views/livewire/project/application/general.blade.php +++ b/resources/views/livewire/project/application/general.blade.php @@ -46,10 +46,9 @@ @if ($buildPack === 'dockercompose') @if ( - !is_null($parsedServices) && + !is_null($parsedServices) && count($parsedServices) > 0 && - !$application->settings->is_raw_compose_deployment_enabled - ) + !$application->settings->is_raw_compose_deployment_enabled)

Domains

@foreach (data_get($parsedServices, 'services') as $serviceName => $service) @if (!isDatabaseImage(data_get($service, 'image'))) @@ -80,11 +79,11 @@ buttonTitle="Generate Default Nginx Configuration" buttonFullWidth submitAction="generateNginxConfiguration('{{ $application->settings->is_spa ? 'spa' : 'static' }}')" :actions="[ - 'This will overwrite your current custom Nginx configuration.', - 'The default configuration will be generated based on your application type (' . - ($application->settings->is_spa ? 'SPA' : 'static') . - ').', - ]" /> + 'This will overwrite your current custom Nginx configuration.', + 'The default configuration will be generated based on your application type (' . + ($application->settings->is_spa ? 'SPA' : 'static') . + ').', + ]" /> @endcan @endif
@@ -166,8 +165,9 @@
@if ($application->destination->server->isSwarm()) @if ($application->build_pack !== 'dockerimage') -
Docker Swarm requires the image to be available in a registry. More info here.
+
Docker Swarm requires the image to be available in a registry. More info here.
@endif @endif
@@ -179,19 +179,19 @@ helper="Enter a tag (e.g., 'latest', 'v1.2.3') or SHA256 hash (e.g., 'sha256-59e02939b1bf39f16c93138a28727aec520bb916da021180ae502c61626b3cf0')" x-bind:disabled="!canUpdate" /> @else - + @endif @else @if ( - $application->destination->server->isSwarm() || + $application->destination->server->isSwarm() || $application->additional_servers->count() > 0 || - $application->settings->is_build_server_enabled - ) - + $application->settings->is_build_server_enabled) + - + @endif @@ -236,82 +237,11 @@ @endif
@if ($buildPack === 'dockercompose') -
-
- - -
-
- -
-
The following commands are for advanced use cases. - Only - modify them if you - know what are - you doing.
-
- - -
- @if ($this->dockerComposeCustomBuildCommand) -
- -
- @endif - @if ($this->dockerComposeCustomStartCommand) -
- -
- @endif - @if ($this->application->is_github_based() && !$this->application->is_public_repository()) -
- -
- @endif -
- @else +
- - @if ($buildPack === 'dockerfile' && !$application->dockerfile) - - @endif - - @if ($buildPack === 'dockerfile') - - @endif - @if ($application->could_set_build_commands()) - @if ($application->settings->is_static) - - @else - - @endif - @endif - + }" class="flex gap-2"> + +
+
+ +
+
The following commands are for advanced use cases. + Only + modify them if you + know what are + you doing.
+
+ + +
+ @if ($this->dockerComposeCustomBuildCommand) +
+ +
+ @endif + @if ($this->dockerComposeCustomStartCommand) +
+ +
+ @endif @if ($this->application->is_github_based() && !$this->application->is_public_repository()) -
+
+ placeholder="services/api/**" id="watchPaths" label="Watch Paths" + x-bind:disabled="shouldDisable()" />
@endif - +
+ @else +
+ + @if ($buildPack === 'dockerfile' && !$application->dockerfile) + + @endif - @if ($buildPack !== 'dockercompose') -
- -
+ @if ($buildPack === 'dockerfile') + @endif + @if ($application->could_set_build_commands()) + @if ($application->settings->is_static) + + @else + + @endif + @endif + +
+ @if ($this->application->is_github_based() && !$this->application->is_public_repository()) +
+ +
@endif -
+ + + @if ($buildPack !== 'dockercompose') +
+ +
+ @endif + @endif +
@endif -
- @if ($buildPack === 'dockercompose') -
-
-

Docker Compose

- -
+
+ @if ($buildPack === 'dockercompose') +
+
+

Docker Compose

+ +
@if ($application->settings->is_raw_compose_deployment_enabled) compose_parsing_version >= 3)
-
@endif
-
@@ -405,172 +417,179 @@
+ id="isContainerLabelEscapeEnabled" instantSave + x-bind:disabled="!canUpdate"> {{-- --}}
-
- @endif - @if ($application->dockerfile) - - @endif - @if ($buildPack !== 'dockercompose') -

Network

- @if ($this->detectedPortInfo) - @if ($this->detectedPortInfo['isEmpty']) -
- - - -
- PORT environment variable detected - ({{ $this->detectedPortInfo['port'] }}) -

Your Ports Exposes field is empty. Consider setting it to - {{ $this->detectedPortInfo['port'] }} to ensure the proxy routes traffic - correctly.

-
+
+ @endif + @if ($application->dockerfile) + + @endif + @if ($buildPack !== 'dockercompose') +

Network

+ @if ($this->detectedPortInfo) + @if ($this->detectedPortInfo['isEmpty']) +
+ + + +
+ PORT environment variable detected + ({{ $this->detectedPortInfo['port'] }}) +

Your Ports Exposes field is empty. Consider setting it to + {{ $this->detectedPortInfo['port'] }} to ensure the proxy routes + traffic + correctly. +

- @elseif (!$this->detectedPortInfo['matches']) -
- - - -
- PORT mismatch detected -

Your PORT environment variable is set to - {{ $this->detectedPortInfo['port'] }}, but it's not in your Ports Exposes - configuration. Ensure they match for proper proxy routing.

-
+
+ @elseif (!$this->detectedPortInfo['matches']) +
+ + + +
+ PORT mismatch detected +

Your PORT environment variable is set to + {{ $this->detectedPortInfo['port'] }}, but it's not in your Ports + Exposes + configuration. Ensure they match for proper proxy routing. +

- @else -
- - - -
- PORT environment variable configured -

Your PORT environment variable ({{ $this->detectedPortInfo['port'] }}) matches - your Ports Exposes configuration.

-
+
+ @else +
+ + + +
+ PORT environment variable configured +

Your PORT environment variable + ({{ $this->detectedPortInfo['port'] }}) matches + your Ports Exposes configuration.

- @endif +
@endif -
- @if ($isStatic || $buildPack === 'static') - + @endif +
+ @if ($isStatic || $buildPack === 'static') + + @else + @if ($application->settings->is_container_label_readonly_enabled === false) + @else - @if ($application->settings->is_container_label_readonly_enabled === false) - - @else - - @endif - @endif - @if (!$application->destination->server->isSwarm()) - @endif - @if (!$application->destination->server->isSwarm()) - - @endif -
- -

HTTP Basic Authentication

-
-
- -
- @if ($application->is_http_basic_auth_enabled) -
- - -
- @endif -
- - @if ($application->settings->is_container_label_readonly_enabled) - - @else - @endif + @if (!$application->destination->server->isSwarm()) + + @endif + @if (!$application->destination->server->isSwarm()) + + @endif +
+ +

HTTP Basic Authentication

+
- - +
- @can('update', $application) - + + +
+ @endif +
+ + @if ($application->settings->is_container_label_readonly_enabled) + + @else + + @endif +
+ + +
+ @can('update', $application) + - @endcan - @endif + confirmationLabel="Please confirm the execution of the actions by entering the Application URL below" + shortConfirmationLabel="Application URL" :confirmWithPassword="false" + step2ButtonText="Permanently Reset Labels" /> + @endcan + @endif -

Pre/Post Deployment Commands

-
- - @if ($buildPack === 'dockercompose') - - @endif -
-
- - @if ($buildPack === 'dockercompose') - - @endif -
+

Pre/Post Deployment Commands

+
+ + @if ($buildPack === 'dockercompose') + + @endif
+
+ + @if ($buildPack === 'dockercompose') + + @endif +
+
- + @script - + @endscript - \ No newline at end of file +