From d396f649dfc607ff245135e3cf0e8ddb0be352d5 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 27 Nov 2023 09:39:43 +0100 Subject: [PATCH] fix: show defined resources in server tab, so you will know what you need to delete before you can delete the server. --- app/Http/Controllers/ProjectController.php | 2 +- app/Http/Livewire/Project/New/DockerCompose.php | 2 +- .../Livewire/Project/Service/Application.php | 2 +- app/Models/Application.php | 9 ++++++++- app/Models/Server.php | 6 ++++++ app/Models/Service.php | 8 ++++++++ app/Models/StandaloneMariadb.php | 8 ++++++++ app/Models/StandaloneMongodb.php | 8 ++++++++ app/Models/StandaloneMysql.php | 8 ++++++++ app/Models/StandalonePostgresql.php | 9 ++++++++- app/Models/StandaloneRedis.php | 9 ++++++++- .../views/components/services/navbar.blade.php | 4 ++-- .../livewire/project/service/show.blade.php | 4 ++-- resources/views/livewire/server/delete.blade.php | 16 ++++++++++++++-- resources/views/project/resources.blade.php | 2 +- routes/web.php | 2 +- 16 files changed, 85 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 73cf55fcd..58d0dbb6a 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -137,7 +137,7 @@ class ProjectController extends Controller } $service->parse(isNew: true); - return redirect()->route('project.service', [ + return redirect()->route('project.service.configuration', [ 'service_uuid' => $service->uuid, 'environment_name' => $environment->name, 'project_uuid' => $project->uuid, diff --git a/app/Http/Livewire/Project/New/DockerCompose.php b/app/Http/Livewire/Project/New/DockerCompose.php index 81c487ccf..cd0d86c08 100644 --- a/app/Http/Livewire/Project/New/DockerCompose.php +++ b/app/Http/Livewire/Project/New/DockerCompose.php @@ -129,7 +129,7 @@ class DockerCompose extends Component $service->parse(isNew: true); - return redirect()->route('project.service', [ + return redirect()->route('project.service.configuration', [ 'service_uuid' => $service->uuid, 'environment_name' => $environment->name, 'project_uuid' => $project->uuid, diff --git a/app/Http/Livewire/Project/Service/Application.php b/app/Http/Livewire/Project/Service/Application.php index 14fd3d5ab..622b1e0e2 100644 --- a/app/Http/Livewire/Project/Service/Application.php +++ b/app/Http/Livewire/Project/Service/Application.php @@ -41,7 +41,7 @@ class Application extends Component try { $this->application->delete(); $this->emit('success', 'Application deleted successfully.'); - return redirect()->route('project.service', $this->parameters); + return redirect()->route('project.service.configuration', $this->parameters); } catch (\Throwable $e) { return handleError($e, $this); } diff --git a/app/Models/Application.php b/app/Models/Application.php index ee7ccf60b..20f61ed39 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -47,7 +47,14 @@ class Application extends BaseModel $application->environment_variables_preview()->delete(); }); } - + public function link() + { + return route('project.application.configuration', [ + 'project_uuid' => $this->environment->project->uuid, + 'environment_name' => $this->environment->name, + 'application_uuid' => $this->uuid + ]); + } public function settings() { return $this->hasOne(ApplicationSetting::class); diff --git a/app/Models/Server.php b/app/Models/Server.php index 8df4c1e3f..5aa571452 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -194,6 +194,12 @@ class Server extends BaseModel { return instant_remote_process(["df /| tail -1 | awk '{ print $5}' | sed 's/%//g'"], $this, false); } + public function definedResources() { + $applications = $this->applications(); + $databases = $this->databases(); + $services = $this->services(); + return $applications->concat($databases)->concat($services->get()); + } public function hasDefinedResources() { $applications = $this->applications()->count() > 0; diff --git a/app/Models/Service.php b/app/Models/Service.php index a05c989b8..345e4db92 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -361,6 +361,14 @@ class Service extends BaseModel } } } + public function link() + { + return route('project.service.configuration', [ + 'project_uuid' => $this->environment->project->uuid, + 'environment_name' => $this->environment->name, + 'service_uuid' => $this->uuid + ]); + } public function documentation() { $services = getServiceTemplates(); diff --git a/app/Models/StandaloneMariadb.php b/app/Models/StandaloneMariadb.php index cb9fa9aa2..ca7221d7c 100644 --- a/app/Models/StandaloneMariadb.php +++ b/app/Models/StandaloneMariadb.php @@ -41,6 +41,14 @@ class StandaloneMariadb extends BaseModel $database->environment_variables()->delete(); }); } + public function link() + { + return route('project.database.configuration', [ + 'project_uuid' => $this->environment->project->uuid, + 'environment_name' => $this->environment->name, + 'database_uuid' => $this->uuid + ]); + } public function isLogDrainEnabled() { return data_get($this, 'is_log_drain_enabled', false); diff --git a/app/Models/StandaloneMongodb.php b/app/Models/StandaloneMongodb.php index 3a5b7a52a..598719acf 100644 --- a/app/Models/StandaloneMongodb.php +++ b/app/Models/StandaloneMongodb.php @@ -48,6 +48,14 @@ class StandaloneMongodb extends BaseModel { return data_get($this, 'is_log_drain_enabled', false); } + public function link() + { + return route('project.database.configuration', [ + 'project_uuid' => $this->environment->project->uuid, + 'environment_name' => $this->environment->name, + 'database_uuid' => $this->uuid + ]); + } public function mongoInitdbRootPassword(): Attribute { return Attribute::make( diff --git a/app/Models/StandaloneMysql.php b/app/Models/StandaloneMysql.php index 6de57cb73..4cbee006e 100644 --- a/app/Models/StandaloneMysql.php +++ b/app/Models/StandaloneMysql.php @@ -41,6 +41,14 @@ class StandaloneMysql extends BaseModel $database->environment_variables()->delete(); }); } + public function link() + { + return route('project.database.configuration', [ + 'project_uuid' => $this->environment->project->uuid, + 'environment_name' => $this->environment->name, + 'database_uuid' => $this->uuid + ]); + } public function type(): string { return 'standalone-mysql'; diff --git a/app/Models/StandalonePostgresql.php b/app/Models/StandalonePostgresql.php index 1bef3b6c9..0056f9b51 100644 --- a/app/Models/StandalonePostgresql.php +++ b/app/Models/StandalonePostgresql.php @@ -41,7 +41,14 @@ class StandalonePostgresql extends BaseModel $database->environment_variables()->delete(); }); } - + public function link() + { + return route('project.database.configuration', [ + 'project_uuid' => $this->environment->project->uuid, + 'environment_name' => $this->environment->name, + 'database_uuid' => $this->uuid + ]); + } public function isLogDrainEnabled() { return data_get($this, 'is_log_drain_enabled', false); diff --git a/app/Models/StandaloneRedis.php b/app/Models/StandaloneRedis.php index fe1281c22..b2038d8af 100644 --- a/app/Models/StandaloneRedis.php +++ b/app/Models/StandaloneRedis.php @@ -36,7 +36,14 @@ class StandaloneRedis extends BaseModel $database->environment_variables()->delete(); }); } - + public function link() + { + return route('project.database.configuration', [ + 'project_uuid' => $this->environment->project->uuid, + 'environment_name' => $this->environment->name, + 'database_uuid' => $this->uuid + ]); + } public function isLogDrainEnabled() { return data_get($this, 'is_log_drain_enabled', false); diff --git a/resources/views/components/services/navbar.blade.php b/resources/views/components/services/navbar.blade.php index 6c9af5f07..83facccec 100644 --- a/resources/views/components/services/navbar.blade.php +++ b/resources/views/components/services/navbar.blade.php @@ -1,6 +1,6 @@