Additional Progress

This commit is contained in:
JonatanRek 2024-08-07 07:52:07 +02:00
parent 13756de3a8
commit 7951b8c84c
6 changed files with 53 additions and 19 deletions

View File

@ -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'),
]);
}
}

View File

@ -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,

View File

@ -6,10 +6,9 @@
<x-form::select group-class="mb-3" wire:model.live="hosts" label="Livewire Select" :options="$hosts_available" placeholder="Select value..." multiple />
@foreach($hosts as $key => $host_id)
<x-form::select group-class="mb-3" wire:model="hosts_tasks.{{ $host_id }}" label="Select Tasks for Host {{ $hosts_available[$host_id] }}" :options="$hosts_tasks_available" placeholder="Select value..." multiple />
<x-form::select group-class="mb-3" wire:key="{{ $host_id }}" wire:model="hosts_tasks.{{ $host_id }}" label="Select Tasks for Host {{ $hosts_available[$host_id] }}" :options="$hosts_tasks_available" placeholder="Select value..." multiple />
@endforeach
<x-form::button class="btn-primary" type="submit">Create</x-form::button>
@dump($hosts_tasks)
</x-form::form>
</div>

View File

@ -0,0 +1,14 @@
<x-layout-app>
<div class="container-xl">
<div class="page-header">
<h1>{{ __('Planned Maintenance') }}</h1>
</div>
<p>{!! $maintenance_history->maintenance->description !!}</p>
@foreach ($maintenance_history->historyHosts as $historyHost)
<b>{{ $historyHost->host->hostname }}</b>
@foreach ($historyHost->historyTasks as $historyTasks)
<x-form::checkbox onclick="return false" checked="{{ isset($maintenance_state[$historyHost->id][$historyTasks->id]) ? 'checked' : '' }}" label="{{ $historyTasks->maintenanceTask->task->name }}" name="test-{{ $historyHost->id }}-{{ $historyTasks->id }}" />
@endforeach
@endforeach
</div>
</x-layout-app>

View File

@ -4,7 +4,7 @@
<h1>{{ __('Planned Maintenance') }}</h1>
</div>
<p>{!! $maintenance_history->maintenance->description !!}</p>
<x-form::form action="save" method="PUT">
<x-form::form action="{{ route('maintenance.planned.detail.put', ['maintenance_history' => $maintenance_history->id]) }}" method="PUT">
@foreach ($maintenance_history->historyHosts as $historyHost)
<div class="mb-3">
<div class="btn-toggle btn py-3 w-100 bg-primary text-start" style="--bs-bg-opacity: .2;" data-bs-toggle="collapse" data-bs-target="#collapse{{ $historyHost->id }}">
@ -13,14 +13,14 @@
<div class="collapse" id="collapse{{ $historyHost->id }}">
<div class="card card-body mt-2">
@foreach ($historyHost->historyTasks as $historyTasks)
<x-form::checkbox wire:model="test" label="{{$historyTasks->maintenanceTask->task->name}}" />
<x-form::checkbox name="test[{{ $historyHost->id }}][{{ $historyTasks->id }}]" id="test-{{ $historyHost->id }}-{{ $historyTasks->id }}" label="{{ $historyTasks->maintenanceTask->task->name }}" />
<p>{!! $historyTasks->maintenanceTask->task->description !!}</p>
@endforeach
</div>
</div>
</div>
@endforeach
<x-form::button class="btn-primary" type="submit">{{ __('Ukončit')}}</x-form::button>
<x-form::button class="btn-primary" type="submit">{{ __('Ukončit') }}</x-form::button>
</x-form::form>
</div>
</x-layout-app>

View File

@ -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');