validate(['newFolderName' => 'required|string|max:255']); $this->organization->documents()->create([ 'folder_id' => $this->folderId, 'name' => $this->newFolderName, 'type' => 'diagram', 'is_folder' => true, 'created_by' => auth()->id(), ]); $this->newFolderName = ''; $this->showNewFolder = false; } public function createDiagram(): void { $this->validate(['newDiagramName' => 'required|string|max:255']); $emptyDiagram = <<<'XML' XML; $document = $this->organization->documents()->create([ 'folder_id' => $this->folderId, 'name' => $this->newDiagramName, 'type' => 'diagram', 'content' => $emptyDiagram, 'current_version' => 1, 'created_by' => auth()->id(), ]); $document->versions()->create([ 'version' => 1, 'content' => $emptyDiagram, 'created_by' => auth()->id(), ]); $this->redirectRoute('organizations.infrastructure.edit', [$this->organization, $document, 'folderId' => $this->folderId], navigate: true); } public function delete(int $documentId): void { $document = $this->organization->documents()->where('type', 'diagram')->findOrFail($documentId); $document->delete(); session()->flash('status', "« {$document->name} » supprimé."); } public function moveDocument(int $documentId, ?int $targetFolderId): void { $document = $this->organization->documents()->where('type', 'diagram')->findOrFail($documentId); if ($document->id === $targetFolderId) { return; } if ($targetFolderId !== null) { $targetFolder = $this->organization->documents()->where('type', 'diagram')->find($targetFolderId); if (! $targetFolder || ! $targetFolder->isFolder()) { return; } // Prevent moving a folder into itself or one of its own descendants. if ($document->isFolder()) { $walk = $targetFolder; while ($walk) { if ($walk->id === $document->id) { return; } $walk = $walk->folder; } } } if ($document->folder_id === $targetFolderId) { return; } $document->update(['folder_id' => $targetFolderId]); session()->flash('status', "« {$document->name} » déplacé."); } private function folderTree(\Illuminate\Support\Collection $allFolders): \Illuminate\Support\Collection { $byParent = $allFolders->groupBy('folder_id'); $walk = function ($parentId, $depth) use (&$walk, $byParent) { return ($byParent->get($parentId) ?? collect()) ->sortBy('name') ->flatMap(fn ($folder) => collect([['folder' => $folder, 'depth' => $depth]]) ->concat($walk($folder->id, $depth + 1))); }; return $walk(null, 0); } public function with(): array { $currentFolder = $this->folderId ? $this->organization->documents()->where('type', 'diagram')->find($this->folderId) : null; $breadcrumbs = collect(); $walk = $currentFolder; while ($walk) { $breadcrumbs->prepend($walk); $walk = $walk->folder; } $allFolders = $this->organization->documents()->where('type', 'diagram')->where('is_folder', true)->get(); return [ 'currentFolder' => $currentFolder, 'breadcrumbs' => $breadcrumbs, 'folderTree' => $this->folderTree($allFolders), 'locations' => $this->organization->locations()->orderBy('name')->get(), 'items' => $this->organization->documents() ->where('type', 'diagram') ->where('folder_id', $this->folderId) ->when($this->locationId, fn ($query) => $query->where('location_id', $this->locationId)) ->with('location') ->orderByDesc('is_folder') ->orderBy('name') ->get(), ]; } }; ?>

Infrastructure

@if (session('status'))
{{ session('status') }}
@endif
Infrastructure @foreach ($breadcrumbs as $crumb) / {{ $crumb->name }} @endforeach
@if ($locations->isNotEmpty()) @endif
@if ($showNewFolder)
@error('newFolderName')

{{ $message }}

@enderror
@endif @if ($showNewDiagram)
@error('newDiagramName')

{{ $message }}

@enderror
@endif @if ($items->isNotEmpty())

Astuce : glissez-déposez un élément sur un dossier pour le déplacer.

@endif
@forelse ($items as $item) @php $isFolder = $item->isFolder(); @endphp @empty @endforelse
Nom Site Mis à jour
@if ($isFolder) 📁 {{ $item->name }} @else 🗺️ {{ $item->name }} @endif {{ $isFolder ? '—' : ($item->location?->name ?? '—') }} {{ $item->updated_at->diffForHumans() }} @unless ($isFolder) Ouvrir @endunless @php // Exclude the item's own subtree (if it's a folder) so it can't be moved into itself or a descendant. $excludedIds = [$item->id, $item->folder_id]; if ($isFolder) { $stack = [$item->id]; while ($stack) { $id = array_pop($stack); foreach ($folderTree as $node) { if ($node['folder']->folder_id === $id) { $excludedIds[] = $node['folder']->id; $stack[] = $node['folder']->id; } } } } $moveTargets = $folderTree->reject(fn ($node) => in_array($node['folder']->id, $excludedIds, true)); @endphp @if ($moveTargets->isNotEmpty() || $item->folder_id !== null) @endif
Dossier vide.
@if ($currentFolder)
⬆️ Glisser ici pour remonter au dossier parent
@endif