- Fiche d'identité par organisation (technicien référent, FAI, IP publiques, prestataires liés) accessible depuis un nouveau menu. - Nouveau module Prestataires dédié (catalogue léger réutilisable entre communes, avec journal de suivi des échanges) plutôt que de détourner les organisations de type "Fournisseur". - Nouveau menu Infrastructure par organisation avec schémas réseau/fonctionnel édités via draw.io embarqué (URL configurable, cf. réglages admin). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
199 lines
8.3 KiB
PHP
199 lines
8.3 KiB
PHP
<?php
|
|
|
|
use App\Models\Organization;
|
|
use App\Models\Provider;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Livewire\Component;
|
|
|
|
new class extends Component
|
|
{
|
|
public Organization $organization;
|
|
|
|
public ?int $technicianUserId = null;
|
|
public string $ispName = '';
|
|
public string $publicIpsText = '';
|
|
|
|
public ?int $newProviderId = null;
|
|
public string $newProviderLabel = '';
|
|
|
|
public function mount(Organization $organization): void
|
|
{
|
|
$this->organization = $organization;
|
|
$this->technicianUserId = $organization->technician_user_id;
|
|
$this->ispName = $organization->isp_name ?? '';
|
|
$this->publicIpsText = implode("\n", $organization->public_ips ?? []);
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$validated = $this->validate([
|
|
'technicianUserId' => 'nullable|exists:users,id',
|
|
'ispName' => 'nullable|string|max:255',
|
|
'publicIpsText' => 'nullable|string',
|
|
]);
|
|
|
|
$ips = collect(preg_split('/[\s,]+/', (string) $validated['publicIpsText'], -1, PREG_SPLIT_NO_EMPTY))
|
|
->unique()
|
|
->values();
|
|
|
|
if ($ips->contains(fn ($ip) => filter_var($ip, FILTER_VALIDATE_IP) === false)) {
|
|
$this->addError('publicIpsText', 'Une ou plusieurs adresses IP sont invalides.');
|
|
|
|
return;
|
|
}
|
|
|
|
$this->organization->update([
|
|
'technician_user_id' => $validated['technicianUserId'],
|
|
'isp_name' => $validated['ispName'] !== '' ? $validated['ispName'] : null,
|
|
'public_ips' => $ips->all(),
|
|
]);
|
|
|
|
session()->flash('status', "Fiche d'identité mise à jour.");
|
|
}
|
|
|
|
public function addProvider(): void
|
|
{
|
|
$validated = $this->validate([
|
|
'newProviderId' => 'required|exists:providers,id',
|
|
'newProviderLabel' => 'nullable|string|max:255',
|
|
]);
|
|
|
|
$label = $validated['newProviderLabel'] ?: null;
|
|
|
|
$alreadyLinked = $this->organization->providers()
|
|
->wherePivot('provider_id', $validated['newProviderId'])
|
|
->wherePivot('label', '=', $label)
|
|
->exists();
|
|
|
|
if ($alreadyLinked) {
|
|
$this->addError('newProviderId', 'Ce prestataire est déjà lié avec ce libellé.');
|
|
|
|
return;
|
|
}
|
|
|
|
$this->organization->providers()->attach($validated['newProviderId'], ['label' => $label]);
|
|
|
|
$this->reset(['newProviderId', 'newProviderLabel']);
|
|
}
|
|
|
|
public function removeProvider(int $pivotId): void
|
|
{
|
|
DB::table('organization_provider')
|
|
->where('id', $pivotId)
|
|
->where('organization_id', $this->organization->id)
|
|
->delete();
|
|
}
|
|
|
|
public function with(): array
|
|
{
|
|
return [
|
|
'technicians' => User::role(['Administrateur', 'Technicien'])->orderBy('name')->get(),
|
|
'availableProviders' => Provider::orderBy('name')->get(),
|
|
'providers' => $this->organization->providers()->orderBy('name')->get(),
|
|
];
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div class="max-w-3xl">
|
|
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
|
<h1 class="mb-6 text-2xl font-semibold text-slate-900">Fiche d'identité informatique</h1>
|
|
|
|
@if (session('status'))
|
|
<div class="mb-4 rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-700">
|
|
{{ session('status') }}
|
|
</div>
|
|
@endif
|
|
|
|
<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">Technicien gestionnaire</label>
|
|
<select wire:model="technicianUserId"
|
|
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
|
<option value="">—</option>
|
|
@foreach ($technicians as $technician)
|
|
<option value="{{ $technician->id }}">{{ $technician->name }}</option>
|
|
@endforeach
|
|
</select>
|
|
@error('technicianUserId') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium text-slate-700">Fournisseur d'accès internet</label>
|
|
<input type="text" wire:model="ispName" placeholder="Orange, Free Pro, Telindus..."
|
|
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
|
@error('ispName') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium text-slate-700">IP(s) publiques</label>
|
|
<textarea wire:model="publicIpsText" rows="3" placeholder="Une adresse IP par ligne"
|
|
class="mt-1 w-full rounded border-slate-300 font-mono text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500"></textarea>
|
|
@error('publicIpsText') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
|
</div>
|
|
|
|
<div class="pt-2">
|
|
<button type="submit"
|
|
class="cursor-pointer rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
|
Enregistrer
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="mt-8 rounded border border-slate-200 bg-white p-6">
|
|
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Prestataires</h2>
|
|
|
|
<ul class="mb-4 divide-y divide-slate-100">
|
|
@forelse ($providers as $provider)
|
|
<li wire:key="provider-{{ $provider->pivot->id }}" class="flex items-center gap-3 py-2 text-sm">
|
|
<img src="{{ $provider->logo_url }}" alt="Logo {{ $provider->name }}"
|
|
class="h-6 w-6 shrink-0 rounded border border-slate-200 bg-white object-contain p-0.5">
|
|
<div class="flex-1">
|
|
<a href="{{ route('providers.edit', $provider) }}" class="font-medium text-slate-900 hover:underline">
|
|
{{ $provider->name }}
|
|
</a>
|
|
@if ($provider->pivot->label)
|
|
<span class="text-xs text-slate-500">· {{ $provider->pivot->label }}</span>
|
|
@endif
|
|
</div>
|
|
<button type="button" wire:click="removeProvider({{ $provider->pivot->id }})"
|
|
wire:confirm="Retirer ce prestataire ?"
|
|
class="cursor-pointer shrink-0 text-xs text-red-500 hover:text-red-700">
|
|
Retirer
|
|
</button>
|
|
</li>
|
|
@empty
|
|
<li class="py-2 text-sm text-slate-400">Aucun prestataire lié.</li>
|
|
@endforelse
|
|
</ul>
|
|
|
|
<form wire:submit="addProvider" class="flex flex-wrap items-start gap-2 rounded border border-slate-100 bg-slate-50 p-3">
|
|
<div class="flex-1">
|
|
<select wire:model="newProviderId"
|
|
class="w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
|
<option value="">Sélectionner un prestataire...</option>
|
|
@foreach ($availableProviders as $availableProvider)
|
|
<option value="{{ $availableProvider->id }}">{{ $availableProvider->name }}</option>
|
|
@endforeach
|
|
</select>
|
|
@error('newProviderId') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
|
</div>
|
|
<div class="flex-1">
|
|
<input type="text" wire:model="newProviderLabel" placeholder="Libellé (ex: Téléphonie, Maintenance copieurs)"
|
|
class="w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
|
</div>
|
|
<button type="submit" class="cursor-pointer rounded bg-slate-900 px-3 py-1.5 text-sm text-white hover:bg-slate-700">
|
|
Ajouter
|
|
</button>
|
|
</form>
|
|
|
|
@if ($availableProviders->isEmpty())
|
|
<p class="mt-3 text-xs text-slate-500">
|
|
Aucun prestataire n'existe encore.
|
|
<a href="{{ route('providers.create') }}" class="underline hover:text-slate-900">En créer un</a>.
|
|
</p>
|
|
@endif
|
|
</div>
|
|
</div>
|