From 7951b8c84c263fb20f67fd72a4f631bfb00153d2 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Wed, 7 Aug 2024 07:52:07 +0200 Subject: [PATCH] Additional Progress --- .../Controllers/MaintenanceController.php | 9 ++++++ app/Livewire/Maintenance/Form.php | 13 ++++++++- .../views/livewire/maintenance/form.blade.php | 7 ++--- .../maintenance/planned-detail-done.blade.php | 14 ++++++++++ .../maintenance/planned-detail.blade.php | 28 +++++++++---------- routes/web.php | 1 + 6 files changed, 53 insertions(+), 19 deletions(-) create mode 100644 resources/views/maintenance/planned-detail-done.blade.php diff --git a/app/Http/Controllers/MaintenanceController.php b/app/Http/Controllers/MaintenanceController.php index b70a708..16a524e 100644 --- a/app/Http/Controllers/MaintenanceController.php +++ b/app/Http/Controllers/MaintenanceController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\MaintenanceHistory; +use Illuminate\Http\Request; class MaintenanceController extends BaseController { @@ -22,4 +23,12 @@ public function plannedDetail(MaintenanceHistory $maintenance_history) 'maintenance_history' => $maintenance_history, ]); } + + public function plannedDetailPut(Request $request, MaintenanceHistory $maintenance_history) + { + return view('maintenance.planned-detail-done', [ + 'maintenance_history' => $maintenance_history, + 'maintenance_state' => $request->input('test'), + ]); + } } diff --git a/app/Livewire/Maintenance/Form.php b/app/Livewire/Maintenance/Form.php index 95df2d0..3ce96e5 100644 --- a/app/Livewire/Maintenance/Form.php +++ b/app/Livewire/Maintenance/Form.php @@ -55,6 +55,17 @@ public function mount($model = null) } } + public function updatedHosts($value) + { + foreach ($this->hosts_tasks as $host_id => $tasks) { + if (in_array($host_id, $this->hosts)) { + continue; + } + + unset($this->hosts_tasks[$host_id]); + } + } + public function store() { $validatedData = $this->validate(); @@ -62,7 +73,7 @@ public function store() $hosts = Host::whereIn('id', $this->hosts)->get(); foreach ($hosts as $key => $host) { $maintenance->hosts()->attach($host); - $tasks = Host::whereIn('id', $this->hosts_tasks[$host->id])->get(); + $tasks = Task::whereIn('id', $this->hosts_tasks[$host->id])->get(); foreach ($tasks as $task) { $maintenance->tasks()->create([ 'task_id' => $task->id, diff --git a/resources/views/livewire/maintenance/form.blade.php b/resources/views/livewire/maintenance/form.blade.php index e673b14..e906b69 100644 --- a/resources/views/livewire/maintenance/form.blade.php +++ b/resources/views/livewire/maintenance/form.blade.php @@ -4,12 +4,11 @@ - + @foreach($hosts as $key => $host_id) - + @endforeach - + Create - @dump($hosts_tasks) diff --git a/resources/views/maintenance/planned-detail-done.blade.php b/resources/views/maintenance/planned-detail-done.blade.php new file mode 100644 index 0000000..0df61b6 --- /dev/null +++ b/resources/views/maintenance/planned-detail-done.blade.php @@ -0,0 +1,14 @@ + +
+ +

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

+ @foreach ($maintenance_history->historyHosts as $historyHost) + {{ $historyHost->host->hostname }} + @foreach ($historyHost->historyTasks as $historyTasks) + + @endforeach + @endforeach +
+
diff --git a/resources/views/maintenance/planned-detail.blade.php b/resources/views/maintenance/planned-detail.blade.php index f94c659..32037a2 100644 --- a/resources/views/maintenance/planned-detail.blade.php +++ b/resources/views/maintenance/planned-detail.blade.php @@ -4,23 +4,23 @@

{{ __('Planned Maintenance') }}

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

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

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

- @endforeach +
+
+ {{ $historyHost->host->hostname }} +
+
+
+ @foreach ($historyHost->historyTasks as $historyTasks) + +

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

+ @endforeach +
-
@endforeach - {{ __('Ukončit')}} + {{ __('Ukončit') }}
- \ No newline at end of file + diff --git a/routes/web.php b/routes/web.php index 0e73331..30778da 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,6 +10,7 @@ Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home'); Route::get('/maintenance/planned', [App\Http\Controllers\MaintenanceController::class, 'planned'])->name('maintenance.planned'); Route::get('/maintenance/planned/{maintenance_history}', [App\Http\Controllers\MaintenanceController::class, 'plannedDetail'])->name('maintenance.planned.detail'); +Route::put('/maintenance/planned/{maintenance_history}', [App\Http\Controllers\MaintenanceController::class, 'plannedDetailPut'])->name('maintenance.planned.detail.put'); Route::get('/host', [App\Http\Controllers\HostController::class, 'index'])->name('host');