This commit is contained in:
JonatanRek 2024-07-31 17:04:33 +02:00
parent 571df9a0a4
commit 5d8b29f828
16 changed files with 379 additions and 19 deletions

View File

@ -8,4 +8,9 @@ public function index()
{ {
return view('maintenance.index'); return view('maintenance.index');
} }
public function planned()
{
return view('maintenance.planned');
}
} }

View File

@ -27,8 +27,25 @@ public function handle(Request $request, Closure $next): Response
Menu::make('main-menu', function ($menu) { Menu::make('main-menu', function ($menu) {
$systemRoutes = [ $systemRoutes = [
'boilerplate::ui.home' => [' fas fa-home', 'home'], 'boilerplate::ui.home' => [' fas fa-home', 'home'],
'boilerplate::ui.host' => [' fas fa-server', 'host'], 'boilerplate::ui.planned' => [' fas fa-home', 'maintenance.planned'],
'boilerplate::ui.maintenance' => [' fas fa-calendar', 'maintenance'], ];
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) { foreach ($systemRoutes as $title => $route_data) {

View File

@ -0,0 +1,43 @@
<?php
namespace App\Jobs;
use App\Models\Maintenance;
use App\Models\MaintenanceHistory;
use Cron\CronExpression;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ScheduleNextMaintenance implements ShouldQueue
{
use Queueable;
/**
* Create a new job instance.
*/
public function __construct()
{
//
}
/**
* Execute the job.
*/
public function handle(): void
{
$maintenances = Maintenance::all();
foreach ($maintenances as $maintenance) {
$cron = new CronExpression($maintenance->schedule);
dump($cron->getNextRunDate(null, 2)->format('Y-m-d H:i:s'));
$maintenance->history()->create([
'start_at' => $cron->getNextRunDate(null, 2)
]);
die();
}
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Livewire\MaintenanceHistory;
use App\Models\MaintenanceHistory;
use SteelAnts\DataTable\Livewire\DataTableComponent;
use Illuminate\Database\Eloquent\Builder;
class DataTable extends DataTableComponent
{
public $listeners = [
'maintenanceHistoryAdded' => '$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();
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace App\Livewire\MaintenanceHistory;
use Livewire\Component;
use App\Models\MaintenanceHistory;
class Form extends Component
{
public $model;
public string $maintenance_id;
public string $start_at;
public string $finished_at;
public $action = 'store';
protected function rules()
{
return [
'maintenance_id' => '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');
}
}

View File

@ -14,4 +14,9 @@ class Maintenance extends Model
'description', 'description',
'schedule', 'schedule',
]; ];
public function history()
{
return $this->hasMany(MaintenanceHistory::class);
}
} }

View File

@ -8,4 +8,15 @@
class MaintenanceHistory extends Model class MaintenanceHistory extends Model
{ {
use HasFactory; use HasFactory;
protected $fillable = [
'maintenance_id',
'start_at',
'finished_at',
];
public function maintenance()
{
return $this->BelongsTo(Maintenance::class);
}
} }

View File

@ -24,6 +24,7 @@ public function render(): View|Closure|string
{ {
return view('components.navigation', [ return view('components.navigation', [
'mainMenuItems' => Menu::get('main-menu')->items() ?? [], 'mainMenuItems' => Menu::get('main-menu')->items() ?? [],
'settingsMenuItems' => Menu::get('settings-menu')->items() ?? [],
'systemMenuItems' => Menu::get('system-menu')->items() ?? [], 'systemMenuItems' => Menu::get('system-menu')->items() ?? [],
]); ]);
} }

View File

@ -6,12 +6,14 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": "^8.2", "php": "^8.2",
"dragonmantank/cron-expression": "^3.3",
"laravel/framework": "^11.9", "laravel/framework": "^11.9",
"laravel/sanctum": "^4.0", "laravel/sanctum": "^4.0",
"laravel/tinker": "^2.9", "laravel/tinker": "^2.9",
"steelants/laravel-boilerplate": "^1.2" "steelants/laravel-boilerplate": "^1.2"
}, },
"require-dev": { "require-dev": {
"barryvdh/laravel-debugbar": "^3.13",
"fakerphp/faker": "^1.23", "fakerphp/faker": "^1.23",
"laravel/pint": "^1.13", "laravel/pint": "^1.13",
"laravel/sail": "^1.26", "laravel/sail": "^1.26",

176
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "d901703e92531876ccae1dd19ef6f1cb", "content-hash": "07da4413e8866ce0abc6ed9d0e274725",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@ -1052,16 +1052,16 @@
}, },
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v11.18.1", "version": "v11.19.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/framework.git", "url": "https://github.com/laravel/framework.git",
"reference": "b19ba518c56852567e99fbae9321bc436c2cc5a8" "reference": "5e103d499e9ee5bcfc184412d034c4e516b87085"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/b19ba518c56852567e99fbae9321bc436c2cc5a8", "url": "https://api.github.com/repos/laravel/framework/zipball/5e103d499e9ee5bcfc184412d034c4e516b87085",
"reference": "b19ba518c56852567e99fbae9321bc436c2cc5a8", "reference": "5e103d499e9ee5bcfc184412d034c4e516b87085",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1254,7 +1254,7 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "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", "name": "laravel/prompts",
@ -6067,6 +6067,90 @@
} }
], ],
"packages-dev": [ "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", "name": "fakerphp/faker",
"version": "v1.23.1", "version": "v1.23.1",
@ -6381,6 +6465,74 @@
}, },
"time": "2024-07-22T14:36:50+00:00" "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", "name": "mockery/mockery",
"version": "1.6.12", "version": "1.6.12",
@ -7064,16 +7216,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "11.2.8", "version": "11.2.9",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39" "reference": "c197bbaaca360efda351369bf1fd9cc1ca6bcbf7"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a7a29e8d3113806f18f99d670f580a30e8ffff39", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c197bbaaca360efda351369bf1fd9cc1ca6bcbf7",
"reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39", "reference": "c197bbaaca360efda351369bf1fd9cc1ca6bcbf7",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -7144,7 +7296,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy", "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": [ "funding": [
{ {
@ -7160,7 +7312,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-07-18T14:56:37+00:00" "time": "2024-07-30T11:09:23+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",

View File

@ -16,9 +16,9 @@ public function up(): void
Schema::create('maintenance_histories', function (Blueprint $table) { Schema::create('maintenance_histories', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignIdFor(Maintenance::class); $table->foreignIdFor(Maintenance::class);
$table->foreignIdFor(User::class); $table->foreignIdFor(User::class)->nullable();
$table->datetime('start_at'); $table->datetime('start_at');
$table->datetime('finished_at'); $table->datetime('finished_at')->nullable();
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -49,18 +49,29 @@
<ul class="app-nav nav flex-column"> <ul class="app-nav nav flex-column">
@foreach ($mainMenuItems as $item) @foreach ($mainMenuItems as $item)
<li class="nav-item {{ ($item->isActive() || $item->isUse()) ? 'is-active' : '' }}"> <li class="nav-item {{ $item->isActive() || $item->isUse() ? 'is-active' : '' }}">
<a class="nav-link" href="{{ route($item->route, $item->parameters) }}"> <a class="nav-link" href="{{ route($item->route, $item->parameters) }}">
<i class="nav-link-ico {{ $item->icon }}"></i> <i class="nav-link-ico {{ $item->icon }}"></i>
{{ __($item->title) }} {{ __($item->title) }}
</a> </a>
</li> </li>
@endforeach @endforeach
<li class="mt-4 text-body-secondary"><small>{{ __('boilerplate::ui.settings') }}</small></li>
@foreach ($settingsMenuItems as $item)
<li class="nav-item {{ $item->isActive() || $item->isUse() ? 'is-active' : '' }}">
<a class="nav-link" href="{{ route($item->route, $item->parameters) }}">
<i class="nav-link-ico {{ $item->icon }}"></i>
{{ __($item->title) }}
</a>
</li>
@endforeach
{{-- MAIN NAVIGATION ALL --}} {{-- MAIN NAVIGATION ALL --}}
@auth @auth
<li class="mt-4 text-body-secondary"><small>{{ __('boilerplate::ui.system') }}</small></li> <li class="mt-4 text-body-secondary"><small>{{ __('boilerplate::ui.system') }}</small></li>
@foreach ($systemMenuItems as $item) @foreach ($systemMenuItems as $item)
<li class="nav-item {{ ($item->isActive() || $item->isUse()) ? 'is-active' : '' }}"> <li class="nav-item {{ $item->isActive() || $item->isUse() ? 'is-active' : '' }}">
<a class="nav-link" href="{{ route($item->route, $item->parameters) }}"> <a class="nav-link" href="{{ route($item->route, $item->parameters) }}">
<i class="nav-link-ico {{ $item->icon }}"></i> <i class="nav-link-ico {{ $item->icon }}"></i>
{{ __($item->title) }} {{ __($item->title) }}

View File

@ -0,0 +1,8 @@
<div>
<x-form::form wire:submit.prevent="{{$action}}">
<x-form::input group-class="mb-3" type="text" wire:model="maintenance_id" id="maintenance_id" label="maintenance_id"/>
<x-form::input group-class="mb-3" type="text" wire:model="start_at" id="start_at" label="start_at"/>
<x-form::input group-class="mb-3" type="text" wire:model="finished_at" id="finished_at" label="finished_at"/>
<x-form::button class="btn-primary" type="submit">Create</x-form::button>
</x-form::form>
</div>

View File

@ -0,0 +1,9 @@
<x-layout-app>
<div class="container-xl">
<div class="page-header">
<h1>{{ __('Planned Maintenance') }}</h1>
</div>
@livewire('maintenance-history.data-table', [], key('data-table'))
</div>
</x-layout-app>

View File

@ -8,11 +8,13 @@
}); });
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home'); Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/maintenance/planned', [App\Http\Controllers\MaintenanceController::class, 'planned'])->name('maintenance.planned');
Route::get('/host', [App\Http\Controllers\HostController::class, 'index'])->name('host'); Route::get('/host', [App\Http\Controllers\HostController::class, 'index'])->name('host');
Route::get('/maintenance', [App\Http\Controllers\MaintenanceController::class, 'index'])->name('maintenance'); Route::get('/maintenance', [App\Http\Controllers\MaintenanceController::class, 'index'])->name('maintenance');
Route::prefix('profile')->name('profile.')->middleware(['auth'])->group(function () { Route::prefix('profile')->name('profile.')->middleware(['auth'])->group(function () {
Route::get('/', [App\Http\Controllers\Auth\ProfileController::class, 'index'])->middleware('auth')->name('index'); Route::get('/', [App\Http\Controllers\Auth\ProfileController::class, 'index'])->middleware('auth')->name('index');
Route::put('/update', [App\Http\Controllers\Auth\ProfileController::class, 'update'])->middleware('auth')->name('update'); Route::put('/update', [App\Http\Controllers\Auth\ProfileController::class, 'update'])->middleware('auth')->name('update');

2
storage/debugbar/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore