Initial commit: CABM-IT (ItGlue-style MSP documentation platform)
Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\VirtualMachine;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public Organization $organization;
|
||||
public ?VirtualMachine $virtualMachine = null;
|
||||
|
||||
public string $name = '';
|
||||
public string $role = '';
|
||||
public ?int $memory_gb = null;
|
||||
public ?int $cpu_count = null;
|
||||
public string $operating_system = '';
|
||||
public string $notes = '';
|
||||
|
||||
public string $newLogNote = '';
|
||||
|
||||
public function mount(Organization $organization, ?VirtualMachine $virtualMachine = null): void
|
||||
{
|
||||
$this->organization = $organization;
|
||||
|
||||
if ($virtualMachine?->exists) {
|
||||
$this->virtualMachine = $virtualMachine;
|
||||
$this->name = $virtualMachine->name;
|
||||
$this->role = $virtualMachine->role ?? '';
|
||||
$this->memory_gb = $virtualMachine->memory_gb;
|
||||
$this->cpu_count = $virtualMachine->cpu_count;
|
||||
$this->operating_system = $virtualMachine->operating_system ?? '';
|
||||
$this->notes = $virtualMachine->notes ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$validated = $this->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'role' => 'nullable|string|max:255',
|
||||
'memory_gb' => 'nullable|integer|min:0',
|
||||
'cpu_count' => 'nullable|integer|min:0',
|
||||
'operating_system' => 'nullable|string|max:255',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
if ($this->virtualMachine?->exists) {
|
||||
$this->virtualMachine->update($validated);
|
||||
session()->flash('status', "Machine virtuelle \"{$this->virtualMachine->name}\" mise à jour.");
|
||||
} else {
|
||||
$this->organization->virtualMachines()->create([
|
||||
...$validated,
|
||||
'created_by' => auth()->id(),
|
||||
]);
|
||||
session()->flash('status', "Machine virtuelle \"{$this->name}\" créée.");
|
||||
}
|
||||
|
||||
$this->redirectRoute('organizations.virtual-machines.index', $this->organization, navigate: true);
|
||||
}
|
||||
|
||||
public function addLogEntry(): void
|
||||
{
|
||||
$this->validate(['newLogNote' => 'required|string']);
|
||||
|
||||
$this->virtualMachine->logs()->create([
|
||||
'note' => $this->newLogNote,
|
||||
'created_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
$this->newLogNote = '';
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="max-w-6xl">
|
||||
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||
<h1 class="mb-6 text-2xl font-semibold text-slate-900">
|
||||
{{ $virtualMachine?->exists ? 'Modifier la machine virtuelle' : 'Nouvelle machine virtuelle' }}
|
||||
</h1>
|
||||
|
||||
<div class="grid grid-cols-1 gap-6 {{ $virtualMachine?->exists ? 'lg:grid-cols-2' : '' }}">
|
||||
<div>
|
||||
<form wire:submit="save" class="space-y-4 rounded border border-slate-200 bg-white p-6">
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Nom</label>
|
||||
<input type="text" wire:model="name"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('name') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Rôle</label>
|
||||
<input type="text" wire:model="role" placeholder="ex. Contrôleur de domaine"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Mémoire (Go)</label>
|
||||
<input type="number" min="0" wire:model="memory_gb"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('memory_gb') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Processeurs (vCPU)</label>
|
||||
<input type="number" min="0" wire:model="cpu_count"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('cpu_count') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Système d'exploitation</label>
|
||||
<input type="text" wire:model="operating_system" placeholder="ex. Ubuntu 22.04"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Notes</label>
|
||||
<textarea wire:model="notes" rows="3"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3 pt-2">
|
||||
<button type="submit"
|
||||
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||
Enregistrer
|
||||
</button>
|
||||
<a href="{{ route('organizations.virtual-machines.index', $organization) }}" class="text-sm text-slate-500 hover:text-slate-900">Annuler</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@if ($virtualMachine?->exists)
|
||||
<div>
|
||||
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Journal MCO</h2>
|
||||
|
||||
<form wire:submit="addLogEntry" class="mb-4 flex items-start gap-2 rounded border border-slate-200 bg-white p-3">
|
||||
<textarea wire:model="newLogNote" rows="2" placeholder="Ajouter une entrée au journal (maintenance, incident, mise à jour...)"
|
||||
class="flex-1 rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500"></textarea>
|
||||
<button type="submit" class="rounded bg-slate-900 px-3 py-1.5 text-sm text-white hover:bg-slate-700">Ajouter</button>
|
||||
</form>
|
||||
@error('newLogNote') <p class="mb-4 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
|
||||
<div class="overflow-hidden rounded border border-slate-200 bg-white">
|
||||
<table class="min-w-full divide-y divide-slate-200 text-sm">
|
||||
<thead class="bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500">
|
||||
<tr>
|
||||
<th class="px-4 py-2">Note</th>
|
||||
<th class="px-4 py-2">Par</th>
|
||||
<th class="px-4 py-2">Quand</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-100">
|
||||
@forelse ($virtualMachine->logs as $log)
|
||||
<tr wire:key="log-{{ $log->id }}">
|
||||
<td class="px-4 py-2 whitespace-pre-line text-slate-900">{{ $log->note }}</td>
|
||||
<td class="px-4 py-2 text-slate-600">{{ $log->creator?->name ?? 'système' }}</td>
|
||||
<td class="px-4 py-2 text-slate-500">{{ $log->created_at->diffForHumans() }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="3" class="px-4 py-6 text-center text-slate-400">Aucune entrée pour le moment.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="mt-8">
|
||||
<livewire:related-items.panel :organization="$organization" :item="$virtualMachine" :key="'related-'.$virtualMachine->id" />
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Organization;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public Organization $organization;
|
||||
|
||||
#[Url]
|
||||
public string $search = '';
|
||||
|
||||
public function delete(int $virtualMachineId): void
|
||||
{
|
||||
$virtualMachine = $this->organization->virtualMachines()->findOrFail($virtualMachineId);
|
||||
$virtualMachine->delete();
|
||||
|
||||
session()->flash('status', "Machine virtuelle \"{$virtualMachine->name}\" supprimée.");
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
return [
|
||||
'virtualMachines' => $this->organization->virtualMachines()
|
||||
->when($this->search, fn ($query) => $query->where(function ($q) {
|
||||
$q->where('name', 'like', "%{$this->search}%")
|
||||
->orWhere('role', 'like', "%{$this->search}%")
|
||||
->orWhere('operating_system', 'like', "%{$this->search}%");
|
||||
}))
|
||||
->orderBy('name')
|
||||
->paginate(15),
|
||||
];
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div>
|
||||
<div class="mb-6 flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||
<h1 class="text-2xl font-semibold text-slate-900">Machines virtuelles</h1>
|
||||
</div>
|
||||
<a href="{{ route('organizations.virtual-machines.create', $organization) }}"
|
||||
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||
+ Nouvelle machine virtuelle
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<input type="text" wire:model.live.debounce.300ms="search" placeholder="Filtrer par nom, rôle ou OS..."
|
||||
class="mb-4 w-full max-w-sm rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
|
||||
<div class="overflow-x-auto rounded border border-slate-200 bg-white">
|
||||
<table class="min-w-full divide-y divide-slate-200 text-sm">
|
||||
<thead class="bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500">
|
||||
<tr>
|
||||
<th class="px-4 py-3">Nom</th>
|
||||
<th class="px-4 py-3">Rôle</th>
|
||||
<th class="px-4 py-3">Mémoire</th>
|
||||
<th class="px-4 py-3">CPU</th>
|
||||
<th class="px-4 py-3">OS</th>
|
||||
<th class="px-4 py-3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-100">
|
||||
@forelse ($virtualMachines as $vm)
|
||||
<tr wire:key="vm-{{ $vm->id }}">
|
||||
<td class="px-4 py-3">
|
||||
<a href="{{ route('organizations.virtual-machines.edit', [$organization, $vm]) }}"
|
||||
class="font-medium text-slate-900 hover:underline">
|
||||
🖥️ {{ $vm->name }}
|
||||
</a>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $vm->role ?? '—' }}</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $vm->memory_gb ? $vm->memory_gb.' Go' : '—' }}</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $vm->cpu_count ? $vm->cpu_count.' vCPU' : '—' }}</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $vm->operating_system ?? '—' }}</td>
|
||||
<td class="px-4 py-3 text-right whitespace-nowrap">
|
||||
<a href="{{ route('organizations.virtual-machines.edit', [$organization, $vm]) }}" class="text-slate-500 hover:text-slate-900">Modifier</a>
|
||||
<button type="button"
|
||||
wire:click="delete({{ $vm->id }})"
|
||||
wire:confirm="Supprimer cette machine virtuelle ? Cette action est irréversible."
|
||||
class="ml-3 text-red-500 hover:text-red-700">
|
||||
Supprimer
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="6" class="px-4 py-6 text-center text-slate-400">Aucune machine virtuelle pour le moment.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
{{ $virtualMachines->links() }}
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user