From 35b08453e1e8393eafdff881f4ff4ad1946ab6ee Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 20 May 2025 10:30:31 +0200 Subject: [PATCH] refactor(service): consolidate configuration change dispatch logic and remove unused navbar component --- app/Livewire/Project/Service/Heading.php | 4 +- app/Livewire/Project/Service/Navbar.php | 154 --------------- .../livewire/project/service/navbar.blade.php | 182 ------------------ .../livewire/project/shared/logs.blade.php | 2 +- 4 files changed, 2 insertions(+), 340 deletions(-) delete mode 100644 app/Livewire/Project/Service/Navbar.php delete mode 100644 resources/views/livewire/project/service/navbar.blade.php diff --git a/app/Livewire/Project/Service/Heading.php b/app/Livewire/Project/Service/Heading.php index f88f62e9c..0587a1ebc 100644 --- a/app/Livewire/Project/Service/Heading.php +++ b/app/Livewire/Project/Service/Heading.php @@ -64,10 +64,8 @@ class Heading extends Component }); if (is_null($this->service->config_hash) || $this->service->isConfigurationChanged()) { $this->service->isConfigurationChanged(true); - $this->dispatch('configurationChanged'); - } else { - $this->dispatch('configurationChanged'); } + $this->dispatch('configurationChanged'); } catch (\Exception $e) { return handleError($e, $this); } finally { diff --git a/app/Livewire/Project/Service/Navbar.php b/app/Livewire/Project/Service/Navbar.php deleted file mode 100644 index 5da425cbd..000000000 --- a/app/Livewire/Project/Service/Navbar.php +++ /dev/null @@ -1,154 +0,0 @@ -service->status)->contains('running') && is_null($this->service->config_hash)) { - $this->service->isConfigurationChanged(true); - $this->dispatch('configurationChanged'); - } - } - - public function getListeners() - { - $userId = Auth::id(); - - return [ - "echo-private:user.{$userId},ServiceStatusChanged" => 'serviceStarted', - 'envsUpdated' => '$refresh', - 'refreshStatus' => '$refresh', - ]; - } - - public function serviceStarted() - { - // $this->dispatch('success', 'Service status changed.'); - if (is_null($this->service->config_hash) || $this->service->isConfigurationChanged()) { - $this->service->isConfigurationChanged(true); - $this->dispatch('configurationChanged'); - } else { - $this->dispatch('configurationChanged'); - } - } - - public function check_status_without_notification() - { - $this->dispatch('check_status'); - } - - public function check_status() - { - $this->dispatch('check_status'); - $this->dispatch('success', 'Service status updated.'); - } - - public function checkDeployments() - { - try { - $activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first(); - $status = data_get($activity, 'properties.status'); - if ($status === ProcessStatus::QUEUED->value || $status === ProcessStatus::IN_PROGRESS->value) { - $this->isDeploymentProgress = true; - } else { - $this->isDeploymentProgress = false; - } - } catch (\Throwable) { - $this->isDeploymentProgress = false; - } - - return $this->isDeploymentProgress; - } - - public function start() - { - $activity = StartService::run($this->service, pullLatestImages: true); - $this->dispatch('activityMonitor', $activity->id); - } - - public function forceDeploy() - { - try { - $activities = Activity::where('properties->type_uuid', $this->service->uuid)->where('properties->status', ProcessStatus::IN_PROGRESS->value)->orWhere('properties->status', ProcessStatus::QUEUED->value)->get(); - foreach ($activities as $activity) { - $activity->properties->status = ProcessStatus::ERROR->value; - $activity->save(); - } - $activity = StartService::run($this->service, pullLatestImages: true, stopBeforeStart: true); - $this->dispatch('activityMonitor', $activity->id); - } catch (\Exception $e) { - $this->dispatch('error', $e->getMessage()); - } - } - - public function stop($cleanupContainers = false) - { - try { - StopService::run($this->service, false, $this->docker_cleanup); - ServiceStatusChanged::dispatch(); - if ($cleanupContainers) { - $this->dispatch('success', 'Containers cleaned up.'); - } else { - $this->dispatch('success', 'Service stopped.'); - } - } catch (\Exception $e) { - $this->dispatch('error', $e->getMessage()); - } - } - - public function restart() - { - $this->checkDeployments(); - if ($this->isDeploymentProgress) { - $this->dispatch('error', 'There is a deployment in progress.'); - - return; - } - $activity = StartService::run($this->service, stopBeforeStart: true); - $this->dispatch('activityMonitor', $activity->id); - } - - public function pullAndRestartEvent() - { - $this->checkDeployments(); - if ($this->isDeploymentProgress) { - $this->dispatch('error', 'There is a deployment in progress.'); - - return; - } - $activity = StartService::run($this->service, pullLatestImages: true, stopBeforeStart: true); - $this->dispatch('activityMonitor', $activity->id); - } - - public function render() - { - return view('livewire.project.service.navbar', [ - 'checkboxes' => [ - ['id' => 'docker_cleanup', 'label' => __('resource.docker_cleanup')], - ], - ]); - } -} diff --git a/resources/views/livewire/project/service/navbar.blade.php b/resources/views/livewire/project/service/navbar.blade.php deleted file mode 100644 index dd2ce4142..000000000 --- a/resources/views/livewire/project/service/navbar.blade.php +++ /dev/null @@ -1,182 +0,0 @@ -