Progress
This commit is contained in:
parent
d0fbb5d5c1
commit
ecb255fc6a
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Models\Maintenance;
|
||||
use App\Models\MaintenanceHistory;
|
||||
use App\Models\MaintenanceTaskHistory;
|
||||
use Cron\CronExpression;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@ -42,16 +43,20 @@ public function handle(): void
|
||||
]);
|
||||
$maintenancePlanned->refresh();
|
||||
|
||||
$tasks = $maintenancePlanned->tasks;
|
||||
if(!empty($tasks)){
|
||||
dd($tasks);
|
||||
$hosts = $maintenance->hosts;
|
||||
foreach ($hosts as $key => $host) {
|
||||
$maintenancePlannedHost = $maintenancePlanned->historyHosts()->create([
|
||||
'host_id' => $host->id
|
||||
]);
|
||||
|
||||
$tasks = $maintenance->tasks;
|
||||
foreach ($tasks as $key => $task) {
|
||||
$maintenancePlanned->tasks()->create([
|
||||
'host_id' => $task->host_id,
|
||||
$maintenancePlannedHost->historyTasks()->create([
|
||||
'maintenance_task_id' => $task->id,
|
||||
'maintenance_history_id' => $maintenancePlanned->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
use Livewire\Component;
|
||||
use App\Models\Maintenance;
|
||||
use App\Models\MaintenanceTask;
|
||||
use Illuminate\Console\View\Components\Task;
|
||||
use App\Models\Task;
|
||||
|
||||
class Form extends Component
|
||||
{
|
||||
@ -35,7 +35,7 @@ protected function rules()
|
||||
public function mount($model = null)
|
||||
{
|
||||
$this->hosts_available = Host::all()->pluck('hostname', 'id')->toArray();
|
||||
$this->hosts_tasks_available = MaintenanceTask::all()->pluck('name', 'id')->toArray();
|
||||
$this->hosts_tasks_available = Task::all()->pluck('name', 'id')->toArray();
|
||||
|
||||
if (!empty($model)) {
|
||||
$maintenance = Maintenance::find($model);
|
||||
@ -48,7 +48,7 @@ public function mount($model = null)
|
||||
|
||||
$this->hosts = $maintenance->hosts()->pluck('hosts.id')->toArray();
|
||||
foreach ($maintenance->tasks as $task) {
|
||||
$this->hosts_tasks_available[$task->host_id][] = $task->id;
|
||||
$this->hosts_tasks[$task->host_id][] = $task->task_id;
|
||||
}
|
||||
|
||||
$this->action = 'update';
|
||||
@ -79,10 +79,14 @@ public function update()
|
||||
$maintenance->hosts()->attach($host);
|
||||
}
|
||||
$maintenance->refresh();
|
||||
|
||||
foreach ($maintenance->hosts as $host) {
|
||||
foreach ($this->hosts_tasks[$host->id] as $task_id => $host_task_name) {
|
||||
$host->tasks()->create([
|
||||
'task_id' => $task_id
|
||||
$alreadyUsedHosts = $maintenance->tasks()->where('host_id', $host->id)->distinct('maintenance_tasks.task_id')->pluck('maintenance_tasks.task_id')->toArray();
|
||||
$tasks = Task::whereIn('id', $this->hosts_tasks[$host->id])->whereNotIn('id', $alreadyUsedHosts)->get();
|
||||
foreach ($tasks as $key => $task) {
|
||||
$maintenance->tasks()->create([
|
||||
'task_id' => $task->id,
|
||||
'host_id' => $host->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
<?php
|
||||
namespace App\Livewire\MaintenanceTask;
|
||||
namespace App\Livewire\Task;
|
||||
|
||||
use App\Models\MaintenanceTask;
|
||||
use App\Models\Task;
|
||||
use SteelAnts\DataTable\Livewire\DataTableComponent;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class DataTable extends DataTableComponent
|
||||
{
|
||||
public $listeners = [
|
||||
'maintenancetaskAdded' => '$refresh',
|
||||
'taskAdded' => '$refresh',
|
||||
'closeModal' => '$refresh',
|
||||
];
|
||||
|
||||
public function query(): Builder
|
||||
{
|
||||
return MaintenanceTask::query();
|
||||
return Task::query();
|
||||
}
|
||||
|
||||
public function headers(): array
|
||||
@ -25,8 +25,8 @@ public function headers(): array
|
||||
];
|
||||
}
|
||||
|
||||
public function remove($maintenancetask_id){
|
||||
MaintenanceTask::find($maintenancetask_id)->delete();
|
||||
public function remove($task_id){
|
||||
Task::find($task_id)->delete();
|
||||
}
|
||||
|
||||
public function actions($item)
|
||||
@ -47,8 +47,8 @@ public function actions($item)
|
||||
];
|
||||
}
|
||||
|
||||
public function edit($maintenancetask_id)
|
||||
public function edit($task_id)
|
||||
{
|
||||
$this->dispatch('openModal', 'maintenance-task.form', __('boilerplate::maintenance-task.edit'), ['model' => $maintenancetask_id]);
|
||||
$this->dispatch('openModal', 'task.form', __('boilerplate::task.edit'), ['model' => $task_id]);
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
<?php
|
||||
namespace App\Livewire\MaintenanceTask;
|
||||
namespace App\Livewire\Task;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\MaintenanceTask;
|
||||
use App\Models\Task;
|
||||
|
||||
class Form extends Component
|
||||
{
|
||||
public $model;
|
||||
public string $maintenance_id;
|
||||
public string $name;
|
||||
public string $description = "";
|
||||
|
||||
@ -16,7 +15,6 @@ class Form extends Component
|
||||
protected function rules()
|
||||
{
|
||||
return [
|
||||
'maintenance_id' => 'required',
|
||||
'name' => 'required',
|
||||
'description' => 'required',
|
||||
];
|
||||
@ -24,13 +22,12 @@ protected function rules()
|
||||
|
||||
public function mount ($model = null){
|
||||
if (!empty($model)) {
|
||||
$maintenanceTask = MaintenanceTask::find($model);
|
||||
$task = Task::find($model);
|
||||
|
||||
$this->model = $model;
|
||||
|
||||
$this->maintenance_id = $maintenanceTask->maintenance_id;
|
||||
$this->name = $maintenanceTask->name;
|
||||
$this->description = $maintenanceTask->description;
|
||||
$this->name = $task->name;
|
||||
$this->description = $task->description;
|
||||
|
||||
$this->action = 'update';
|
||||
}
|
||||
@ -39,22 +36,22 @@ public function mount ($model = null){
|
||||
public function store()
|
||||
{
|
||||
$validatedData = $this->validate();
|
||||
MaintenanceTask::create($validatedData);
|
||||
Task::create($validatedData);
|
||||
$this->dispatch('closeModal');
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$validatedData = $this->validate();
|
||||
$maintenanceTask = MaintenanceTask::find($this->model);
|
||||
if (!empty($maintenanceTask)) {
|
||||
$maintenanceTask->update($validatedData);
|
||||
$task = Task::find($this->model);
|
||||
if (!empty($task)) {
|
||||
$task->update($validatedData);
|
||||
}
|
||||
$this->dispatch('closeModal');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.maintenance-task.form');
|
||||
return view('livewire.task.form');
|
||||
}
|
||||
}
|
@ -15,16 +15,16 @@ class Maintenance extends Model
|
||||
'schedule',
|
||||
];
|
||||
|
||||
public function history()
|
||||
{
|
||||
return $this->hasMany(MaintenanceHistory::class);
|
||||
}
|
||||
|
||||
public function hosts()
|
||||
{
|
||||
return $this->belongsToMany(Host::class, "maintenance_host", "maintenance_id", "host_id" );
|
||||
}
|
||||
|
||||
public function history()
|
||||
{
|
||||
return $this->hasMany(MaintenanceHistory::class);
|
||||
}
|
||||
|
||||
public function tasks()
|
||||
{
|
||||
return $this->hasMany(MaintenanceTask::class,);
|
||||
|
@ -19,4 +19,9 @@ public function maintenance()
|
||||
{
|
||||
return $this->BelongsTo(Maintenance::class);
|
||||
}
|
||||
|
||||
public function historyHosts()
|
||||
{
|
||||
return $this->hasMany(MaintenanceHostHistory::class);
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,17 @@ class MaintenanceHostHistory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function hosts()
|
||||
protected $fillable = [
|
||||
'maintenance_history_id',
|
||||
'host_id',
|
||||
];
|
||||
|
||||
public function host()
|
||||
{
|
||||
return $this->belongsToMany(MaintenanceHostHistory::class);
|
||||
return $this->belongsTo(Host::class);
|
||||
}
|
||||
|
||||
public function tasks()
|
||||
public function historyTasks()
|
||||
{
|
||||
return $this->hasMany(MaintenanceTaskHistory::class);
|
||||
}
|
||||
|
@ -12,7 +12,12 @@ class MaintenanceTask extends Model
|
||||
protected $fillable = [
|
||||
'maintenance_id',
|
||||
'host_id',
|
||||
'name',
|
||||
'description',
|
||||
'task_id',
|
||||
];
|
||||
|
||||
|
||||
public function task()
|
||||
{
|
||||
return $this->belongsTo(Task::class);
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,19 @@ class MaintenanceTaskHistory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function task()
|
||||
protected $fillable = [
|
||||
'maintenance_task_id',
|
||||
'maintenance_history_id',
|
||||
'maintenance_host_history_id',
|
||||
];
|
||||
|
||||
public function maintenance()
|
||||
{
|
||||
return $this->BelongsTo(MaintenanceTask::class);
|
||||
return $this->BelongsTo(MaintenanceHistory::class);
|
||||
}
|
||||
|
||||
public function maintenanceTask()
|
||||
{
|
||||
return $this->belongsTo(MaintenanceTask::class);
|
||||
}
|
||||
}
|
||||
|
@ -8,4 +8,9 @@
|
||||
class Task extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public function up(): void
|
||||
$table->id();
|
||||
$table->foreignIdFor(Maintenance::class);
|
||||
$table->foreignIdFor(Task::class);
|
||||
$table->foreignIdFor(Host::class);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use App\Models\Host;
|
||||
use App\Models\MaintenanceHistory;
|
||||
use App\Models\MaintenanceHostHistory;
|
||||
use App\Models\MaintenanceTask;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
@ -18,7 +19,7 @@ public function up(): void
|
||||
$table->id();
|
||||
$table->foreignIdFor(MaintenanceTask::class);
|
||||
$table->foreignIdFor(MaintenanceHistory::class);
|
||||
$table->foreignIdFor(Host::class);
|
||||
$table->foreignIdFor(MaintenanceHostHistory::class);
|
||||
$table->string('status')->default(1);
|
||||
$table->datetime('finished_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
use App\Models\Host;
|
||||
use App\Models\Maintenance;
|
||||
use App\Models\MaintenanceHistory;
|
||||
use App\Models\MaintenanceHostHistory;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@ -15,7 +17,7 @@ public function up(): void
|
||||
{
|
||||
Schema::create('maintenance_host_histories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignIdFor(Maintenance::class);
|
||||
$table->foreignIdFor(MaintenanceHistory::class);
|
||||
$table->foreignIdFor(Host::class);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
@ -5,7 +5,7 @@
|
||||
<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.live="hosts" label="Livewire Select" :options="$hosts_available" placeholder="Select value..." multiple />
|
||||
|
||||
@foreach($hosts as $host_id)
|
||||
@foreach($hosts as $key => $host_id)
|
||||
<x-form::select group-class="mb-3" wire:model="hosts_tasks.{{ $host_id }}" label="Select Tasks for Host {{ $hosts_available[$host_id] }}" :options="$hosts_tasks_available" placeholder="Select value..." multiple />
|
||||
@endforeach
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
<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="name" id="name" label="name"/>
|
||||
<x-form::quill group-class="mb-3" type="text" wire:model="description" id="description" label="description" />
|
||||
<x-form::button class="btn-primary" type="submit">Create</x-form::button>
|
@ -3,18 +3,21 @@
|
||||
<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>
|
||||
<p>{!! $maintenance_history->maintenance->description !!}</p>
|
||||
@foreach ($maintenance_history->historyHosts as $historyHost)
|
||||
<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{{ $historyHost->id }}">
|
||||
<b>{{ $historyHost->host->hostname }}</b>
|
||||
</div>
|
||||
<div class="collapse" id="collapse{{ $historyHost->id }}">
|
||||
<div class="card card-body mt-2">
|
||||
@foreach ($historyHost->historyTasks as $historyTasks)
|
||||
<x-form::checkbox wire:model="test" label="{{$historyTasks->maintenanceTask->task->name}}"/>
|
||||
{!! $historyTasks->maintenanceTask->task->description !!}
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</x-layout-app>
|
@ -1,13 +1,13 @@
|
||||
<x-layout-app>
|
||||
<div class="container-xl">
|
||||
<div class="page-header">
|
||||
<h1>{{ __('boilerplate::maintenance-task.title') }}</h1>
|
||||
<h1>{{ __('boilerplate::task.title') }}</h1>
|
||||
|
||||
<button class="btn btn-primary" onclick="Livewire.dispatch('openModal', {livewireComponents: 'maintenance-task.form', title: '{{ __('boilerplate::maintenance-task.create') }}'})">
|
||||
<button class="btn btn-primary" onclick="Livewire.dispatch('openModal', {livewireComponents: 'task.form', title: '{{ __('boilerplate::task.create') }}'})">
|
||||
<i class="me-2 fas fa-plus"></i><span>{{ __('boilerplate::ui.add') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@livewire('maintenance-task.data-table', [], key('data-table'))
|
||||
@livewire('task.data-table', [], key('data-table'))
|
||||
</div>
|
||||
</x-layout-app>
|
||||
|
Loading…
Reference in New Issue
Block a user