diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 9e0e442..e0fa251 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -8,4 +8,6 @@ use SteelAnts\LaravelAuth\Traits\Authentication; class AuthController { use Authentication; + + protected string $redirectTo = "dashboard"; } diff --git a/app/Http/Controllers/MaintenanceController.php b/app/Http/Controllers/MaintenanceController.php index 16a524e..b26f082 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 Carbon\Carbon; use Illuminate\Http\Request; class MaintenanceController extends BaseController @@ -19,6 +20,10 @@ class MaintenanceController extends BaseController public function plannedDetail(MaintenanceHistory $maintenance_history) { + if (!empty($maintenance_history->finished_at)){ + abort(404); + } + return view('maintenance.planned-detail', [ 'maintenance_history' => $maintenance_history, ]); @@ -26,9 +31,26 @@ class MaintenanceController extends BaseController public function plannedDetailPut(Request $request, MaintenanceHistory $maintenance_history) { + 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_state' => $request->input('test'), + 'maintenance_task_status' => $request->input('maintenance_task_status'), ]); } + + public function plannedDetailFinishPost(Request $request, MaintenanceHistory $maintenance_history) + { + dd(); + } + + public function history(Request $request, MaintenanceHistory $maintenance_history) + { + return view('maintenance.history'); + } } diff --git a/app/Http/Middleware/GenerateMenus.php b/app/Http/Middleware/GenerateMenus.php index fd27dd3..eda83c5 100644 --- a/app/Http/Middleware/GenerateMenus.php +++ b/app/Http/Middleware/GenerateMenus.php @@ -26,8 +26,9 @@ class GenerateMenus Menu::make('main-menu', function ($menu) { $systemRoutes = [ - 'boilerplate::ui.home' => [' fas fa-home', 'dashboard'], - 'boilerplate::ui.planned' => [' fas fa-home', 'maintenance.planned'], + 'ui.dashboard' => [' fas fa-home', 'dashboard'], + 'ui.planned' => [' fas fa-home', 'maintenance.planned'], + 'ui.history' => [' fas fa-home', 'maintenance.history'], ]; foreach ($systemRoutes as $title => $route_data) { diff --git a/app/Jobs/ScheduleNextMaintenance.php b/app/Jobs/ScheduleNextMaintenance.php index f24463e..abf36b5 100644 --- a/app/Jobs/ScheduleNextMaintenance.php +++ b/app/Jobs/ScheduleNextMaintenance.php @@ -36,6 +36,7 @@ class ScheduleNextMaintenance implements ShouldQueue $cron = new CronCronExpression($maintenance->schedule); $maintenancePlanned = $maintenance->history()->create([ 'start_at' => Carbon::createFromTimestamp($cron->getNext()), + 'guestor_id' => $maintenance->guestor_id, ]); $maintenancePlanned->refresh(); diff --git a/app/Livewire/Maintenance/DataTable.php b/app/Livewire/Maintenance/DataTable.php index 1311873..a7ca106 100644 --- a/app/Livewire/Maintenance/DataTable.php +++ b/app/Livewire/Maintenance/DataTable.php @@ -22,10 +22,20 @@ class DataTable extends DataTableComponent return [ 'name' => 'name', 'description' => 'description', - 'schedule' => 'schedule', + 'schedule' => 'schedule/offset', ]; } + public function renderColumnSchedule($value, $row) + { + return e(!empty($value) ? $value : $row['blocking_maintenance_offset']); + } + + public function renderColumnDescription($value, $row) + { + return e(!empty($value) ? mb_strimwidth(strip_tags($value), 0, 50, "...") : ""); + } + public function remove($maintenance_id){ Maintenance::find($maintenance_id)->delete(); } diff --git a/app/Livewire/Maintenance/Form.php b/app/Livewire/Maintenance/Form.php index 3ce96e5..b21b7ba 100644 --- a/app/Livewire/Maintenance/Form.php +++ b/app/Livewire/Maintenance/Form.php @@ -7,6 +7,7 @@ use Livewire\Component; use App\Models\Maintenance; use App\Models\MaintenanceTask; use App\Models\Task; +use App\Models\User; class Form extends Component { @@ -23,12 +24,26 @@ class Form extends Component public $hosts_tasks = []; public $hosts_tasks_available = []; + public int $guestor_id; + public $guestor_available = []; + + public $blocking_maintenance_id = null; + public $maintenances_available = []; + + public $blocking_maintenance_offset = null; + + public int $duration = 0; + protected function rules() { return [ 'name' => 'required', + 'guestor_id' => 'required|exists:users,id', + 'blocking_maintenance_id' => 'exists:maintenances,id|nullable', + 'blocking_maintenance_offset' => 'nullable', 'description' => 'required', - 'schedule' => 'required', + 'schedule' => 'nullable', + 'duration' => 'required|max:24', ]; } @@ -36,6 +51,10 @@ class Form extends Component { $this->hosts_available = Host::all()->pluck('hostname', 'id')->toArray(); $this->hosts_tasks_available = Task::all()->pluck('name', 'id')->toArray(); + $this->guestor_available = User::all()->pluck('name', 'id')->toArray(); + $this->maintenances_available = Maintenance::where('id', '!=', $model)->pluck('name', 'id')->toArray(); + $this->maintenances_available = [null => 'Select blocking maintenance...'] + $this->maintenances_available; + if (!empty($model)) { $maintenance = Maintenance::find($model); @@ -45,6 +64,11 @@ class Form extends Component $this->name = $maintenance->name; $this->description = $maintenance->description; $this->schedule = $maintenance->schedule; + $this->guestor_id = $maintenance->guestor_id; + $this->blocking_maintenance_id = $maintenance->blocking_maintenance_id ?? null; + $this->blocking_maintenance_offset = $maintenance->blocking_maintenance_offset ?? null; + + $this->duration = $maintenance->duration ; $this->hosts = $maintenance->hosts()->pluck('hosts.id')->toArray(); foreach ($maintenance->tasks as $task) { @@ -71,6 +95,7 @@ class Form extends Component $validatedData = $this->validate(); $maintenance = Maintenance::create($validatedData); $hosts = Host::whereIn('id', $this->hosts)->get(); + foreach ($hosts as $key => $host) { $maintenance->hosts()->attach($host); $tasks = Task::whereIn('id', $this->hosts_tasks[$host->id])->get(); diff --git a/app/Livewire/Maintenance/ProgressForm.php b/app/Livewire/Maintenance/ProgressForm.php index eb4838f..be72d84 100644 --- a/app/Livewire/Maintenance/ProgressForm.php +++ b/app/Livewire/Maintenance/ProgressForm.php @@ -20,6 +20,9 @@ class ProgressForm extends Component public function mount(int $maintenanceHistory) { $this->maintenanceHistory = self::getMaintenanceHistory($maintenanceHistory); + if (!empty($this->maintenanceHistory->finished_at)){ + abort(404); + } foreach ($this->maintenanceHistory->historyHosts as $maintenanceHost) { foreach ($maintenanceHost->historyTasks as $maintenanceTask) { diff --git a/app/Livewire/MaintenanceHistory/DataTable.php b/app/Livewire/MaintenanceHistory/DataTable.php index b9d3ee4..1274c98 100644 --- a/app/Livewire/MaintenanceHistory/DataTable.php +++ b/app/Livewire/MaintenanceHistory/DataTable.php @@ -8,6 +8,8 @@ use Illuminate\Database\Eloquent\Builder; class DataTable extends DataTableComponent { + public string $type = "planned"; + public $listeners = [ 'maintenanceHistoryAdded' => '$refresh', 'closeModal' => '$refresh', @@ -15,16 +17,31 @@ class DataTable extends DataTableComponent public function query(): Builder { - return MaintenanceHistory::query(); + $query = MaintenanceHistory::query(); + + if ($this->type == "planned") { + $query->whereNull('finished_at'); + } elseif ($this->type == "history") { + $query->whereNotNull('finished_at'); + } + + return $query; } public function headers(): array { - return [ + $headers = [ 'maintenance.name' => 'maintenance.name', 'start_at' => 'start_at', - 'finished_at' => 'finished_at', ]; + + if ($this->type == "planned") { + $headers['guestor.name'] = 'guestor'; + } else { + $headers['finished_at'] = 'finished_at'; + } + + return $headers; } public function remove($maintenancehistory_id) @@ -34,7 +51,12 @@ class DataTable extends DataTableComponent public function renderColumnMaintenanceName($val, $row) { - $ret = '' . e($val) . ''; + if ($this->type == "planned") { + $ret = '' . e($val) . ''; + } else { + $ret = '' . e($val) . ''; + } + return $ret; } diff --git a/app/Livewire/Task/DataTable.php b/app/Livewire/Task/DataTable.php index 88b52af..7423071 100644 --- a/app/Livewire/Task/DataTable.php +++ b/app/Livewire/Task/DataTable.php @@ -25,6 +25,11 @@ class DataTable extends DataTableComponent ]; } + public function renderColumnDescription($value, $row) + { + return e(!empty($value) ? mb_strimwidth(strip_tags($value), 0, 50, "...") : ""); + } + public function remove($task_id){ Task::find($task_id)->delete(); } diff --git a/app/Models/Maintenance.php b/app/Models/Maintenance.php index 57abc06..24d07dc 100644 --- a/app/Models/Maintenance.php +++ b/app/Models/Maintenance.php @@ -13,6 +13,10 @@ class Maintenance extends Model 'name', 'description', 'schedule', + 'guestor_id', + 'blocking_maintenance_id', + 'duration', + 'blocking_maintenance_offset', ]; public function hosts() @@ -29,4 +33,9 @@ class Maintenance extends Model { return $this->hasMany(MaintenanceTask::class,); } + + public function guestor() + { + return $this->BelongsTo(User::class, 'guestor_id'); + } } diff --git a/app/Models/MaintenanceHistory.php b/app/Models/MaintenanceHistory.php index ddd1a56..1f3e5bc 100644 --- a/app/Models/MaintenanceHistory.php +++ b/app/Models/MaintenanceHistory.php @@ -13,6 +13,7 @@ class MaintenanceHistory extends Model 'maintenance_id', 'start_at', 'finished_at', + 'guestor_id', ]; public function maintenance() @@ -24,4 +25,9 @@ class MaintenanceHistory extends Model { return $this->hasMany(MaintenanceHostHistory::class); } + + public function guestor() + { + return $this->BelongsTo(User::class, 'guestor_id'); + } } diff --git a/database/migrations/2024_08_08_051731_add_guestor_and_duration_to_maintenance_table.php b/database/migrations/2024_08_08_051731_add_guestor_and_duration_to_maintenance_table.php new file mode 100644 index 0000000..407d418 --- /dev/null +++ b/database/migrations/2024_08_08_051731_add_guestor_and_duration_to_maintenance_table.php @@ -0,0 +1,33 @@ +foreignIdFor(User::class, 'guestor_id'); + $table->foreignIdFor(Maintenance::class, 'blocking_maintenance_id')->nullable(); + $table->string('blocking_maintenance_offset')->nullable(); + $table->integer('duration'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('maintenances', function (Blueprint $table) { + // + }); + } +}; diff --git a/database/migrations/2024_08_08_082255_add_guestor_maintenance_history_table.php b/database/migrations/2024_08_08_082255_add_guestor_maintenance_history_table.php new file mode 100644 index 0000000..5e42aea --- /dev/null +++ b/database/migrations/2024_08_08_082255_add_guestor_maintenance_history_table.php @@ -0,0 +1,28 @@ +foreignIdFor(User::class, 'guestor_id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('maintenance_histories', function (Blueprint $table) { + }); + } +}; diff --git a/lang/en/ui.php b/lang/en/ui.php new file mode 100644 index 0000000..f517f26 --- /dev/null +++ b/lang/en/ui.php @@ -0,0 +1,7 @@ + 'Dashboard', + 'planned' => 'Planned', + 'history' => 'History', +]; diff --git a/resources/views/livewire/maintenance/form.blade.php b/resources/views/livewire/maintenance/form.blade.php index e906b69..1ab5fe8 100644 --- a/resources/views/livewire/maintenance/form.blade.php +++ b/resources/views/livewire/maintenance/form.blade.php @@ -1,14 +1,23 @@
+ + + + @if(empty($blocking_maintenance_id)) + @else + + @endif + + @foreach($hosts as $key => $host_id) - + @endforeach Create -
+ \ No newline at end of file diff --git a/resources/views/livewire/maintenance/progress-form.blade.php b/resources/views/livewire/maintenance/progress-form.blade.php index 24cbceb..bbccf25 100644 --- a/resources/views/livewire/maintenance/progress-form.blade.php +++ b/resources/views/livewire/maintenance/progress-form.blade.php @@ -8,7 +8,7 @@
@foreach ($historyHost->historyTasks as $historyTasks) - +

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

@endforeach
diff --git a/resources/views/maintenance/history.blade.php b/resources/views/maintenance/history.blade.php new file mode 100644 index 0000000..58ece70 --- /dev/null +++ b/resources/views/maintenance/history.blade.php @@ -0,0 +1,9 @@ + +
+ + + @livewire('maintenance-history.data-table', ['type' => 'history'], key('data-table')) +
+
diff --git a/resources/views/maintenance/planned-detail-done.blade.php b/resources/views/maintenance/planned-detail-done.blade.php index 0df61b6..c24742a 100644 --- a/resources/views/maintenance/planned-detail-done.blade.php +++ b/resources/views/maintenance/planned-detail-done.blade.php @@ -5,10 +5,13 @@

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

@foreach ($maintenance_history->historyHosts as $historyHost) - {{ $historyHost->host->hostname }} - @foreach ($historyHost->historyTasks as $historyTasks) - - @endforeach + {{ $historyHost->host->hostname }} + @foreach ($historyHost->historyTasks as $historyTasks) + + @if(!isset($maintenance_task_status[$historyHost->id][$historyTasks->id])) + + @endif + @endforeach @endforeach - + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 4ae7295..9b67213 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,6 +11,7 @@ Route::get('/dashboard', [App\Http\Controllers\DashboardController::class, 'inde 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('/maintenance/history/', [App\Http\Controllers\MaintenanceController::class, 'history'])->name('maintenance.history'); Route::get('/host', [App\Http\Controllers\HostController::class, 'index'])->name('host');