fix: show defined resources in server tab, so you will know what you need to delete before you can delete the server.

This commit is contained in:
Andras Bacsai 2023-11-27 09:39:43 +01:00
parent ec21155c9e
commit d396f649df
16 changed files with 85 additions and 14 deletions

View File

@ -137,7 +137,7 @@ public function new()
} }
$service->parse(isNew: true); $service->parse(isNew: true);
return redirect()->route('project.service', [ return redirect()->route('project.service.configuration', [
'service_uuid' => $service->uuid, 'service_uuid' => $service->uuid,
'environment_name' => $environment->name, 'environment_name' => $environment->name,
'project_uuid' => $project->uuid, 'project_uuid' => $project->uuid,

View File

@ -129,7 +129,7 @@ public function submit()
$service->parse(isNew: true); $service->parse(isNew: true);
return redirect()->route('project.service', [ return redirect()->route('project.service.configuration', [
'service_uuid' => $service->uuid, 'service_uuid' => $service->uuid,
'environment_name' => $environment->name, 'environment_name' => $environment->name,
'project_uuid' => $project->uuid, 'project_uuid' => $project->uuid,

View File

@ -41,7 +41,7 @@ public function delete()
try { try {
$this->application->delete(); $this->application->delete();
$this->emit('success', 'Application deleted successfully.'); $this->emit('success', 'Application deleted successfully.');
return redirect()->route('project.service', $this->parameters); return redirect()->route('project.service.configuration', $this->parameters);
} catch (\Throwable $e) { } catch (\Throwable $e) {
return handleError($e, $this); return handleError($e, $this);
} }

View File

@ -47,7 +47,14 @@ protected static function booted()
$application->environment_variables_preview()->delete(); $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() public function settings()
{ {
return $this->hasOne(ApplicationSetting::class); return $this->hasOne(ApplicationSetting::class);

View File

@ -194,6 +194,12 @@ public function getDiskUsage()
{ {
return instant_remote_process(["df /| tail -1 | awk '{ print $5}' | sed 's/%//g'"], $this, false); 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() public function hasDefinedResources()
{ {
$applications = $this->applications()->count() > 0; $applications = $this->applications()->count() > 0;

View File

@ -361,6 +361,14 @@ public function saveExtraFields($fields)
} }
} }
} }
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() public function documentation()
{ {
$services = getServiceTemplates(); $services = getServiceTemplates();

View File

@ -41,6 +41,14 @@ protected static function booted()
$database->environment_variables()->delete(); $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() public function isLogDrainEnabled()
{ {
return data_get($this, 'is_log_drain_enabled', false); return data_get($this, 'is_log_drain_enabled', false);

View File

@ -48,6 +48,14 @@ public function isLogDrainEnabled()
{ {
return data_get($this, 'is_log_drain_enabled', false); 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 public function mongoInitdbRootPassword(): Attribute
{ {
return Attribute::make( return Attribute::make(

View File

@ -41,6 +41,14 @@ protected static function booted()
$database->environment_variables()->delete(); $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 public function type(): string
{ {
return 'standalone-mysql'; return 'standalone-mysql';

View File

@ -41,7 +41,14 @@ protected static function booted()
$database->environment_variables()->delete(); $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() public function isLogDrainEnabled()
{ {
return data_get($this, 'is_log_drain_enabled', false); return data_get($this, 'is_log_drain_enabled', false);

View File

@ -36,7 +36,14 @@ protected static function booted()
$database->environment_variables()->delete(); $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() public function isLogDrainEnabled()
{ {
return data_get($this, 'is_log_drain_enabled', false); return data_get($this, 'is_log_drain_enabled', false);

View File

@ -1,6 +1,6 @@
<div class="navbar-main"> <div class="navbar-main">
<a class="{{ request()->routeIs('project.service') ? 'text-white' : '' }}" <a class="{{ request()->routeIs('project.service.configuration') ? 'text-white' : '' }}"
href="{{ route('project.service', $parameters) }}"> href="{{ route('project.service.configuration', $parameters) }}">
<button>Configuration</button> <button>Configuration</button>
</a> </a>
<x-services.links /> <x-services.links />

View File

@ -2,8 +2,8 @@
<livewire:project.service.navbar :service="$service" :parameters="$parameters" :query="$query" /> <livewire:project.service.navbar :service="$service" :parameters="$parameters" :query="$query" />
<div class="flex h-full pt-6"> <div class="flex h-full pt-6">
<div class="flex flex-col gap-4 min-w-fit"> <div class="flex flex-col gap-4 min-w-fit">
<a class="{{ request()->routeIs('project.service') ? 'text-white' : '' }}" <a class="{{ request()->routeIs('project.service.configuration') ? 'text-white' : '' }}"
href="{{ route('project.service', [...$parameters, 'service_name' => null]) }}"> href="{{ route('project.service.configuration', [...$parameters, 'service_name' => null]) }}">
<button><- Back</button> <button><- Back</button>
</a> </a>
<a :class="activeTab === 'general' && 'text-white'" <a :class="activeTab === 'general' && 'text-white'"

View File

@ -11,12 +11,24 @@
<div class="pb-4">This will remove this server from Coolify. Beware! There is no coming <div class="pb-4">This will remove this server from Coolify. Beware! There is no coming
back! back!
</div> </div>
@if ($server->hasDefinedResources()) @if ($server->definedResources()->count() > 0)
<div class="text-warning">Please delete all resources before deleting this server.</div> <x-forms.button disabled isError isModal modalId="deleteServer">
Delete
</x-forms.button>
@else @else
<x-forms.button isError isModal modalId="deleteServer"> <x-forms.button isError isModal modalId="deleteServer">
Delete Delete
</x-forms.button> </x-forms.button>
@endif @endif
@forelse ($server->definedResources() as $resource)
@if ($loop->first)
<div class="text-warning">Please delete all resources before deleting this server.</div>
@endif
<div class="flex gap-2">
<div class="w-64">{{ str($resource->type())->headline() }}</div>
<a class="text-white underline" href="{{ $resource->link() }}">{{ $resource->name }}</a>
</div>
@empty
@endforelse
@endif @endif
</div> </div>

View File

@ -79,7 +79,7 @@ class="items-center justify-center box">+ Add New Resource</a>
@endforeach @endforeach
@foreach ($environment->services->sortBy('name') as $service) @foreach ($environment->services->sortBy('name') as $service)
<a class="relative box group" <a class="relative box group"
href="{{ route('project.service', [$project->uuid, $environment->name, $service->uuid]) }}"> href="{{ route('project.service.configuration', [$project->uuid, $environment->name, $service->uuid]) }}">
<div class="flex flex-col mx-6"> <div class="flex flex-col mx-6">
<div class="font-bold text-white">{{ $service->name }}</div> <div class="font-bold text-white">{{ $service->name }}</div>
<div class="description">{{ $service->description }}</div> <div class="description">{{ $service->description }}</div>

View File

@ -120,7 +120,7 @@
// Services // Services
Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}', ServiceIndex::class)->name('project.service'); Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}', ServiceIndex::class)->name('project.service.configuration');
Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/{service_name}', ServiceShow::class)->name('project.service.show'); Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/{service_name}', ServiceShow::class)->name('project.service.show');
Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/{service_name}/logs', Logs::class)->name('project.service.logs'); Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/{service_name}/logs', Logs::class)->name('project.service.logs');
}); });