Compare commits

..

No commits in common. "0b29730e7f8ccbbb26f47e1879dc4879a3e5e217" and "8d408c470468cb192a1e67279e749fd69dc2c8ee" have entirely different histories.

16 changed files with 5 additions and 310 deletions

View File

@ -1,24 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Models\Host;
use App\Services\ZabbixService;
use Carbon\Carbon;
class HostGroupController extends BaseController
{
public function index()
{
return view('host_groups.index');
}
public function sync()
{
$zabbix = new ZabbixService(config('zabbix.url'));
$zabbix->connect(config('zabbix.username'), config('zabbix.password'));
return redirect()->back();
}
}

View File

@ -45,7 +45,6 @@ public function handle(Request $request, Closure $next): Response
Menu::make('settings-menu', function ($menu) {
$systemRoutes = [
'Host' => [' fas fa-server', 'host'],
'Host Groups' => [' fas fa-server', 'host_groups'],
'Maintenance' => [' fas fa-calendar', 'maintenance'],
'Tasks' => [' fas fa-list', 'tasks'],
];

View File

@ -18,7 +18,7 @@ class DataTable extends DataTableComponent
public function query(): Builder
{
return Host::query()->with(['hostGroups']);
return Host::query();
}
public function headers(): array
@ -26,7 +26,6 @@ public function headers(): array
return [
'display_name' => 'display_name',
'hostname' => 'hostname',
'host_groups' => 'host_groups',
];
}
@ -34,12 +33,6 @@ public function remove($host_id){
Host::find($host_id)->delete();
}
public function columnHostGroups(mixed $column): mixed
{
return implode(", " , $column->pluck('name')->toArray());
}
public function actions($item)
{
return [

View File

@ -3,16 +3,12 @@
use Livewire\Component;
use App\Models\Host;
use App\Models\HostGroup;
class Form extends Component
{
public $model;
public string $hostname;
public $host_groups = [];
public $host_groups_available = [];
public $action = 'store';
protected function rules()
@ -23,15 +19,12 @@ protected function rules()
}
public function mount ($model = null){
$this->host_groups_available = HostGroup::pluck('name', 'id')->toArray();
if (!empty($model)) {
$host = Host::find($model);
$this->model = $model;
$this->hostname = $host->hostname;
$this->host_groups = $host->hostGroups()->pluck('host_groups.id')->toArray();
$this->action = 'update';
}
@ -40,8 +33,7 @@ public function mount ($model = null){
public function store()
{
$validatedData = $this->validate();
$host = Host::create($validatedData);
$host->hostGroups()->sync($this->host_groups);
Host::create($validatedData);
$this->dispatch('closeModal');
}
@ -51,7 +43,6 @@ public function update()
$host = Host::find($this->model);
if (!empty($host)) {
$host->update($validatedData);
$host->hostGroups()->sync($this->host_groups);
}
$this->dispatch('closeModal');
}

View File

@ -1,59 +0,0 @@
<?php
namespace App\Livewire\HostGroup;
use App\Models\HostGroup;
use SteelAnts\DataTable\Livewire\DataTableComponent;
use Illuminate\Database\Eloquent\Builder;
class DataTable extends DataTableComponent
{
public $listeners = [
'hostgroupAdded' => '$refresh',
'closeModal' => '$refresh',
];
public function query(): Builder
{
return HostGroup::query()->with(['hosts:id']);
}
public function headers(): array
{
return [
'name' => 'name',
'hosts_count' => 'hosts_count',
];
}
public function row($row){
$row['hosts_count'] = $row->hosts->count();
return $row;
}
public function remove($hostgroup_id){
HostGroup::find($hostgroup_id)->delete();
}
public function actions($item)
{
return [
[
'type' => "livewire",
'action' => "edit",
'text' => "edit",
'parameters' => $item['id']
],
[
'type' => "livewire",
'action' => "remove",
'text' => "remove",
'parameters' => $item['id']
]
];
}
public function edit($host_id)
{
$this->dispatch('openModal', 'host.form', __('boilerplate::host.edit'), ['model' => $host_id]);
}
}

View File

@ -1,54 +0,0 @@
<?php
namespace App\Livewire\HostGroup;
use Livewire\Component;
use App\Models\HostGroup;
class Form extends Component
{
public $model;
public string $name;
public $action = 'store';
protected function rules()
{
return [
'name' => 'required',
];
}
public function mount ($model = null){
if (!empty($model)) {
$hostGroup = HostGroup::find($model);
$this->model = $model;
$this->name = $hostGroup->name;
$this->action = 'update';
}
}
public function store()
{
$validatedData = $this->validate();
HostGroup::create($validatedData);
$this->dispatch('closeModal');
}
public function update()
{
$validatedData = $this->validate();
$hostGroup = HostGroup::find($this->model);
if (!empty($hostGroup)) {
$hostGroup->update($validatedData);
}
$this->dispatch('closeModal');
}
public function render()
{
return view('livewire.host-group.form');
}
}

View File

@ -17,11 +17,6 @@ class Host extends Model
public function tasks()
{
return $this->hasMany(MaintenanceTask::class);
}
public function hostGroups()
{
return $this->belongsToMany(HostGroup::class)->using(HostHostGroup::class);
return $this->hasMany(MaintenanceTask::class,);
}
}

View File

@ -1,21 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class HostGroup extends Model
{
use HasFactory;
protected $fillable = [
'name',
'external_id',
];
public function hosts()
{
return $this->belongsToMany(Host::class)->using(HostHostGroup::class);
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
class HostHostGroup extends Pivot
{
//
}

View File

@ -1,29 +0,0 @@
<?php
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('host_groups', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('external_id')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('host_groups');
}
};

View File

@ -1,29 +0,0 @@
<?php
use App\Models\HostGroup;
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::table('hosts', function (Blueprint $table) {
$table->foreignIdFor(HostGroup::class, 'host_group_id')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('hosts', function (Blueprint $table) {
//
});
}
};

View File

@ -1,30 +0,0 @@
<?php
use App\Models\Host;
use App\Models\HostGroup;
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('host_host_group', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Host::class, 'host_id')->nullable();
$table->foreignIdFor(HostGroup::class, 'host_group_id')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('host_host_group');
}
};

View File

@ -1,20 +0,0 @@
<x-layout-app>
<div class="container-xl">
<div class="page-header">
<h1>{{ __('boilerplate::host_groups.title') }}</h1>
<div>
<a class="btn btn-primary" href="{{ route('host.sync') }}">
<i class="me-2 fas fa-sync-alt"></i><span>{{ __('boilerplate::ui.sync') }}</span>
</a>
<button class="btn btn-primary"
onclick="Livewire.dispatch('openModal', {livewireComponents: 'host_group.form', title: '{{ __('boilerplate::host_group.create') }}'})">
<i class="me-2 fas fa-plus"></i><span>{{ __('boilerplate::ui.add') }}</span>
</button>
</div>
</div>
@livewire('host_group.data-table', [], key('data-table'))
</div>
</x-layout-app>

View File

@ -1,6 +0,0 @@
<div>
<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::button class="btn-primary" type="submit">Create</x-form::button>
</x-form::form>
</div>

View File

@ -1,7 +1,6 @@
<div>
<x-form::form wire:submit.prevent="{{$action}}">
<x-form::input group-class="mb-3" type="text" wire:model="hostname" id="hostname" label="hostname"/>
<x-form::select group-class="mb-3" wire:model.live="host_groups" label="Select groups for Host" :options="$host_groups_available" placeholder="Select value..." multiple />
<x-form::button class="btn-primary" type="submit">Create</x-form::button>
</x-form::form>
</div>

View File

@ -22,7 +22,7 @@
Route::get('/host', [App\Http\Controllers\HostController::class, 'index'])->name('host');
Route::get('/host/sync', [App\Http\Controllers\HostController::class, 'sync'])->name('host.sync');
Route::get('/host_groups', [App\Http\Controllers\HostGroupController::class, 'index'])->name('host_groups');
Route::get('/maintenance', [App\Http\Controllers\MaintenanceController::class, 'index'])->name('maintenance');
Route::get('/tasks', [App\Http\Controllers\TaskController::class, 'index'])->name('tasks');