From 956416b522125ba49f982502405542c0c9b09824 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 11 Dec 2023 11:27:41 +0100 Subject: [PATCH] refactor: service logs are now on one page --- .../Shared/ExecuteContainerCommand.php | 2 +- app/Livewire/Project/Shared/GetLogs.php | 19 ++++++++---- app/Livewire/Project/Shared/Logs.php | 21 ++++++++----- .../livewire/project/service/index.blade.php | 15 +++++----- .../livewire/project/service/show.blade.php | 6 ---- .../livewire/project/shared/logs.blade.php | 30 +++++++++++-------- routes/web.php | 1 - 7 files changed, 53 insertions(+), 41 deletions(-) diff --git a/app/Livewire/Project/Shared/ExecuteContainerCommand.php b/app/Livewire/Project/Shared/ExecuteContainerCommand.php index 5e0745490..a3a63c154 100644 --- a/app/Livewire/Project/Shared/ExecuteContainerCommand.php +++ b/app/Livewire/Project/Shared/ExecuteContainerCommand.php @@ -80,7 +80,7 @@ class ExecuteContainerCommand extends Component $this->resource = $resource; $this->server = $this->resource->destination->server; $this->container = $this->resource->uuid; - if (data_get($this,'resource.status') == 'running') { + if (str(data_get($this,'resource.status'))->startsWith('running')) { $this->containers->push($this->container); } } else if (data_get($this->parameters, 'service_uuid')) { diff --git a/app/Livewire/Project/Shared/GetLogs.php b/app/Livewire/Project/Shared/GetLogs.php index 6f431b11e..db2170b5f 100644 --- a/app/Livewire/Project/Shared/GetLogs.php +++ b/app/Livewire/Project/Shared/GetLogs.php @@ -51,19 +51,26 @@ class GetLogs extends Component if ($this->resource->getMorphClass() === 'App\Models\Application') { $this->resource->settings->is_include_timestamps = $this->showTimeStamps; $this->resource->settings->save(); - } else { - if ($this->servicesubtype) { - $this->servicesubtype->is_include_timestamps = $this->showTimeStamps; - $this->servicesubtype->save(); + } + if ($this->resource->getMorphClass() === 'App\Models\Service') { + $serviceName = str($this->container)->beforeLast('-')->value(); + $subType = $this->resource->applications()->where('name', $serviceName)->first(); + if ($subType) { + $subType->is_include_timestamps = $this->showTimeStamps; + $subType->save(); } else { - $this->resource->is_include_timestamps = $this->showTimeStamps; - $this->resource->save(); + $subType = $this->resource->databases()->where('name', $serviceName)->first(); + if ($subType) { + $subType->is_include_timestamps = $this->showTimeStamps; + $subType->save(); + } } } } } public function getLogs($refresh = false) { + if (!$refresh && $this->resource->getMorphClass() === 'App\Models\Service') return; if ($this->container) { if ($this->showTimeStamps) { $sshCommand = generateSshCommand($this->server, "docker logs -n {$this->numberOfLines} -t {$this->container}"); diff --git a/app/Livewire/Project/Shared/Logs.php b/app/Livewire/Project/Shared/Logs.php index a927ba9ef..f7c952b46 100644 --- a/app/Livewire/Project/Shared/Logs.php +++ b/app/Livewire/Project/Shared/Logs.php @@ -62,17 +62,24 @@ class Logs extends Component $this->status = $this->resource->status; $this->server = $this->resource->destination->server; $this->container = $this->resource->uuid; + if (str(data_get($this,'resource.status'))->startsWith('running')) { + $this->containers->push($this->container); + } } else if (data_get($this->parameters, 'service_uuid')) { $this->type = 'service'; $this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail(); - $service_name = data_get($this->parameters, 'service_name'); - $this->serviceSubType = $this->resource->applications()->where('name', $service_name)->first(); - if (!$this->serviceSubType) { - $this->serviceSubType = $this->resource->databases()->where('name', $service_name)->first(); - } - $this->status = $this->resource->status; + $this->resource->applications()->get()->each(function ($application) { + if (str(data_get($application, 'status'))->contains('running')) { + $this->containers->push(data_get($application, 'name') . '-' . data_get($this->resource, 'uuid')); + } + }); + $this->resource->databases()->get()->each(function ($database) { + if (str(data_get($database, 'status'))->contains('running')) { + $this->containers->push(data_get($database, 'name') . '-' . data_get($this->resource, 'uuid')); + } + }); + $this->server = $this->resource->server; - $this->container = data_get($this->parameters, 'service_name') . '-' . $this->resource->uuid; } } diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.php index 1c9466575..1daade6af 100644 --- a/resources/views/livewire/project/service/index.blade.php +++ b/resources/views/livewire/project/service/index.blade.php @@ -11,6 +11,10 @@ @click.prevent="activeTab = 'execute-command'; window.location.hash = 'execute-command'" href="#">Execute Command + Logs {{ $application->status }} - Logs @endforeach @foreach ($databases as $database) @@ -90,9 +91,6 @@ @endif
{{ $database->status }}
- Logs @endforeach @@ -114,8 +112,11 @@
+
+ +
- +
diff --git a/resources/views/livewire/project/service/show.blade.php b/resources/views/livewire/project/service/show.blade.php index e7feaae79..8631aa20b 100644 --- a/resources/views/livewire/project/service/show.blade.php +++ b/resources/views/livewire/project/service/show.blade.php @@ -20,12 +20,6 @@ Backups @endif - @if (data_get($parameters, 'service_name')) - - - - @endif
@isset($serviceApplication) diff --git a/resources/views/livewire/project/shared/logs.blade.php b/resources/views/livewire/project/shared/logs.blade.php index 7495ef190..3d011e1e8 100644 --- a/resources/views/livewire/project/shared/logs.blade.php +++ b/resources/views/livewire/project/shared/logs.blade.php @@ -16,21 +16,25 @@

Logs

- + @forelse ($containers as $container) + @if ($loop->first) +

Logs

+ @endif + + @empty +
No containers are not running.
+ @endforelse
@elseif ($type === 'service') - -
- -
- -
+
+ @forelse ($containers as $container) + @if ($loop->first) +

Logs

+ @endif + + @empty +
No containers are not running.
+ @endforelse
@endif
diff --git a/routes/web.php b/routes/web.php index dba77238d..0b3aee821 100644 --- a/routes/web.php +++ b/routes/web.php @@ -136,7 +136,6 @@ Route::middleware(['auth', 'verified'])->group(function () { // Services 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}/logs', Logs::class)->name('project.service.logs'); Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/command', ExecuteContainerCommand::class)->name('project.service.command'); });