Additional Fixes
This commit is contained in:
parent
5d8b29f828
commit
bb450e3a80
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\MaintenanceHistory;
|
||||||
|
|
||||||
class MaintenanceController extends BaseController
|
class MaintenanceController extends BaseController
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
@ -13,4 +15,11 @@ public function planned()
|
|||||||
{
|
{
|
||||||
return view('maintenance.planned');
|
return view('maintenance.planned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function plannedDetail(MaintenanceHistory $maintenance_history)
|
||||||
|
{
|
||||||
|
return view('maintenance.planned-detail', [
|
||||||
|
'maintenance_history' => $maintenance_history,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Livewire\Maintenance;
|
namespace App\Livewire\Maintenance;
|
||||||
|
|
||||||
|
use App\Models\Host;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use App\Models\Maintenance;
|
use App\Models\Maintenance;
|
||||||
|
|
||||||
@ -13,6 +15,10 @@ class Form extends Component
|
|||||||
|
|
||||||
public $action = 'store';
|
public $action = 'store';
|
||||||
|
|
||||||
|
public $hosts = [];
|
||||||
|
public $hosts_available = [];
|
||||||
|
|
||||||
|
|
||||||
protected function rules()
|
protected function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -22,7 +28,9 @@ protected function rules()
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mount ($model = null){
|
public function mount($model = null)
|
||||||
|
{
|
||||||
|
$this->hosts_available = Host::all()->pluck('hostname', 'id')->toArray();
|
||||||
if (!empty($model)) {
|
if (!empty($model)) {
|
||||||
$maintenance = Maintenance::find($model);
|
$maintenance = Maintenance::find($model);
|
||||||
|
|
||||||
@ -31,6 +39,7 @@ public function mount ($model = null){
|
|||||||
$this->name = $maintenance->name;
|
$this->name = $maintenance->name;
|
||||||
$this->description = $maintenance->description;
|
$this->description = $maintenance->description;
|
||||||
$this->schedule = $maintenance->schedule;
|
$this->schedule = $maintenance->schedule;
|
||||||
|
$this->hosts = $maintenance->hosts()->pluck('hosts.id')->toArray();
|
||||||
|
|
||||||
$this->action = 'update';
|
$this->action = 'update';
|
||||||
}
|
}
|
||||||
@ -39,7 +48,11 @@ public function mount ($model = null){
|
|||||||
public function store()
|
public function store()
|
||||||
{
|
{
|
||||||
$validatedData = $this->validate();
|
$validatedData = $this->validate();
|
||||||
Maintenance::create($validatedData);
|
$maintenance = Maintenance::create($validatedData);
|
||||||
|
$hosts = Host::whereIn('id', $this->hosts)->get();
|
||||||
|
foreach ($hosts as $key => $host) {
|
||||||
|
$maintenance->hosts()->attach($host);
|
||||||
|
}
|
||||||
$this->dispatch('closeModal');
|
$this->dispatch('closeModal');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,9 +60,16 @@ public function update()
|
|||||||
{
|
{
|
||||||
$validatedData = $this->validate();
|
$validatedData = $this->validate();
|
||||||
$maintenance = Maintenance::find($this->model);
|
$maintenance = Maintenance::find($this->model);
|
||||||
|
$maintenance->hosts()->whereNotIn('host_id', $this->hosts)->delete();
|
||||||
|
|
||||||
if (!empty($maintenance)) {
|
if (!empty($maintenance)) {
|
||||||
$maintenance->update($validatedData);
|
$maintenance->update($validatedData);
|
||||||
|
$hosts = Host::whereIn('id', $this->hosts)->whereNotIn('id', $maintenance->hosts()->pluck('hosts.id')->toArray())->get();
|
||||||
|
foreach ($hosts as $key => $host) {
|
||||||
|
$maintenance->hosts()->attach($host);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->dispatch('closeModal');
|
$this->dispatch('closeModal');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,4 +77,14 @@ public function render()
|
|||||||
{
|
{
|
||||||
return view('livewire.maintenance.form');
|
return view('livewire.maintenance.form');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addHost()
|
||||||
|
{
|
||||||
|
$this->hosts[] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeHost($id)
|
||||||
|
{
|
||||||
|
unset($this->hosts[$id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Livewire\MaintenanceHistory;
|
namespace App\Livewire\MaintenanceHistory;
|
||||||
|
|
||||||
use App\Models\MaintenanceHistory;
|
use App\Models\MaintenanceHistory;
|
||||||
@ -26,7 +27,14 @@ public function headers(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove($maintenancehistory_id){
|
public function remove($maintenancehistory_id)
|
||||||
|
{
|
||||||
MaintenanceHistory::find($maintenancehistory_id)->delete();
|
MaintenanceHistory::find($maintenancehistory_id)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function renderColumnMaintenanceName($val, $row)
|
||||||
|
{
|
||||||
|
$ret = '<a href="' . route('maintenance.planned.detail', $row['id']) . '">' . e($val) . '</a>';
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,4 +19,9 @@ public function history()
|
|||||||
{
|
{
|
||||||
return $this->hasMany(MaintenanceHistory::class);
|
return $this->hasMany(MaintenanceHistory::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hosts()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Host::class, "maintenance_host", "maintenance_id", "host_id" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
10
app/Models/MaintenanceHost.php
Normal file
10
app/Models/MaintenanceHost.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||||
|
|
||||||
|
class MaintenanceHost extends Pivot
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Maintenance;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@ -13,7 +14,8 @@ public function up(): void
|
|||||||
{
|
{
|
||||||
Schema::create('maintenance_tasks', function (Blueprint $table) {
|
Schema::create('maintenance_tasks', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('hostname');
|
$table->foreignIdFor(Maintenance::class);
|
||||||
|
$table->string('name');
|
||||||
$table->text('description');
|
$table->text('description');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Host;
|
||||||
|
use App\Models\Maintenance;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('maintenance_host', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignIdFor(Maintenance::class);
|
||||||
|
$table->foreignIdFor(Host::class);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('maintenance_host');
|
||||||
|
}
|
||||||
|
};
|
@ -1,8 +1,10 @@
|
|||||||
<div>
|
<div>
|
||||||
<x-form::form wire:submit.prevent="{{$action}}">
|
<x-form::form wire:submit.prevent="{{ $action }}">
|
||||||
<x-form::input group-class="mb-3" type="text" wire:model="name" id="name" label="name"/>
|
<x-form::input group-class="mb-3" type="text" wire:model="name" id="name" label="name" />
|
||||||
<x-form::quill group-class="mb-3" type="text" wire:model="description" id="description" label="description"/>
|
<x-form::quill group-class="mb-3" type="text" wire:model="description" id="description" label="description" />
|
||||||
<x-form::input group-class="mb-3" type="text" wire:model="schedule" id="schedule" label="schedule"/>
|
<x-form::input group-class="mb-3" type="text" wire:model="schedule" id="schedule" label="schedule" />
|
||||||
|
<x-form::select group-class="mb-3" wire:model="hosts" label="Livewire Select" :options="$hosts_available" placeholder="Select value..." multiple />
|
||||||
<x-form::button class="btn-primary" type="submit">Create</x-form::button>
|
<x-form::button class="btn-primary" type="submit">Create</x-form::button>
|
||||||
|
@dump($hosts)
|
||||||
</x-form::form>
|
</x-form::form>
|
||||||
</div>
|
</div>
|
||||||
|
20
resources/views/maintenance/planned-detail.blade.php
Normal file
20
resources/views/maintenance/planned-detail.blade.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<x-layout-app>
|
||||||
|
<div class="container-xl">
|
||||||
|
<div class="page-header">
|
||||||
|
<h1>{{ __('Planned Maintenance') }}</h1>
|
||||||
|
</div>
|
||||||
|
<p>{!! $maintenance_history->maintenance->description !!}</p>
|
||||||
|
@foreach ($maintenance_history->maintenance->hosts as $host)
|
||||||
|
<div class="mb-3">
|
||||||
|
<div class="btn-toggle btn py-3 w-100 bg-primary text-start" style="--bs-bg-opacity: .2;" data-bs-toggle="collapse" data-bs-target="#collapse{{ $host->id }}">
|
||||||
|
<b>{{ $host->hostname }}</b>
|
||||||
|
</div>
|
||||||
|
<div class="collapse" id="collapse{{ $host->id }}">
|
||||||
|
<div class="card card-body mt-2">
|
||||||
|
<h6>Description</h6>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
</x-layout-app>
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
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('/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::get('/host', [App\Http\Controllers\HostController::class, 'index'])->name('host');
|
Route::get('/host', [App\Http\Controllers\HostController::class, 'index'])->name('host');
|
||||||
|
Loading…
Reference in New Issue
Block a user