[#278] Plan du site #33

Merged
tristan merged 10 commits from feat/278-plan-du-site into develop 2026-02-25 14:16:11 +00:00
2 changed files with 144 additions and 78 deletions
Showing only changes of commit 527fb77668 - Show all commits

View File

@@ -1,6 +1,7 @@
<template> <template>
<div class="min-h-screen"> <div class="min-h-screen">
<div class="flex items-center justify-between mb-4"> <!-- En-tête de page avec retour et titre -->
<div class="flex items-center justify-between mb-8">
<div class="flex items-center gap-10"> <div class="flex items-center gap-10">
<Icon <Icon
@click="router.push('/')" @click="router.push('/')"
@@ -12,49 +13,62 @@
</div> </div>
</div> </div>
<div class="px-[86px]"> <div class="px-[86px] space-y-6">
<div> <!-- Liste des bâtiments + rendu du plan de chaque bâtiment -->
<div <div
v-for="entry in buildingLayouts" v-for="entry in buildingLayouts"
:key="entry.building.id" :key="entry.building.id"
> >
<div class="font-semibold tracking-wide"> <div class="font-semibold tracking-wide">
{{ entry.building.label || `Bâtiment ${entry.building.id}` }} {{ entry.building.label || `Bâtiment ${entry.building.id}` }}
</div> </div>
<div class="px-4 py-4"> <div class="py-4">
<!-- Aucun layout disponible pour ce bâtiment -->
<div v-if="!entry.layout" class="text-sm text-slate-400"> <div v-if="!entry.layout" class="text-sm text-slate-400">
Aucun plan de bâtiment. Aucun plan de bâtiment.
</div> </div>
<div v-else> <!-- Grille CSS : les cases sont positionnées via spanStyle -->
<div class="overflow-auto"> <div v-else class="overflow-auto">
<div class="grid" :style="entry.gridStyle"> <div class="grid" :style="entry.gridStyle">
<NuxtLink <NuxtLink
v-for="cell in entry.cells" v-for="cell in entry.cells"
:key="cell.key" :key="cell.key"
class="relative flex items-center justify-center h-[50px] border-y-2 border-y-black hover:opacity-85 focus-visible:outline-none" class="relative text-white flex h-[50px] items-center justify-center border-y-[3px] border-y-black bg-white hover:opacity-85 focus-visible:outline-none"
:class="activeLegendStatutId !== null && cell.caseStatusId !== activeLegendStatutId ? 'opacity-35 hover:opacity-70' : ''" :class="[cell.sideBorderClass, activeLegendStatutId !== null && cell.caseStatusId !== activeLegendStatutId ? 'opacity-35 hover:opacity-70' : '']"
:style="[cell.spanStyle, cell.caseStyle]" :style="[cell.spanStyle, cell.sideBorderStyle]"
:to="cell.caseId ? `/infrastructure/case?id=${cell.caseId}` : '/infrastructure/case'" :to="cell.caseId ? `/infrastructure/case?id=${cell.caseId}` : '/infrastructure/case'"
:title="cell.caseStatusLabel ?? undefined" :title="cell.caseStatusLabel ?? undefined"
> >
<!-- Le blanc latéral est géré sur ce bloc interne (conditionnel par voisinage) -->
<div
class="flex h-full w-full items-center justify-center bg-white"
:class="cell.contentInsetClass"
:style="cell.caseStyle"
>
<!-- Numéro de case -->
{{ cell.display }} {{ cell.display }}
</div>
</NuxtLink> </NuxtLink>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
<div class="px-4 py-4"> <!-- Légende : survol d'un statut => atténue les autres cases -->
<div class="flex flex-wrap gap-3"> <div class="py-4">
<!-- 3 zones fixes pour forcer gauche / centre / droite sur toute la largeur -->
<div class="grid w-full grid-cols-3 gap-3">
<div <div
v-for="statut in statutLegend" v-for="(statut, index) in statutLegend"
:key="statut.id" :key="statut.id"
class="inline-flex cursor-pointer items-center gap-2 px-2 py-1" class="flex min-w-0 cursor-pointer items-center gap-2 py-1"
:class="[
index === 0 ? 'justify-self-start' : '',
index === statutLegend.length - 1 ? 'justify-self-end' : '',
index > 0 && index < statutLegend.length - 1 ? 'justify-self-center' : ''
]"
@mouseenter="activeLegendStatutId = statut.id" @mouseenter="activeLegendStatutId = statut.id"
@mouseleave="activeLegendStatutId = null" @mouseleave="activeLegendStatutId = null"
> >
@@ -62,7 +76,7 @@
class="h-5 w-5 border border-slate-300" class="h-5 w-5 border border-slate-300"
:style="statut.couleur ? { backgroundColor: statut.couleur } : {}" :style="statut.couleur ? { backgroundColor: statut.couleur } : {}"
></span> ></span>
<span class="text-sm uppercase text-slate-700"> <span class="truncate text-sm uppercase text-slate-700">
{{ statut.label }} {{ statut.label }}
</span> </span>
</div> </div>
@@ -70,7 +84,6 @@
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@@ -81,15 +94,18 @@ import type { BuildingCaseStatusData } from "~/services/dto/building-case-status
import {getBuildingList} from "~/services/building" import {getBuildingList} from "~/services/building"
import {getStatutList} from "~/services/statut" import {getStatutList} from "~/services/statut"
definePageMeta({layout: "default"}) definePageMeta({layout: "default"})
const router = useRouter() const router = useRouter()
// Données brutes chargées depuis l'API
const buildingList = ref<BuildingData[]>([]) const buildingList = ref<BuildingData[]>([])
const statutLegend = ref<BuildingCaseStatusData[]>([]) const statutLegend = ref<BuildingCaseStatusData[]>([])
// Statut actuellement survolé dans la légende (pour filtrage visuel)
const activeLegendStatutId = ref<number | null>(null) const activeLegendStatutId = ref<number | null>(null)
// Modèle de vue prêt pour le template (layout + cellules + styles de grille)
const buildingLayouts = computed(() => const buildingLayouts = computed(() =>
buildingList.value.map((building) => { buildingList.value.map((building) => {
// On affiche uniquement le premier layout du bâtiment
const layout = building.layouts?.[0] ?? null const layout = building.layouts?.[0] ?? null
const view = layout ? buildLayoutView(layout) : null const view = layout ? buildLayoutView(layout) : null
return {building, layout, cells: view?.cells ?? [], gridStyle: view?.gridStyle ?? {}} return {building, layout, cells: view?.cells ?? [], gridStyle: view?.gridStyle ?? {}}
@@ -102,22 +118,46 @@ type GridCell = {
display: string display: string
caseStatusId: number | null caseStatusId: number | null
caseStatusLabel: string | null caseStatusLabel: string | null
// Couleur de fond de la case (dépend du statut)
caseStyle?: Record<string, string> caseStyle?: Record<string, string>
// Placement dans la grille CSS (colonne/ligne de départ + span)
spanStyle: Record<string, string> spanStyle: Record<string, string>
// Bordures latérales pointillées si la case touche un gap ou le bord du plan
sideBorderClass: string
// Couleur des bordures pointillées latérales (reprend la couleur de la cellule)
sideBorderStyle?: Record<string, string>
// Espace blanc interne uniquement côté(s) adjacent(s) à une autre case
contentInsetClass: string
} }
// Type intermédiaire : garde des infos utiles au calcul des bordures, retirées ensuite
type GridCellDraft = Omit<GridCell, "sideBorderClass" | "sideBorderStyle" | "contentInsetClass"> & { x: number; columnSpan: number }
// Nettoie la couleur de statut pour éviter les chaînes vides / espaces
const normalizeCaseStatusColor = (value: string | null | undefined): string | null => { const normalizeCaseStatusColor = (value: string | null | undefined): string | null => {
const color = (value ?? "").trim() const color = (value ?? "").trim()
return color.length > 0 ? color : null return color.length > 0 ? color : null
} }
// Styles de base communs à toutes les grilles de bâtiments
const BASE_GRID_STYLE = {gridAutoRows: "1fr", rowGap: "18px", columnGap: "0px", width: "100%"} as const const BASE_GRID_STYLE = {gridAutoRows: "1fr", rowGap: "18px", columnGap: "0px", width: "100%"} as const
const buildLayoutView = (layout: BuildingLayoutData): { cells: GridCell[]; gridStyle: Record<string, string> } | null => {
// Transforme un layout API en structure de rendu (cellules + style de grille)
const buildLayoutView = (layout: BuildingLayoutData): {
cells: GridCell[];
gridStyle: Record<string, string>
} | null => {
const rows = layout.rows ?? 0, cols = layout.columns ?? 0 const rows = layout.rows ?? 0, cols = layout.columns ?? 0
if (rows <= 0 || cols <= 0) return null if (rows <= 0 || cols <= 0) return null
// Liste des positions de cases (filtre de sécurité sur les valeurs nulles)
const positions = (layout.casePositions ?? []).filter(Boolean) as BuildingCasePositionData[] const positions = (layout.casePositions ?? []).filter(Boolean) as BuildingCasePositionData[]
// Colonnes occupées par au moins une case (sert à détecter les gaps)
const occupiedColumns = new Set<number>() const occupiedColumns = new Set<number>()
// Sécurité : si deux positions ont le même x/y, on garde la première
const seenCoordinates = new Set<string>() const seenCoordinates = new Set<string>()
const cells: GridCell[] = [] const cellDrafts: GridCellDraft[] = []
// Tri visuel : de haut en bas, puis de gauche à droite
const positionsSorted = [...positions].sort((a, b) => (a.y ?? 1) - (b.y ?? 1) || (a.x ?? 1) - (b.x ?? 1)) const positionsSorted = [...positions].sort((a, b) => (a.y ?? 1) - (b.y ?? 1) || (a.x ?? 1) - (b.x ?? 1))
for (const position of positionsSorted) { for (const position of positionsSorted) {
const x = position.x ?? 1 const x = position.x ?? 1
@@ -125,36 +165,73 @@ const buildLayoutView = (layout: BuildingLayoutData): { cells: GridCell[]; gridS
const coordinateKey = `${x}-${y}` const coordinateKey = `${x}-${y}`
if (seenCoordinates.has(coordinateKey)) continue if (seenCoordinates.has(coordinateKey)) continue
seenCoordinates.add(coordinateKey) seenCoordinates.add(coordinateKey)
occupiedColumns.add(x)
// w/h = nombre de colonnes / lignes occupées par la case dans la grille
const columnSpan = position.w ?? 1 const columnSpan = position.w ?? 1
const rowSpan = position.h ?? 1 const rowSpan = position.h ?? 1
// Une case peut couvrir plusieurs colonnes : on les marque toutes comme occupées
for (let column = x; column < x + columnSpan; column++) {
if (column <= cols) occupiedColumns.add(column)
}
// Métadonnées utiles au rendu / navigation / légende
const caseId = (position.buildingCase?.id ?? null) as number | null const caseId = (position.buildingCase?.id ?? null) as number | null
const caseNumber = (position.buildingCase?.caseNumber ?? null) as number | null const caseNumber = (position.buildingCase?.caseNumber ?? null) as number | null
const caseStatusId = position.buildingCase?.statut?.id ?? null const caseStatusId = position.buildingCase?.statut?.id ?? null
const caseStatusLabel = position.buildingCase?.statut?.label ?? null const caseStatusLabel = position.buildingCase?.statut?.label ?? null
const statusColor = normalizeCaseStatusColor(position.buildingCase?.statut?.couleur) const statusColor = normalizeCaseStatusColor(position.buildingCase?.statut?.couleur)
cells.push({ cellDrafts.push({
key: `case-${layout.id}-${position.id}`, key: `case-${layout.id}-${position.id}`,
x,
columnSpan,
caseId, caseId,
display: caseNumber !== null ? String(caseNumber) : "Case", display: caseNumber !== null ? String(caseNumber) : "Case",
caseStatusId, caseStatusId,
caseStatusLabel, caseStatusLabel,
caseStyle: statusColor ? {backgroundColor: statusColor} : undefined, caseStyle: statusColor ? {backgroundColor: statusColor} : undefined,
// Exemple : "14 / span 1" => commence en colonne 14 et occupe 1 colonne
spanStyle: {gridColumn: `${x} / span ${columnSpan}`, gridRow: `${y} / span ${rowSpan}`} spanStyle: {gridColumn: `${x} / span ${columnSpan}`, gridRow: `${y} / span ${rowSpan}`}
}) })
} }
// Colonnes vides = gaps visuels (plus étroites dans la grille)
const gapColumns = Array.from({length: cols}, (_, i) => i + 1).filter((x) => !occupiedColumns.has(x)) const gapColumns = Array.from({length: cols}, (_, i) => i + 1).filter((x) => !occupiedColumns.has(x))
const gapSet = new Set(gapColumns) const gapSet = new Set(gapColumns)
// Ajoute les bordures latérales pointillées pour les cases au contact d'un gap ou d'un bord
const cells: GridCell[] = cellDrafts.map(({x, columnSpan, ...cell}) => {
const touchesLeftGapOrEdge = x === 1 || gapSet.has(x - 1)
const touchesRightGapOrEdge = x + columnSpan - 1 === cols || gapSet.has(x + columnSpan)
const sideBorderClass = [
touchesLeftGapOrEdge ? "border-l-[3px] [border-left-style:dashed]" : "",
touchesRightGapOrEdge ? "border-r-[3px] [border-right-style:dashed]" : ""
].filter(Boolean).join(" ")
// Les pointillés latéraux reprennent la couleur de la cellule (si un statut en fournit une)
const sideBorderStyle = {
...(cell.caseStyle?.backgroundColor && touchesLeftGapOrEdge ? {borderLeftColor: cell.caseStyle.backgroundColor} : {}),
...(cell.caseStyle?.backgroundColor && touchesRightGapOrEdge ? {borderRightColor: cell.caseStyle.backgroundColor} : {})
}
// Le "blanc" n'est ajouté qu'entre deux cellules adjacentes (pas sur bord/gap)
const contentInsetClass = [
!touchesLeftGapOrEdge ? "ml-[4px]" : "",
!touchesRightGapOrEdge ? "mr-[4px]" : ""
].filter(Boolean).join(" ")
return {...cell, sideBorderClass, sideBorderStyle, contentInsetClass}
})
// Les colonnes de gap sont rendues en 24px, les autres occupent l'espace restant
const columnsTemplate = Array.from({length: cols}, (_, i) => (gapSet.has(i + 1) ? "24px" : "minmax(0, 1fr)")).join(" ") const columnsTemplate = Array.from({length: cols}, (_, i) => (gapSet.has(i + 1) ? "24px" : "minmax(0, 1fr)")).join(" ")
return {cells, gridStyle: {gridTemplateColumns: columnsTemplate, ...BASE_GRID_STYLE}} return {cells, gridStyle: {gridTemplateColumns: columnsTemplate, ...BASE_GRID_STYLE}}
} }
onMounted(async () => { onMounted(async () => {
// Chargement initial des bâtiments et de la légende des statuts
const buildings = await getBuildingList() const buildings = await getBuildingList()
const statuts = await getStatutList() const statuts = await getStatutList()
buildingList.value = buildings buildingList.value = buildings
// Tri alphabétique FR pour une légende stable
statutLegend.value = [...statuts].sort((a, b) => statutLegend.value = [...statuts].sort((a, b) =>
(a.label ?? "").localeCompare(b.label ?? "", "fr", {sensitivity: "base"}) (a.label ?? "").localeCompare(b.label ?? "", "fr", {sensitivity: "base"})
) )

View File

@@ -7,14 +7,3 @@ export interface BuildingLayoutData {
rows: number | null rows: number | null
casePositions?: BuildingCasePositionData[] | null casePositions?: BuildingCasePositionData[] | null
} }
export type LayoutCell = {
key: string
isEmpty: boolean
caseId: number | null
display: string
caseStatusId: number | null
caseStatusLabel: string | null
caseStyle?: Record<string, string>
spanStyle: Record<string, string>
baseClass: string
}