Progress
This commit is contained in:
parent
7951b8c84c
commit
b486cad1ad
70
app/Livewire/Maintenance/ProgressForm.php
Normal file
70
app/Livewire/Maintenance/ProgressForm.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Maintenance;
|
||||
|
||||
use App\Models\MaintenanceHistory;
|
||||
use Carbon\Carbon;
|
||||
use Livewire\Component;
|
||||
|
||||
class ProgressForm extends Component
|
||||
{
|
||||
public $maintenanceHistory;
|
||||
|
||||
//INPUTS
|
||||
public array $maintenance_task_status;
|
||||
|
||||
public function mount(int $maintenanceHistory)
|
||||
{
|
||||
$this->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');
|
||||
}
|
||||
}
|
14
app/Livewire/MaintenanceProgressForm.php
Normal file
14
app/Livewire/MaintenanceProgressForm.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class MaintenanceProgressForm extends Component
|
||||
{
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.maintenance-progress-form');
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
class MaintenanceTaskHistory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'maintenance_task_id',
|
||||
'maintenance_history_id',
|
||||
|
17
resources/views/livewire/maintenance/progress-form.blade.php
Normal file
17
resources/views/livewire/maintenance/progress-form.blade.php
Normal file
@ -0,0 +1,17 @@
|
||||
<div>
|
||||
@foreach ($maintenanceHistory->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 }}">
|
||||
<b>{{ $historyHost->host->hostname }}</b>
|
||||
</div>
|
||||
<div class="collapse" id="collapse{{ $historyHost->id }}" wire:ignore.self>
|
||||
<div class="card card-body mt-2">
|
||||
@foreach ($historyHost->historyTasks as $historyTasks)
|
||||
<x-form::checkbox wire:key="{{ $historyHost->id . $historyTasks->id}}" wire:model.live.debounce.250ms="maintenance_task_status.{{ $historyHost->id }}.{{ $historyTasks->id }}" 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
|
||||
</div>
|
@ -5,21 +5,7 @@
|
||||
</div>
|
||||
<p>{!! $maintenance_history->maintenance->description !!}</p>
|
||||
<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 }}">
|
||||
<b>{{ $historyHost->host->hostname }}</b>
|
||||
</div>
|
||||
<div class="collapse" id="collapse{{ $historyHost->id }}">
|
||||
<div class="card card-body mt-2">
|
||||
@foreach ($historyHost->historyTasks as $historyTasks)
|
||||
<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
|
||||
@livewire('maintenance.progress-form', ['maintenanceHistory' => $maintenance_history->id], key('progress-form'))
|
||||
<x-form::button class="btn-primary" type="submit">{{ __('Ukončit') }}</x-form::button>
|
||||
</x-form::form>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user