From b486cad1ada5cb4a8b457256aab0946865d776a3 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Wed, 7 Aug 2024 09:54:20 +0200 Subject: [PATCH] Progress --- app/Livewire/Maintenance/ProgressForm.php | 70 +++++++++++++++++++ app/Livewire/MaintenanceProgressForm.php | 14 ++++ app/Models/MaintenanceTaskHistory.php | 2 +- .../maintenance/progress-form.blade.php | 17 +++++ .../maintenance/planned-detail.blade.php | 16 +---- 5 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 app/Livewire/Maintenance/ProgressForm.php create mode 100644 app/Livewire/MaintenanceProgressForm.php create mode 100644 resources/views/livewire/maintenance/progress-form.blade.php diff --git a/app/Livewire/Maintenance/ProgressForm.php b/app/Livewire/Maintenance/ProgressForm.php new file mode 100644 index 0000000..28f40ac --- /dev/null +++ b/app/Livewire/Maintenance/ProgressForm.php @@ -0,0 +1,70 @@ +maintenanceHistory = MaintenanceHistory::with(['historyHosts', 'historyHosts.historyTasks', 'historyHosts.historyTasks.maintenanceTask', 'historyHosts.historyTasks.maintenanceTask.task'])->find($maintenanceHistory); + foreach ($this->maintenanceHistory->historyHosts as $maintenanceHost) { + foreach ($maintenanceHost->historyTasks as $maintenanceTask) { + $this->maintenance_task_status[$maintenanceHost->id][$maintenanceTask->id] = (!empty($maintenanceTask->finished_at) ? true : false); + } + } + } + + public function updatedMaintenanceTaskStatus($value) + { + $hosts = $this->maintenanceHistory->historyHosts()->whereIn('maintenance_host_histories.id', array_keys($this->maintenance_task_status))->get()->keyBy(['id']); + foreach ($this->maintenance_task_status as $host_history_id => $tasks) { + $done = []; + $notDone = []; + + foreach ($tasks as $task_history_id => $state) { + if ($state === true) { + $done[] = $task_history_id; + continue; + } + + $notDone[] = $task_history_id; + } + + if (count($done) != 0) { + $hosts[$host_history_id]->historyTasks() + ->whereIn('maintenance_task_histories.id', $done) + ->update([ + 'maintenance_task_histories.maintenance_host_history_id' => $host_history_id, + 'maintenance_task_histories.status' => 2, + 'maintenance_task_histories.finished_at' => Carbon::now(), + ]); + } + + if (count($notDone) != 0) { + $this->maintenanceHistory->historyHosts() + ->find($host_history_id)->historyTasks() + ->whereIn('maintenance_task_histories.id', $notDone) + ->update([ + 'maintenance_task_histories.maintenance_host_history_id' => $host_history_id, + 'maintenance_task_histories.status' => 1, + 'maintenance_task_histories.finished_at' => null, + ]); + } + } + } + + + public function render() + { + return view('livewire.maintenance.progress-form'); + } +} diff --git a/app/Livewire/MaintenanceProgressForm.php b/app/Livewire/MaintenanceProgressForm.php new file mode 100644 index 0000000..3a26440 --- /dev/null +++ b/app/Livewire/MaintenanceProgressForm.php @@ -0,0 +1,14 @@ + + @foreach ($maintenanceHistory->historyHosts as $historyHost) +
+
+ {{ $historyHost->host->hostname }} +
+
+
+ @foreach ($historyHost->historyTasks as $historyTasks) + +

{!! $historyTasks->maintenanceTask->task->description !!}

+ @endforeach +
+
+
+ @endforeach + diff --git a/resources/views/maintenance/planned-detail.blade.php b/resources/views/maintenance/planned-detail.blade.php index 32037a2..675183c 100644 --- a/resources/views/maintenance/planned-detail.blade.php +++ b/resources/views/maintenance/planned-detail.blade.php @@ -5,21 +5,7 @@

{!! $maintenance_history->maintenance->description !!}

- @foreach ($maintenance_history->historyHosts as $historyHost) -
-
- {{ $historyHost->host->hostname }} -
-
-
- @foreach ($historyHost->historyTasks as $historyTasks) - -

{!! $historyTasks->maintenanceTask->task->description !!}

- @endforeach -
-
-
- @endforeach + @livewire('maintenance.progress-form', ['maintenanceHistory' => $maintenance_history->id], key('progress-form')) {{ __('UkonĨit') }}