Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
177 lines
8.5 KiB
PHP
177 lines
8.5 KiB
PHP
<?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>
|