From 3b67d0a8de20b71d7274f7057d28b1b29bf4e834 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 1 Dec 2023 10:34:30 +0100 Subject: [PATCH] feat: save timestamp configuration for logs --- app/Http/Livewire/Project/Shared/GetLogs.php | 36 +++++++++++ app/Http/Livewire/Project/Shared/Logs.php | 6 ++ ...3_12_01_091723_save_logs_view_settings.php | 64 +++++++++++++++++++ .../livewire/project/shared/logs.blade.php | 6 +- 4 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2023_12_01_091723_save_logs_view_settings.php diff --git a/app/Http/Livewire/Project/Shared/GetLogs.php b/app/Http/Livewire/Project/Shared/GetLogs.php index 4244bed12..933938f56 100644 --- a/app/Http/Livewire/Project/Shared/GetLogs.php +++ b/app/Http/Livewire/Project/Shared/GetLogs.php @@ -2,7 +2,16 @@ namespace App\Http\Livewire\Project\Shared; +use App\Models\Application; use App\Models\Server; +use App\Models\Service; +use App\Models\ServiceApplication; +use App\Models\ServiceDatabase; +use App\Models\StandaloneMariadb; +use App\Models\StandaloneMongodb; +use App\Models\StandaloneMysql; +use App\Models\StandalonePostgresql; +use App\Models\StandaloneRedis; use Illuminate\Support\Facades\Process; use Livewire\Component; @@ -10,17 +19,44 @@ class GetLogs extends Component { public string $outputs = ''; public string $errors = ''; + public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb $resource; + public ServiceApplication|ServiceDatabase|null $servicesubtype = null; public Server $server; public ?string $container = null; public ?bool $streamLogs = false; public ?bool $showTimeStamps = true; public int $numberOfLines = 100; + + public function mount() + { + if ($this->resource->getMorphClass() === 'App\Models\Application') { + $this->showTimeStamps = $this->resource->settings->is_include_timestamps; + } else { + if ($this->servicesubtype) { + $this->showTimeStamps = $this->servicesubtype->is_include_timestamps; + } else { + $this->showTimeStamps = $this->resource->is_include_timestamps; + } + } + } public function doSomethingWithThisChunkOfOutput($output) { $this->outputs .= removeAnsiColors($output); } public function instantSave() { + 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(); + } else { + $this->resource->is_include_timestamps = $this->showTimeStamps; + $this->resource->save(); + } + } } public function getLogs($refresh = false) { diff --git a/app/Http/Livewire/Project/Shared/Logs.php b/app/Http/Livewire/Project/Shared/Logs.php index 982f729b4..18b632ab4 100644 --- a/app/Http/Livewire/Project/Shared/Logs.php +++ b/app/Http/Livewire/Project/Shared/Logs.php @@ -22,6 +22,7 @@ class Logs extends Component public $parameters; public $query; public $status; + public $serviceSubType; public function mount() { @@ -64,6 +65,11 @@ public function mount() } 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->server = $this->resource->server; $this->container = data_get($this->parameters, 'service_name') . '-' . $this->resource->uuid; diff --git a/database/migrations/2023_12_01_091723_save_logs_view_settings.php b/database/migrations/2023_12_01_091723_save_logs_view_settings.php new file mode 100644 index 000000000..a43564454 --- /dev/null +++ b/database/migrations/2023_12_01_091723_save_logs_view_settings.php @@ -0,0 +1,64 @@ +boolean('is_include_timestamps')->default(false); + }); + Schema::table('service_applications', function (Blueprint $table) { + $table->boolean('is_include_timestamps')->default(false); + }); + Schema::table('service_databases', function (Blueprint $table) { + $table->boolean('is_include_timestamps')->default(false); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->boolean('is_include_timestamps')->default(false); + }); + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->boolean('is_include_timestamps')->default(false); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->boolean('is_include_timestamps')->default(false); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->boolean('is_include_timestamps')->default(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('application_settings', function (Blueprint $table) { + $table->dropColumn('is_include_timestamps'); + }); + Schema::table('service_applications', function (Blueprint $table) { + $table->dropColumn('is_include_timestamps'); + }); + Schema::table('service_databases', function (Blueprint $table) { + $table->dropColumn('is_include_timestamps'); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->dropColumn('is_include_timestamps'); + }); + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->dropColumn('is_include_timestamps'); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->dropColumn('is_include_timestamps'); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->dropColumn('is_include_timestamps'); + }); + } +}; diff --git a/resources/views/livewire/project/shared/logs.blade.php b/resources/views/livewire/project/shared/logs.blade.php index db5320a17..2b21f18a9 100644 --- a/resources/views/livewire/project/shared/logs.blade.php +++ b/resources/views/livewire/project/shared/logs.blade.php @@ -7,7 +7,7 @@ @if ($loop->first)

Logs

@endif - + @empty
No containers are not running.
@endforelse @@ -16,7 +16,7 @@

Logs

- +
@elseif ($type === 'service') @@ -28,7 +28,7 @@
- +
@endif