2024-01-07 15:23:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire\Project\Resource;
|
|
|
|
|
|
|
|
|
|
use App\Models\Environment;
|
|
|
|
|
use App\Models\Project;
|
2024-12-17 12:42:16 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2024-01-07 15:23:41 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class Index extends Component
|
|
|
|
|
{
|
|
|
|
|
public Project $project;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
public Environment $environment;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
public Collection $allProjects;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
public Collection $allEnvironments;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
public array $parameters;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
protected Collection $applications;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
protected Collection $postgresqls;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
protected Collection $redis;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
protected Collection $mongodbs;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
protected Collection $mysqls;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
protected Collection $mariadbs;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
protected Collection $keydbs;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
protected Collection $dragonflies;
|
2026-01-16 10:51:26 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
protected Collection $clickhouses;
|
2026-01-16 10:51:26 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
protected Collection $services;
|
2024-10-14 17:42:44 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
public function mount(): void
|
2024-01-12 10:25:20 +00:00
|
|
|
{
|
2024-12-17 12:42:16 +00:00
|
|
|
$this->applications = $this->postgresqls = $this->redis = $this->mongodbs = $this->mysqls = $this->mariadbs = $this->keydbs = $this->dragonflies = $this->clickhouses = $this->services = collect();
|
2024-10-14 17:42:44 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
2024-12-17 12:42:16 +00:00
|
|
|
$project = currentTeam()
|
|
|
|
|
->projects()
|
|
|
|
|
->select('id', 'uuid', 'team_id', 'name')
|
|
|
|
|
->where('uuid', request()->route('project_uuid'))
|
|
|
|
|
->firstOrFail();
|
|
|
|
|
$environment = $project->environments()
|
|
|
|
|
->select('id', 'uuid', 'name', 'project_id')
|
|
|
|
|
->where('uuid', request()->route('environment_uuid'))
|
|
|
|
|
->firstOrFail();
|
|
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
$this->project = $project;
|
2026-01-16 10:51:26 +00:00
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
// Load projects and environments for breadcrumb navigation
|
2026-01-16 10:51:26 +00:00
|
|
|
$this->allProjects = Project::ownedByCurrentTeamCached();
|
2026-07-19 09:44:12 +00:00
|
|
|
$environmentRelations = [
|
|
|
|
|
'applications:id,uuid,name,environment_id',
|
|
|
|
|
'services:id,uuid,name,environment_id',
|
|
|
|
|
'postgresqls:id,uuid,name,environment_id',
|
|
|
|
|
'redis:id,uuid,name,environment_id',
|
|
|
|
|
'mongodbs:id,uuid,name,environment_id',
|
|
|
|
|
'mysqls:id,uuid,name,environment_id',
|
|
|
|
|
'mariadbs:id,uuid,name,environment_id',
|
|
|
|
|
'keydbs:id,uuid,name,environment_id',
|
|
|
|
|
'dragonflies:id,uuid,name,environment_id',
|
|
|
|
|
'clickhouses:id,uuid,name,environment_id',
|
|
|
|
|
];
|
|
|
|
|
|
2026-01-16 10:51:26 +00:00
|
|
|
$this->allEnvironments = $project->environments()
|
2026-03-19 23:02:18 +00:00
|
|
|
->select('id', 'uuid', 'name', 'project_id')
|
2026-07-19 09:44:12 +00:00
|
|
|
->with($environmentRelations)
|
2026-03-19 23:02:18 +00:00
|
|
|
->get();
|
2026-01-16 10:51:26 +00:00
|
|
|
|
2024-12-11 16:09:53 +00:00
|
|
|
$this->environment = $environment->loadCount([
|
|
|
|
|
'applications',
|
|
|
|
|
'redis',
|
|
|
|
|
'postgresqls',
|
|
|
|
|
'mysqls',
|
|
|
|
|
'keydbs',
|
|
|
|
|
'dragonflies',
|
|
|
|
|
'clickhouses',
|
|
|
|
|
'mariadbs',
|
|
|
|
|
'mongodbs',
|
|
|
|
|
'services',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-19 23:02:18 +00:00
|
|
|
// Eager load relationships for applications
|
2024-12-11 16:09:53 +00:00
|
|
|
$this->applications = $this->environment->applications()->with([
|
|
|
|
|
'tags',
|
|
|
|
|
'destination.server.settings',
|
|
|
|
|
'settings',
|
|
|
|
|
])->get()->sortBy('name');
|
2026-01-16 10:51:26 +00:00
|
|
|
$projectUuid = $this->project->uuid;
|
|
|
|
|
$environmentUuid = $this->environment->uuid;
|
|
|
|
|
$this->applications = $this->applications->map(function ($application) use ($projectUuid, $environmentUuid) {
|
2024-12-11 16:09:53 +00:00
|
|
|
$application->hrefLink = route('project.application.configuration', [
|
2026-01-16 10:51:26 +00:00
|
|
|
'project_uuid' => $projectUuid,
|
|
|
|
|
'environment_uuid' => $environmentUuid,
|
|
|
|
|
'application_uuid' => $application->uuid,
|
2024-12-11 16:09:53 +00:00
|
|
|
]);
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-12 10:25:20 +00:00
|
|
|
return $application;
|
|
|
|
|
});
|
2026-07-19 09:44:12 +00:00
|
|
|
$this->applications = $this->applications->sortBy('name');
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-12-11 16:09:53 +00:00
|
|
|
// Load all database resources in a single query per type
|
|
|
|
|
$databaseTypes = [
|
|
|
|
|
'postgresqls' => 'postgresqls',
|
|
|
|
|
'redis' => 'redis',
|
|
|
|
|
'mongodbs' => 'mongodbs',
|
|
|
|
|
'mysqls' => 'mysqls',
|
|
|
|
|
'mariadbs' => 'mariadbs',
|
|
|
|
|
'keydbs' => 'keydbs',
|
|
|
|
|
'dragonflies' => 'dragonflies',
|
|
|
|
|
'clickhouses' => 'clickhouses',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($databaseTypes as $property => $relation) {
|
|
|
|
|
$this->{$property} = $this->environment->{$relation}()->with([
|
|
|
|
|
'tags',
|
|
|
|
|
'destination.server.settings',
|
|
|
|
|
])->get()->sortBy('name');
|
2026-01-16 10:51:26 +00:00
|
|
|
$this->{$property} = $this->{$property}->map(function ($db) use ($projectUuid, $environmentUuid) {
|
2024-12-11 16:09:53 +00:00
|
|
|
$db->hrefLink = route('project.database.configuration', [
|
2026-01-16 10:51:26 +00:00
|
|
|
'project_uuid' => $projectUuid,
|
2024-12-11 16:09:53 +00:00
|
|
|
'database_uuid' => $db->uuid,
|
2026-01-16 10:51:26 +00:00
|
|
|
'environment_uuid' => $environmentUuid,
|
2024-01-12 10:25:20 +00:00
|
|
|
]);
|
2024-12-17 12:42:16 +00:00
|
|
|
|
2024-12-11 16:09:53 +00:00
|
|
|
return $db;
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-12-11 16:09:53 +00:00
|
|
|
// Load services with their tags and server
|
|
|
|
|
$this->services = $this->environment->services()->with([
|
|
|
|
|
'tags',
|
|
|
|
|
'destination.server.settings',
|
|
|
|
|
])->get()->sortBy('name');
|
2026-01-16 10:51:26 +00:00
|
|
|
$this->services = $this->services->map(function ($service) use ($projectUuid, $environmentUuid) {
|
2024-12-11 16:09:53 +00:00
|
|
|
$service->hrefLink = route('project.service.configuration', [
|
2026-01-16 10:51:26 +00:00
|
|
|
'project_uuid' => $projectUuid,
|
|
|
|
|
'environment_uuid' => $environmentUuid,
|
|
|
|
|
'service_uuid' => $service->uuid,
|
2024-12-11 16:09:53 +00:00
|
|
|
]);
|
2024-12-17 12:42:16 +00:00
|
|
|
|
2024-01-12 10:25:20 +00:00
|
|
|
return $service;
|
|
|
|
|
});
|
2024-01-07 15:23:41 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
public function render()
|
|
|
|
|
{
|
2026-03-19 23:02:18 +00:00
|
|
|
return view('livewire.project.resource.index', [
|
|
|
|
|
'applications' => $this->applications,
|
|
|
|
|
'postgresqls' => $this->postgresqls,
|
|
|
|
|
'redis' => $this->redis,
|
|
|
|
|
'mongodbs' => $this->mongodbs,
|
|
|
|
|
'mysqls' => $this->mysqls,
|
|
|
|
|
'mariadbs' => $this->mariadbs,
|
|
|
|
|
'keydbs' => $this->keydbs,
|
|
|
|
|
'dragonflies' => $this->dragonflies,
|
|
|
|
|
'clickhouses' => $this->clickhouses,
|
|
|
|
|
'services' => $this->services,
|
2026-08-03 21:11:54 +00:00
|
|
|
'applicationsJs' => $this->toSearchableArray($this->applications, 'application', 'Application'),
|
2026-08-05 11:50:11 +00:00
|
|
|
'postgresqlsJs' => $this->toSearchableArray($this->postgresqls, 'database', 'Database'),
|
|
|
|
|
'redisJs' => $this->toSearchableArray($this->redis, 'database', 'Database'),
|
|
|
|
|
'mongodbsJs' => $this->toSearchableArray($this->mongodbs, 'database', 'Database'),
|
|
|
|
|
'mysqlsJs' => $this->toSearchableArray($this->mysqls, 'database', 'Database'),
|
|
|
|
|
'mariadbsJs' => $this->toSearchableArray($this->mariadbs, 'database', 'Database'),
|
|
|
|
|
'keydbsJs' => $this->toSearchableArray($this->keydbs, 'database', 'Database'),
|
|
|
|
|
'dragonfliesJs' => $this->toSearchableArray($this->dragonflies, 'database', 'Database'),
|
|
|
|
|
'clickhousesJs' => $this->toSearchableArray($this->clickhouses, 'database', 'Database'),
|
2026-08-03 21:11:54 +00:00
|
|
|
'servicesJs' => $this->toSearchableArray($this->services, 'service', 'Service'),
|
2026-03-19 23:02:18 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-03 21:11:54 +00:00
|
|
|
private function toSearchableArray(Collection $items, string $type, string $typeLabel): array
|
2026-03-19 23:02:18 +00:00
|
|
|
{
|
|
|
|
|
return $items->map(fn ($item) => [
|
|
|
|
|
'uuid' => $item->uuid,
|
|
|
|
|
'name' => $item->name,
|
2026-08-03 21:11:54 +00:00
|
|
|
'type' => $type,
|
chore(v5): archive V5 implementation and remove runtime integration
Move V5 source, migrations, UI, scripts, and tests into documentation, then remove V5 routes, models, jobs, configuration, dependencies, and application hooks.
2026-08-15 17:13:30 +00:00
|
|
|
'typeLabel' => $typeLabel,
|
2026-03-19 23:02:18 +00:00
|
|
|
'fqdn' => $item->fqdn ?? null,
|
chore(v5): archive V5 implementation and remove runtime integration
Move V5 source, migrations, UI, scripts, and tests into documentation, then remove V5 routes, models, jobs, configuration, dependencies, and application hooks.
2026-08-15 17:13:30 +00:00
|
|
|
'description' => $item->description ?? null,
|
2026-03-19 23:02:18 +00:00
|
|
|
'status' => $item->status ?? '',
|
2026-08-31 11:13:26 +00:00
|
|
|
'restartLimitReached' => method_exists($item, 'stoppedAfterRestartLimit') && $item->stoppedAfterRestartLimit(),
|
|
|
|
|
'restartCount' => method_exists($item, 'stoppedAfterRestartLimit') && $item->stoppedAfterRestartLimit()
|
|
|
|
|
? max($item->restart_count ?? 0, $item->max_restart_count ?? 0)
|
|
|
|
|
: ($item->restart_count ?? 0),
|
|
|
|
|
'maxRestartCount' => $item->max_restart_count ?? 0,
|
2026-03-19 23:02:18 +00:00
|
|
|
'server_status' => $item->server_status ?? null,
|
|
|
|
|
'hrefLink' => $item->hrefLink ?? '',
|
|
|
|
|
'destination' => [
|
|
|
|
|
'server' => [
|
chore(v5): archive V5 implementation and remove runtime integration
Move V5 source, migrations, UI, scripts, and tests into documentation, then remove V5 routes, models, jobs, configuration, dependencies, and application hooks.
2026-08-15 17:13:30 +00:00
|
|
|
'name' => $item->destination?->server?->name ?? 'Unknown',
|
2026-03-19 23:02:18 +00:00
|
|
|
],
|
|
|
|
|
],
|
chore(v5): archive V5 implementation and remove runtime integration
Move V5 source, migrations, UI, scripts, and tests into documentation, then remove V5 routes, models, jobs, configuration, dependencies, and application hooks.
2026-08-15 17:13:30 +00:00
|
|
|
'tags' => $item->tags->map(fn ($tag) => [
|
2026-03-19 23:02:18 +00:00
|
|
|
'id' => $tag->id,
|
|
|
|
|
'name' => $tag->name,
|
|
|
|
|
])->values()->toArray(),
|
|
|
|
|
])->values()->toArray();
|
2024-01-07 15:23:41 +00:00
|
|
|
}
|
|
|
|
|
}
|