This commit is contained in:
JonatanRek 2024-08-09 08:37:00 +02:00
parent 17616bad17
commit c1802dfb52
12 changed files with 127 additions and 29 deletions

View File

@ -35,22 +35,51 @@ public function plannedDetailPut(Request $request, MaintenanceHistory $maintenan
abort(404);
}
$maintenance_history->finished_at = Carbon::now();
$maintenance_history->save();
return view('maintenance.planned-detail-done', [
'maintenance_history' => $maintenance_history,
'maintenance_task_status' => $request->input('maintenance_task_status'),
'maintenance_host_skipped' => $request->input('maintenance_host_skipped'),
]);
}
public function plannedDetailFinishPost(Request $request, MaintenanceHistory $maintenance_history)
{
dd();
if (!empty($maintenance_history->finished_at)) {
abort(404);
}
public function history(Request $request, MaintenanceHistory $maintenance_history)
foreach ($request->input('skippedHostsSummary') as $history_host_id => $summary) {
$maintenance_history->historyHosts->find($history_host_id)->update([
'summary' => $summary,
]);
}
if (!$request->has('skippedHostsTasksSummary')) {
foreach ($maintenance_history->historyHosts as $history_host) {
if (!isset($request->input('skippedHostsTasksSummary')[$history_host->id]))
continue;
foreach ($request->input('skippedHostsTasksSummary')[$history_host->id] as $history_task_id => $task_summary) {
$history_host->find($history_task_id)->update([
'summary' => $task_summary,
]);
}
}
}
$maintenance_history->finished_at = Carbon::now();
$maintenance_history->save();
return redirect()->route('maintenance.history.detail', $maintenance_history->id);
}
public function history(Request $request)
{
return view('maintenance.history');
}
public function historyDetail(Request $request, MaintenanceHistory $maintenance_history)
{
dd($maintenance_history->historyHosts);
}
}

View File

@ -8,6 +8,7 @@
use App\Models\MaintenanceTask;
use App\Models\Task;
use App\Models\User;
use Illuminate\Http\Request;
class Form extends Component
{
@ -47,7 +48,7 @@ protected function rules()
];
}
public function mount($model = null)
public function mount(Request $request, $model = null)
{
$this->hosts_available = Host::all()->pluck('hostname', 'id')->toArray();
$this->hosts_tasks_available = Task::all()->pluck('name', 'id')->toArray();
@ -76,6 +77,8 @@ public function mount($model = null)
}
$this->action = 'update';
} else {
$this->guestor_id = $request->user()->id;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Livewire\Maintenance;
use App\Models\MaintenanceHistory;
use App\Models\MaintenanceHostHistory;
use App\Models\MaintenanceTaskHistory;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
@ -16,21 +17,50 @@ class ProgressForm extends Component
//INPUTS
public array $maintenance_task_status;
public array $maintenance_task_status_old;
public array $maintenance_host_skipped;
public function mount(int $maintenanceHistory)
{
$this->maintenanceHistory = self::getMaintenanceHistory($maintenanceHistory);
$this->maintenanceHistory = self::getMaintenanceHistory($maintenanceHistory, true);
if (!empty($this->maintenanceHistory->finished_at)) {
abort(404);
}
foreach ($this->maintenanceHistory->historyHosts as $maintenanceHost) {
$this->maintenance_host_skipped[$maintenanceHost->id] = (bool)$maintenanceHost->is_skipped;
foreach ($maintenanceHost->historyTasks as $maintenanceTask) {
$this->maintenance_task_status[$maintenanceHost->id][$maintenanceTask->id] = (!empty($maintenanceTask->finished_at) ? true : false);
}
}
}
public function updatedMaintenanceHostSkipped($value)
{
$skipped = [];
$notSkipped = [];
foreach ($this->maintenance_host_skipped as $host_history_id => $is_skipped) {
if ($is_skipped === true) {
$skipped[] = $host_history_id;
continue;
}
$notSkipped[] = $host_history_id;
}
if (count($skipped) != 0) {
MaintenanceHostHistory::whereIn('id', $skipped)->update([
'is_skipped' => true,
]);
}
if (count($notSkipped) != 0) {
MaintenanceHostHistory::whereIn('id', $notSkipped)->update([
'is_skipped' => false,
]);
}
}
public function updatedMaintenanceTaskStatus($value)
{
foreach ($this->maintenance_task_status as $host_history_id => $tasks) {
@ -82,7 +112,12 @@ public function render()
return view('livewire.maintenance.progress-form');
}
private static function getMaintenanceHistory(int $maintenanceHistoryId){
private static function getMaintenanceHistory(int $maintenanceHistoryId, bool $force = false)
{
if ($force){
Cache::forget("maintenance_history_{$maintenanceHistoryId}");
}
return Cache::remember("maintenance_history_{$maintenanceHistoryId}", 60, function () use ($maintenanceHistoryId) {
return MaintenanceHistory::with([
'maintenance.tasks',

View File

@ -12,6 +12,12 @@ class MaintenanceHostHistory extends Model
protected $fillable = [
'maintenance_history_id',
'host_id',
'summary',
'is_skipped',
];
protected $cast = [
'is_skipped' => 'bool'
];
public function host()

View File

@ -13,6 +13,7 @@ class MaintenanceTaskHistory extends Model
'maintenance_task_id',
'maintenance_history_id',
'maintenance_host_history_id',
'summary',
];
public function maintenance()

View File

@ -22,6 +22,7 @@ public function up(): void
$table->foreignIdFor(MaintenanceHostHistory::class);
$table->string('status')->default(1);
$table->datetime('finished_at')->nullable();
$table->text('summary')->nullable();
$table->timestamps();
});
}

View File

@ -19,6 +19,8 @@ public function up(): void
$table->id();
$table->foreignIdFor(MaintenanceHistory::class);
$table->foreignIdFor(Host::class);
$table->text('summary')->nullable();
$table->boolean('is_skipped')->default(false);
$table->timestamps();
});
}

View File

@ -1,15 +1,19 @@
<div>
@foreach ($maintenanceHistory->historyHosts as $historyHost)
<div class="mb-3">
<div class="btn-toggle btn py-3 w-100 bg-primary text-start d-flex justify-content-between" style="--bs-bg-opacity: .2;" data-bs-toggle="collapse" data-bs-target="#collapse{{ $historyHost->id }}">
<div class="position-relative">
<div class="btn-toggle btn py-3 bg-primary w-100 text-start" style="--bs-bg-opacity: .2;" data-bs-toggle="collapse" data-bs-target="#collapse{{ $historyHost->id }}">
<b>{{ $historyHost->host->hostname }}</b>
<x-form::checkbox groupClass="ms-auto" wire:key="{{ $historyHost->id . 'skip' }}" name="test[{{ $historyHost->id }}][skip]" id="test-{{ $historyHost->id }}-skip" label="{{ __('Skip') }}" />
</div>
<div class="position-absolute top-50 end-0 translate-middle-y px-3 py-2">
<x-form::checkbox groupClass="ms-auto" wire:key="{{ $historyHost->id . 'skip' }}" wire:model.live.debounce.250ms="maintenance_host_skipped.{{ $historyHost->id }}" name="maintenance_host_skipped[{{ $historyHost->id }}]" id="maintenance_host_skipped-{{ $historyHost->id }}" label="{{ __('Skip') }}" />
</div>
</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="maintenance_task_status[{{ $historyHost->id }}][{{ $historyTasks->id }}]" id="maintenance_task_status-{{ $historyHost->id }}-{{ $historyTasks->id }}" label="{{ $historyTasks->maintenanceTask->task->name }}" />
<p>{!! $historyTasks->maintenanceTask->task->description !!}</p>
@foreach ($historyHost->historyTasks as $historyTask)
<x-form::checkbox wire:key="{{ $historyHost->id . $historyTask->id }}" wire:model.live.debounce.250ms="maintenance_task_status.{{ $historyHost->id }}.{{ $historyTask->id }}" name="maintenance_task_status[{{ $historyHost->id }}][{{ $historyTask->id }}]" id="maintenance_task_status-{{ $historyHost->id }}-{{ $historyTask->id }}" label="{{ $historyTask->maintenanceTask->task->name }}" />
<p>{!! $historyTask->maintenanceTask->task->description !!}</p>
@endforeach
</div>
</div>

View File

@ -4,14 +4,21 @@
<h1>{{ __('Planned Maintenance') }}</h1>
</div>
<p>{!! $maintenance_history->maintenance->description !!}</p>
<x-form::form action="{{ route('maintenance.planned.finished', ['maintenance_history' => $maintenance_history->id]) }}" method="POST">
@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_task_status[$historyHost->id][$historyTasks->id]) ? 'checked' : '' }}" label="{{ $historyTasks->maintenanceTask->task->name }}" name="test-{{ $historyHost->id }}-{{ $historyTasks->id }}" />
@if(!isset($maintenance_task_status[$historyHost->id][$historyTasks->id]))
<x-form::quill />
@if (in_array($historyHost->id, array_keys($maintenance_host_skipped)))
<x-form::quill label="{{ __('Reason for Skipping Host: ') . $historyHost->host->hostname}}" id="skipped-host-{{ $historyHost->id }}-summary" name="skippedHostsSummary[{{ $historyHost->id }}]" help="{{ _('Describe why did you skipped the host') }}" />
@else
@foreach ($historyHost->historyTasks as $historyTask)
@if (!isset($maintenance_task_status[$historyHost->id][$historyTask->id]))
<x-form::quill label="{{ __('Reason for Skipping Task: ') . $historyTask->maintenanceTask->name}}" id="skipped-host-{{ $historyHost->id }}-task-{{ $historyTask->id }}-summary" name="skippedHostTasksSummary[{{ $historyHost->id }}][{{ $historyTask->id }}]" help="{{ _('Describe why did you not finished the task') }}" />
@else
<x-form::checkbox onclick="return false" checked="{{ isset($maintenance_task_status[$historyHost->id][$historyTask->id]) ? 'checked' : '' }}" label="{{ $historyTask->maintenanceTask->task->name }}" name="test-{{ $historyHost->id }}-{{ $historyTask->id }}" />
@endif
@endforeach
@endif
@endforeach
<x-form::button class="btn-primary" type="submit">{{ __('Ukončit Maintenance') }}</x-form::button>
</x-form::form>
</div>
</x-layout-app>

View File

@ -6,7 +6,7 @@
<p>{!! $maintenance_history->maintenance->description !!}</p>
<x-form::form action="{{ route('maintenance.planned.detail.put', ['maintenance_history' => $maintenance_history->id]) }}" method="PUT">
@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::button class="btn-primary" type="submit">{{ __('Pokračovat') }}</x-form::button>
</x-form::form>
</div>
</x-layout-app>

View File

@ -11,7 +11,9 @@
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::post('/maintenance/planned/{maintenance_history}/finished', [App\Http\Controllers\MaintenanceController::class, 'plannedDetailFinishPost'])->name('maintenance.planned.finished');
Route::get('/maintenance/history/', [App\Http\Controllers\MaintenanceController::class, 'history'])->name('maintenance.history');
Route::get('/maintenance/history/{maintenance_history}', [App\Http\Controllers\MaintenanceController::class, 'historyDetail'])->name('maintenance.history.detail');
Route::get('/host', [App\Http\Controllers\HostController::class, 'index'])->name('host');

View File

@ -30,8 +30,16 @@ php artisan migrate --force --no-interaction
# Link storage and create default user
if [ "$init" = true ]; then
echo "Initialization of Laravel"
# Install project build dependencies
composer install --quiet --prefer-dist-o
php artisan db:seed --force --class=DatabaseSeeder
php artisan storage:link
#clear build dependencies and install production dependencies
rm -rf vendor/*
composer install --quiet --prefer-dist --no-dev -o
fi
# Clear Cashes