diff --git a/app/Http/Controllers/MaintenanceController.php b/app/Http/Controllers/MaintenanceController.php index b26f082..b160ac6 100644 --- a/app/Http/Controllers/MaintenanceController.php +++ b/app/Http/Controllers/MaintenanceController.php @@ -20,7 +20,7 @@ public function planned() public function plannedDetail(MaintenanceHistory $maintenance_history) { - if (!empty($maintenance_history->finished_at)){ + if (!empty($maintenance_history->finished_at)) { abort(404); } @@ -31,26 +31,55 @@ public function plannedDetail(MaintenanceHistory $maintenance_history) public function plannedDetailPut(Request $request, MaintenanceHistory $maintenance_history) { - if (!empty($maintenance_history->finished_at)){ + if (!empty($maintenance_history->finished_at)) { 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); + } + + 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, MaintenanceHistory $maintenance_history) + public function history(Request $request) { return view('maintenance.history'); } + + public function historyDetail(Request $request, MaintenanceHistory $maintenance_history) + { + dd($maintenance_history->historyHosts); + } } diff --git a/app/Livewire/Maintenance/Form.php b/app/Livewire/Maintenance/Form.php index b21b7ba..e97845f 100644 --- a/app/Livewire/Maintenance/Form.php +++ b/app/Livewire/Maintenance/Form.php @@ -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; } } diff --git a/app/Livewire/Maintenance/ProgressForm.php b/app/Livewire/Maintenance/ProgressForm.php index be72d84..0aecac8 100644 --- a/app/Livewire/Maintenance/ProgressForm.php +++ b/app/Livewire/Maintenance/ProgressForm.php @@ -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); - if (!empty($this->maintenanceHistory->finished_at)){ + $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) { @@ -39,7 +69,7 @@ public function updatedMaintenanceTaskStatus($value) $notDone = []; foreach ($tasks as $task_history_id => $state) { - if (isset($this->maintenance_task_status_old[$host_history_id][$task_history_id]) && $this->maintenance_task_status_old[$host_history_id][$task_history_id] === $state){ + if (isset($this->maintenance_task_status_old[$host_history_id][$task_history_id]) && $this->maintenance_task_status_old[$host_history_id][$task_history_id] === $state) { continue; } @@ -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', diff --git a/app/Models/MaintenanceHostHistory.php b/app/Models/MaintenanceHostHistory.php index 60e994a..0d6d93f 100644 --- a/app/Models/MaintenanceHostHistory.php +++ b/app/Models/MaintenanceHostHistory.php @@ -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() diff --git a/app/Models/MaintenanceTaskHistory.php b/app/Models/MaintenanceTaskHistory.php index 2883a6c..88176f6 100644 --- a/app/Models/MaintenanceTaskHistory.php +++ b/app/Models/MaintenanceTaskHistory.php @@ -13,6 +13,7 @@ class MaintenanceTaskHistory extends Model 'maintenance_task_id', 'maintenance_history_id', 'maintenance_host_history_id', + 'summary', ]; public function maintenance() diff --git a/database/migrations/2024_07_30_083546_create_maintenance_task_histories_table.php b/database/migrations/2024_07_30_083546_create_maintenance_task_histories_table.php index a4b0fd8..eb06b74 100644 --- a/database/migrations/2024_07_30_083546_create_maintenance_task_histories_table.php +++ b/database/migrations/2024_07_30_083546_create_maintenance_task_histories_table.php @@ -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(); }); } diff --git a/database/migrations/2024_07_30_083607_create_maintenance_host_histories_table.php b/database/migrations/2024_07_30_083607_create_maintenance_host_histories_table.php index dd8bcf2..abd28bb 100644 --- a/database/migrations/2024_07_30_083607_create_maintenance_host_histories_table.php +++ b/database/migrations/2024_07_30_083607_create_maintenance_host_histories_table.php @@ -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(); }); } diff --git a/resources/views/livewire/maintenance/progress-form.blade.php b/resources/views/livewire/maintenance/progress-form.blade.php index bbccf25..e8386ef 100644 --- a/resources/views/livewire/maintenance/progress-form.blade.php +++ b/resources/views/livewire/maintenance/progress-form.blade.php @@ -1,15 +1,19 @@
@foreach ($maintenanceHistory->historyHosts as $historyHost)
-
- {{ $historyHost->host->hostname }} - +
+
+ {{ $historyHost->host->hostname }} +
+
+ +
- @foreach ($historyHost->historyTasks as $historyTasks) - -

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

+ @foreach ($historyHost->historyTasks as $historyTask) + +

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

@endforeach
diff --git a/resources/views/maintenance/planned-detail-done.blade.php b/resources/views/maintenance/planned-detail-done.blade.php index c24742a..5a8d934 100644 --- a/resources/views/maintenance/planned-detail-done.blade.php +++ b/resources/views/maintenance/planned-detail-done.blade.php @@ -4,14 +4,21 @@

{{ __('Planned Maintenance') }}

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

- @foreach ($maintenance_history->historyHosts as $historyHost) - {{ $historyHost->host->hostname }} - @foreach ($historyHost->historyTasks as $historyTasks) - - @if(!isset($maintenance_task_status[$historyHost->id][$historyTasks->id])) - - @endif - @endforeach - @endforeach + + @foreach ($maintenance_history->historyHosts as $historyHost) + @if (in_array($historyHost->id, array_keys($maintenance_host_skipped))) + + @else + @foreach ($historyHost->historyTasks as $historyTask) + @if (!isset($maintenance_task_status[$historyHost->id][$historyTask->id])) + + @else + + @endif + @endforeach + @endif + @endforeach + {{ __('Ukončit Maintenance') }} +
- \ No newline at end of file + diff --git a/resources/views/maintenance/planned-detail.blade.php b/resources/views/maintenance/planned-detail.blade.php index 675183c..abc203d 100644 --- a/resources/views/maintenance/planned-detail.blade.php +++ b/resources/views/maintenance/planned-detail.blade.php @@ -6,7 +6,7 @@

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

@livewire('maintenance.progress-form', ['maintenanceHistory' => $maintenance_history->id], key('progress-form')) - {{ __('Ukončit') }} + {{ __('Pokračovat') }}
diff --git a/routes/web.php b/routes/web.php index 9b67213..7d7e211 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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'); diff --git a/start.sh b/start.sh index 3c9ca7e..d4385e7 100644 --- a/start.sh +++ b/start.sh @@ -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