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,143 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Location;
|
||||
use App\Models\Organization;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public Organization $organization;
|
||||
public ?Location $location = null;
|
||||
|
||||
public string $name = '';
|
||||
public string $address_line_1 = '';
|
||||
public string $address_line_2 = '';
|
||||
public string $city = '';
|
||||
public string $region = '';
|
||||
public string $postal_code = '';
|
||||
public string $country = '';
|
||||
public string $phone = '';
|
||||
public bool $is_primary = false;
|
||||
|
||||
public function mount(Organization $organization, ?Location $location = null): void
|
||||
{
|
||||
$this->organization = $organization;
|
||||
|
||||
if ($location?->exists) {
|
||||
$this->location = $location;
|
||||
$this->name = $location->name;
|
||||
$this->address_line_1 = $location->address_line_1 ?? '';
|
||||
$this->address_line_2 = $location->address_line_2 ?? '';
|
||||
$this->city = $location->city ?? '';
|
||||
$this->region = $location->region ?? '';
|
||||
$this->postal_code = $location->postal_code ?? '';
|
||||
$this->country = $location->country ?? '';
|
||||
$this->phone = $location->phone ?? '';
|
||||
$this->is_primary = $location->is_primary;
|
||||
}
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$validated = $this->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'address_line_1' => 'nullable|string|max:255',
|
||||
'address_line_2' => 'nullable|string|max:255',
|
||||
'city' => 'nullable|string|max:255',
|
||||
'region' => 'nullable|string|max:255',
|
||||
'postal_code' => 'nullable|string|max:255',
|
||||
'country' => 'nullable|string|max:255',
|
||||
'phone' => 'nullable|string|max:255',
|
||||
'is_primary' => 'boolean',
|
||||
]);
|
||||
|
||||
if ($validated['is_primary']) {
|
||||
$this->organization->locations()
|
||||
->when($this->location?->exists, fn ($query) => $query->whereKeyNot($this->location->id))
|
||||
->update(['is_primary' => false]);
|
||||
}
|
||||
|
||||
if ($this->location?->exists) {
|
||||
$this->location->update($validated);
|
||||
session()->flash('status', "Site \"{$this->location->name}\" mis à jour.");
|
||||
} else {
|
||||
$this->organization->locations()->create($validated);
|
||||
session()->flash('status', "Site \"{$this->name}\" créé.");
|
||||
}
|
||||
|
||||
$this->redirectRoute('organizations.locations.index', $this->organization, navigate: true);
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="max-w-2xl">
|
||||
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||
<h1 class="mb-6 text-2xl font-semibold text-slate-900">
|
||||
{{ $location?->exists ? 'Modifier le site' : 'Nouveau site' }}
|
||||
</h1>
|
||||
|
||||
<form wire:submit="save" class="space-y-4 rounded border border-slate-200 bg-white p-6">
|
||||
<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">Adresse ligne 1</label>
|
||||
<input type="text" wire:model="address_line_1"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Adresse ligne 2</label>
|
||||
<input type="text" wire:model="address_line_2"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Ville</label>
|
||||
<input type="text" wire:model="city"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Région</label>
|
||||
<input type="text" wire:model="region"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Code postal</label>
|
||||
<input type="text" wire:model="postal_code"
|
||||
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-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Pays</label>
|
||||
<input type="text" wire:model="country"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Téléphone</label>
|
||||
<input type="text" wire:model="phone"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="flex items-center gap-2 text-sm text-slate-700">
|
||||
<input type="checkbox" wire:model="is_primary" class="rounded border-slate-300">
|
||||
Site principal
|
||||
</label>
|
||||
|
||||
<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.locations.index', $organization) }}" class="text-sm text-slate-500 hover:text-slate-900">Annuler</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,104 @@
|
||||
<?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 $locationId): void
|
||||
{
|
||||
$location = $this->organization->locations()->findOrFail($locationId);
|
||||
$location->delete();
|
||||
|
||||
session()->flash('status', "Site \"{$location->name}\" supprimé.");
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
return [
|
||||
'locations' => $this->organization->locations()
|
||||
->when($this->search, fn ($query) => $query->where(function ($q) {
|
||||
$q->where('name', 'like', "%{$this->search}%")
|
||||
->orWhere('city', 'like', "%{$this->search}%");
|
||||
}))
|
||||
->orderByDesc('is_primary')
|
||||
->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">Sites</h1>
|
||||
</div>
|
||||
<a href="{{ route('organizations.locations.create', $organization) }}"
|
||||
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||
+ Nouveau site
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<input type="text" wire:model.live.debounce.300ms="search" placeholder="Filtrer par nom ou ville..."
|
||||
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">Ville</th>
|
||||
<th class="px-4 py-3">Pays</th>
|
||||
<th class="px-4 py-3">Téléphone</th>
|
||||
<th class="px-4 py-3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-100">
|
||||
@forelse ($locations as $location)
|
||||
<tr wire:key="loc-{{ $location->id }}">
|
||||
<td class="px-4 py-3">
|
||||
<a href="{{ route('organizations.locations.edit', [$organization, $location]) }}"
|
||||
class="font-medium text-slate-900 hover:underline">
|
||||
{{ $location->name }}
|
||||
</a>
|
||||
@if ($location->is_primary)
|
||||
<span class="ml-2 rounded-full bg-emerald-100 px-2 py-0.5 text-xs font-medium text-emerald-700">Principal</span>
|
||||
@endif
|
||||
</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $location->city ?? '—' }}</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $location->country ?? '—' }}</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $location->phone ?? '—' }}</td>
|
||||
<td class="px-4 py-3 text-right whitespace-nowrap">
|
||||
<a href="{{ route('organizations.locations.edit', [$organization, $location]) }}" class="text-slate-500 hover:text-slate-900">Modifier</a>
|
||||
<button type="button"
|
||||
wire:click="delete({{ $location->id }})"
|
||||
wire:confirm="Supprimer ce site ? Cette action est irréversible."
|
||||
class="ml-3 text-red-500 hover:text-red-700">
|
||||
Supprimer
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="px-4 py-6 text-center text-slate-400">Aucun site pour le moment.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
{{ $locations->links() }}
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user