diff --git a/app/Http/Controllers/MaintenanceController.php b/app/Http/Controllers/MaintenanceController.php index 488068a..5ed5d20 100644 --- a/app/Http/Controllers/MaintenanceController.php +++ b/app/Http/Controllers/MaintenanceController.php @@ -8,4 +8,9 @@ public function index() { return view('maintenance.index'); } + + public function planned() + { + return view('maintenance.planned'); + } } diff --git a/app/Http/Middleware/GenerateMenus.php b/app/Http/Middleware/GenerateMenus.php index 6de8cc5..655c4e5 100644 --- a/app/Http/Middleware/GenerateMenus.php +++ b/app/Http/Middleware/GenerateMenus.php @@ -27,8 +27,25 @@ public function handle(Request $request, Closure $next): Response Menu::make('main-menu', function ($menu) { $systemRoutes = [ 'boilerplate::ui.home' => [' fas fa-home', 'home'], - 'boilerplate::ui.host' => [' fas fa-server', 'host'], - 'boilerplate::ui.maintenance' => [' fas fa-calendar', 'maintenance'], + 'boilerplate::ui.planned' => [' fas fa-home', 'maintenance.planned'], + ]; + + foreach ($systemRoutes as $title => $route_data) { + $icon = $route_data[0]; + $route = $route_data[1]; + + $menu = $menu->add($title, [ + 'id' => strtolower($title), + 'icon' => $icon, + 'route' => $route, + ]); + } + }); + + Menu::make('settings-menu', function ($menu) { + $systemRoutes = [ + 'Host' => [' fas fa-server', 'host'], + 'Maintenance' => [' fas fa-calendar', 'maintenance'], ]; foreach ($systemRoutes as $title => $route_data) { diff --git a/app/Jobs/ScheduleNextMaintenance.php b/app/Jobs/ScheduleNextMaintenance.php new file mode 100644 index 0000000..944cd6a --- /dev/null +++ b/app/Jobs/ScheduleNextMaintenance.php @@ -0,0 +1,43 @@ +schedule); + dump($cron->getNextRunDate(null, 2)->format('Y-m-d H:i:s')); + + + $maintenance->history()->create([ + 'start_at' => $cron->getNextRunDate(null, 2) + ]); + die(); + } + } +} diff --git a/app/Livewire/MaintenanceHistory/DataTable.php b/app/Livewire/MaintenanceHistory/DataTable.php new file mode 100644 index 0000000..cd1b0a0 --- /dev/null +++ b/app/Livewire/MaintenanceHistory/DataTable.php @@ -0,0 +1,32 @@ + '$refresh', + 'closeModal' => '$refresh', + ]; + + public function query(): Builder + { + return MaintenanceHistory::query(); + } + + public function headers(): array + { + return [ + 'maintenance.name' => 'maintenance.name', + 'start_at' => 'start_at', + 'finished_at' => 'finished_at', + ]; + } + + public function remove($maintenancehistory_id){ + MaintenanceHistory::find($maintenancehistory_id)->delete(); + } +} diff --git a/app/Livewire/MaintenanceHistory/Form.php b/app/Livewire/MaintenanceHistory/Form.php new file mode 100644 index 0000000..7cf9969 --- /dev/null +++ b/app/Livewire/MaintenanceHistory/Form.php @@ -0,0 +1,60 @@ + 'required', + 'start_at' => 'required', + 'finished_at' => 'required', + ]; + } + + public function mount ($model = null){ + if (!empty($model)) { + $maintenance-history = MaintenanceHistory::find($model); + + $this->model = $model; + + $this->maintenance_id = $maintenance-history->maintenance_id; + $this->start_at = $maintenance-history->start_at; + $this->finished_at = $maintenance-history->finished_at; + + $this->action = 'update'; + } + } + + public function store() + { + $validatedData = $this->validate(); + MaintenanceHistory::create($validatedData); + $this->dispatch('closeModal'); + } + + public function update() + { + $validatedData = $this->validate(); + $maintenance-history = MaintenanceHistory::find($this->model); + if (!empty($maintenance-history)) { + $maintenance-history->update($validatedData); + } + $this->dispatch('closeModal'); + } + + public function render() + { + return view('livewire.components.maintenance-history.form'); + } +} diff --git a/app/Models/Maintenance.php b/app/Models/Maintenance.php index aa90bf8..0bde4b8 100644 --- a/app/Models/Maintenance.php +++ b/app/Models/Maintenance.php @@ -14,4 +14,9 @@ class Maintenance extends Model 'description', 'schedule', ]; + + public function history() + { + return $this->hasMany(MaintenanceHistory::class); + } } diff --git a/app/Models/MaintenanceHistory.php b/app/Models/MaintenanceHistory.php index 60845fb..d956f08 100644 --- a/app/Models/MaintenanceHistory.php +++ b/app/Models/MaintenanceHistory.php @@ -8,4 +8,15 @@ class MaintenanceHistory extends Model { use HasFactory; + + protected $fillable = [ + 'maintenance_id', + 'start_at', + 'finished_at', + ]; + + public function maintenance() + { + return $this->BelongsTo(Maintenance::class); + } } diff --git a/app/View/Components/Navigation.php b/app/View/Components/Navigation.php index 90126ea..bc91a97 100644 --- a/app/View/Components/Navigation.php +++ b/app/View/Components/Navigation.php @@ -24,6 +24,7 @@ public function render(): View|Closure|string { return view('components.navigation', [ 'mainMenuItems' => Menu::get('main-menu')->items() ?? [], + 'settingsMenuItems' => Menu::get('settings-menu')->items() ?? [], 'systemMenuItems' => Menu::get('system-menu')->items() ?? [], ]); } diff --git a/composer.json b/composer.json index 357e0a0..179e747 100644 --- a/composer.json +++ b/composer.json @@ -6,12 +6,14 @@ "license": "MIT", "require": { "php": "^8.2", + "dragonmantank/cron-expression": "^3.3", "laravel/framework": "^11.9", "laravel/sanctum": "^4.0", "laravel/tinker": "^2.9", "steelants/laravel-boilerplate": "^1.2" }, "require-dev": { + "barryvdh/laravel-debugbar": "^3.13", "fakerphp/faker": "^1.23", "laravel/pint": "^1.13", "laravel/sail": "^1.26", diff --git a/composer.lock b/composer.lock index 04c6632..598c435 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d901703e92531876ccae1dd19ef6f1cb", + "content-hash": "07da4413e8866ce0abc6ed9d0e274725", "packages": [ { "name": "brick/math", @@ -1052,16 +1052,16 @@ }, { "name": "laravel/framework", - "version": "v11.18.1", + "version": "v11.19.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "b19ba518c56852567e99fbae9321bc436c2cc5a8" + "reference": "5e103d499e9ee5bcfc184412d034c4e516b87085" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/b19ba518c56852567e99fbae9321bc436c2cc5a8", - "reference": "b19ba518c56852567e99fbae9321bc436c2cc5a8", + "url": "https://api.github.com/repos/laravel/framework/zipball/5e103d499e9ee5bcfc184412d034c4e516b87085", + "reference": "5e103d499e9ee5bcfc184412d034c4e516b87085", "shasum": "" }, "require": { @@ -1254,7 +1254,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-26T10:39:29+00:00" + "time": "2024-07-30T15:22:41+00:00" }, { "name": "laravel/prompts", @@ -6067,6 +6067,90 @@ } ], "packages-dev": [ + { + "name": "barryvdh/laravel-debugbar", + "version": "v3.13.5", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-debugbar.git", + "reference": "92d86be45ee54edff735e46856f64f14b6a8bb07" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/92d86be45ee54edff735e46856f64f14b6a8bb07", + "reference": "92d86be45ee54edff735e46856f64f14b6a8bb07", + "shasum": "" + }, + "require": { + "illuminate/routing": "^9|^10|^11", + "illuminate/session": "^9|^10|^11", + "illuminate/support": "^9|^10|^11", + "maximebf/debugbar": "~1.22.0", + "php": "^8.0", + "symfony/finder": "^6|^7" + }, + "require-dev": { + "mockery/mockery": "^1.3.3", + "orchestra/testbench-dusk": "^5|^6|^7|^8|^9", + "phpunit/phpunit": "^9.6|^10.5", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.13-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Debugbar\\ServiceProvider" + ], + "aliases": { + "Debugbar": "Barryvdh\\Debugbar\\Facades\\Debugbar" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Barryvdh\\Debugbar\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "PHP Debugbar integration for Laravel", + "keywords": [ + "debug", + "debugbar", + "laravel", + "profiler", + "webprofiler" + ], + "support": { + "issues": "https://github.com/barryvdh/laravel-debugbar/issues", + "source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.13.5" + }, + "funding": [ + { + "url": "https://fruitcake.nl", + "type": "custom" + }, + { + "url": "https://github.com/barryvdh", + "type": "github" + } + ], + "time": "2024-04-12T11:20:37+00:00" + }, { "name": "fakerphp/faker", "version": "v1.23.1", @@ -6381,6 +6465,74 @@ }, "time": "2024-07-22T14:36:50+00:00" }, + { + "name": "maximebf/debugbar", + "version": "v1.22.3", + "source": { + "type": "git", + "url": "https://github.com/maximebf/php-debugbar.git", + "reference": "7aa9a27a0b1158ed5ad4e7175e8d3aee9a818b96" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/7aa9a27a0b1158ed5ad4e7175e8d3aee9a818b96", + "reference": "7aa9a27a0b1158ed5ad4e7175e8d3aee9a818b96", + "shasum": "" + }, + "require": { + "php": "^7.2|^8", + "psr/log": "^1|^2|^3", + "symfony/var-dumper": "^4|^5|^6|^7" + }, + "require-dev": { + "dbrekelmans/bdi": "^1", + "phpunit/phpunit": "^8|^9", + "symfony/panther": "^1|^2.1", + "twig/twig": "^1.38|^2.7|^3.0" + }, + "suggest": { + "kriswallsmith/assetic": "The best way to manage assets", + "monolog/monolog": "Log using Monolog", + "predis/predis": "Redis storage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.22-dev" + } + }, + "autoload": { + "psr-4": { + "DebugBar\\": "src/DebugBar/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maxime Bouroumeau-Fuseau", + "email": "maxime.bouroumeau@gmail.com", + "homepage": "http://maximebf.com" + }, + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Debug bar in the browser for php application", + "homepage": "https://github.com/maximebf/php-debugbar", + "keywords": [ + "debug", + "debugbar" + ], + "support": { + "issues": "https://github.com/maximebf/php-debugbar/issues", + "source": "https://github.com/maximebf/php-debugbar/tree/v1.22.3" + }, + "time": "2024-04-03T19:39:26+00:00" + }, { "name": "mockery/mockery", "version": "1.6.12", @@ -7064,16 +7216,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.2.8", + "version": "11.2.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39" + "reference": "c197bbaaca360efda351369bf1fd9cc1ca6bcbf7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a7a29e8d3113806f18f99d670f580a30e8ffff39", - "reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c197bbaaca360efda351369bf1fd9cc1ca6bcbf7", + "reference": "c197bbaaca360efda351369bf1fd9cc1ca6bcbf7", "shasum": "" }, "require": { @@ -7144,7 +7296,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.2.8" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.2.9" }, "funding": [ { @@ -7160,7 +7312,7 @@ "type": "tidelift" } ], - "time": "2024-07-18T14:56:37+00:00" + "time": "2024-07-30T11:09:23+00:00" }, { "name": "sebastian/cli-parser", diff --git a/database/migrations/2024_07_30_083555_create_maintenance_histories_table.php b/database/migrations/2024_07_30_083555_create_maintenance_histories_table.php index 274aede..1a25764 100644 --- a/database/migrations/2024_07_30_083555_create_maintenance_histories_table.php +++ b/database/migrations/2024_07_30_083555_create_maintenance_histories_table.php @@ -16,9 +16,9 @@ public function up(): void Schema::create('maintenance_histories', function (Blueprint $table) { $table->id(); $table->foreignIdFor(Maintenance::class); - $table->foreignIdFor(User::class); + $table->foreignIdFor(User::class)->nullable(); $table->datetime('start_at'); - $table->datetime('finished_at'); + $table->datetime('finished_at')->nullable(); $table->timestamps(); }); } diff --git a/resources/views/components/navigation.blade.php b/resources/views/components/navigation.blade.php index 7fd2ee6..bc0c465 100644 --- a/resources/views/components/navigation.blade.php +++ b/resources/views/components/navigation.blade.php @@ -49,18 +49,29 @@