mirror of
https://github.com/coollabsio/coolify.git
synced 2026-06-14 03:19:51 +00:00
feat(destination): show resources that are deployed on the destination
This commit is contained in:
@@ -24,6 +24,8 @@ class Show extends Component
|
||||
#[Validate(['string', 'required'])]
|
||||
public string $serverIp;
|
||||
|
||||
public array $resources = [];
|
||||
|
||||
public function mount(string $destination_uuid)
|
||||
{
|
||||
try {
|
||||
@@ -33,11 +35,71 @@ class Show extends Component
|
||||
}
|
||||
$this->destination = $destination;
|
||||
$this->syncData();
|
||||
$this->loadResources();
|
||||
} catch (\Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
|
||||
public function loadResources(): void
|
||||
{
|
||||
if ($this->destination->getMorphClass() !== \App\Models\StandaloneDocker::class) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->resources = $this->collectResources([
|
||||
$this->destination->applications,
|
||||
$this->destination->services,
|
||||
$this->destination->postgresqls,
|
||||
$this->destination->redis,
|
||||
$this->destination->mongodbs,
|
||||
$this->destination->mysqls,
|
||||
$this->destination->mariadbs,
|
||||
$this->destination->keydbs,
|
||||
$this->destination->dragonflies,
|
||||
$this->destination->clickhouses,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function collectResources(array $groups): array
|
||||
{
|
||||
$rows = [];
|
||||
foreach ($groups as $group) {
|
||||
foreach ($group as $resource) {
|
||||
$rows[] = $this->resourceRow($resource);
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
protected function resourceRow($resource): array
|
||||
{
|
||||
$type = match (true) {
|
||||
$resource instanceof \App\Models\Application => 'application',
|
||||
$resource instanceof \App\Models\Service => 'service',
|
||||
default => 'database',
|
||||
};
|
||||
$environment = $resource->environment;
|
||||
$project = $environment?->project;
|
||||
$routeName = "project.{$type}.configuration";
|
||||
$url = ($project && $environment)
|
||||
? route($routeName, [
|
||||
'project_uuid' => $project->uuid,
|
||||
'environment_uuid' => $environment->uuid,
|
||||
"{$type}_uuid" => $resource->uuid,
|
||||
])
|
||||
: null;
|
||||
|
||||
return [
|
||||
'type' => $type,
|
||||
'name' => $resource->name,
|
||||
'project' => $project?->name,
|
||||
'environment' => $environment?->name,
|
||||
'url' => $url,
|
||||
];
|
||||
}
|
||||
|
||||
public function syncData(bool $toModel = false)
|
||||
{
|
||||
if ($toModel) {
|
||||
|
||||
@@ -134,8 +134,11 @@ class StandaloneDocker extends BaseModel
|
||||
$mongodbs = $this->mongodbs;
|
||||
$mysqls = $this->mysqls;
|
||||
$mariadbs = $this->mariadbs;
|
||||
$keydbs = $this->keydbs;
|
||||
$dragonflies = $this->dragonflies;
|
||||
$clickhouses = $this->clickhouses;
|
||||
|
||||
return $postgresqls->concat($redis)->concat($mongodbs)->concat($mysqls)->concat($mariadbs);
|
||||
return $postgresqls->concat($redis)->concat($mongodbs)->concat($mysqls)->concat($mariadbs)->concat($keydbs)->concat($dragonflies)->concat($clickhouses);
|
||||
}
|
||||
|
||||
public function attachedTo()
|
||||
|
||||
@@ -28,4 +28,24 @@
|
||||
@endif
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@if ($destination->getMorphClass() === 'App\Models\StandaloneDocker')
|
||||
<div class="pt-6">
|
||||
<h3>Resources</h3>
|
||||
<div class="pb-2 text-xs opacity-70">Applications, services, and databases deployed to this network.</div>
|
||||
@if (count($resources) === 0)
|
||||
<div class="text-xs opacity-70 pt-2">No resources are using this destination.</div>
|
||||
@else
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-2 pt-2">
|
||||
@foreach ($resources as $row)
|
||||
<a href="{{ $row['url'] }}"
|
||||
class="relative flex flex-col dark:text-white coolbox group cursor-pointer">
|
||||
<div class="box-title">{{ ucfirst($row['type']) }}: {{ $row['name'] }}</div>
|
||||
<div class="box-description">{{ $row['project'] }} / {{ $row['environment'] }}</div>
|
||||
</a>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user