From 958a00c8fc1a67ea5d66c0c73f6a84c7561aea4e Mon Sep 17 00:00:00 2001 From: Matthieu Date: Tue, 31 Mar 2026 17:53:30 +0200 Subject: [PATCH] WIP --- app/components/ComponentItem.vue | 40 +++++++++++----- app/components/ConstructeurLinksTable.vue | 6 ++- app/components/DetailHeader.vue | 17 +++++-- app/components/PieceItem.vue | 42 ++++++++++++----- .../machine/MachineDetailHeader.vue | 14 ++++++ app/components/machine/MachineInfoCard.vue | 36 ++++++--------- app/composables/useConstructeurLinks.ts | 9 ++-- app/composables/useDataTable.ts | 41 +++++++++++++++-- app/composables/useMachineDetailData.ts | 45 +++++++++++------- app/composables/useMachineDetailUpdates.ts | 34 +++++++++----- app/composables/useMachines.ts | 5 +- app/pages/comments.vue | 1 + app/pages/component-catalog.vue | 2 +- app/pages/machine/[id].vue | 12 ++++- app/pages/machines/index.vue | 25 +++++++++- app/pages/piece-category/[id]/edit.vue | 2 + app/pages/pieces-catalog.vue | 2 +- app/pages/pieces/create.vue | 40 ++++++++++++++-- app/pages/product-catalog.vue | 2 +- app/shared/constructeurUtils.ts | 46 ------------------- nuxt.config.ts | 4 +- 21 files changed, 281 insertions(+), 144 deletions(-) diff --git a/app/components/ComponentItem.vue b/app/components/ComponentItem.vue index 6de2d7b..a7e7bab 100644 --- a/app/components/ComponentItem.vue +++ b/app/components/ComponentItem.vue @@ -35,6 +35,7 @@ class="text-xs text-base-content/50" > {{ constructeur.name }} + ({{ supplierReferenceMap.get(constructeur.id) }}) {{ displayProductName }} @@ -102,6 +103,9 @@ class="text-base-content" > {{ constructeur.name }} + + — Réf. {{ supplierReferenceMap.get(constructeur.id) }} + {{ formatConstructeurContact(constructeur) }} @@ -292,6 +296,7 @@ import { formatConstructeurContact as formatConstructeurContactSummary, resolveConstructeurs, uniqueConstructeurIds, + parseConstructeurLinksFromApi, } from '~/shared/constructeurUtils' import { formatSize, @@ -391,23 +396,36 @@ const structurePieces = computed(() => allPieces.value.filter((p) => p._structur // --- Constructeurs --- const { constructeurs } = useConstructeurs() -const componentConstructeurIds = computed(() => - uniqueConstructeurIds( - props.component, +const componentConstructeurLinks = computed(() => + parseConstructeurLinksFromApi( Array.isArray(props.component.constructeurs) ? props.component.constructeurs : [], - props.component.constructeur ? [props.component.constructeur] : [], ), ) -const componentConstructeursDisplay = computed(() => - resolveConstructeurs( - componentConstructeurIds.value, - Array.isArray(props.component.constructeurs) ? props.component.constructeurs : [], - props.component.constructeur ? [props.component.constructeur] : [], - constructeurs.value, - ), +const supplierReferenceMap = computed(() => { + const map = new Map() + componentConstructeurLinks.value.forEach(l => { + if (l.supplierReference) map.set(l.constructeurId, l.supplierReference) + }) + return map +}) + +const componentConstructeurIds = computed(() => + componentConstructeurLinks.value.map(l => l.constructeurId).filter(Boolean), ) +const componentConstructeursDisplay = computed(() => { + // Extract nested constructeur objects from link entries + const linkConstructeurs = componentConstructeurLinks.value + .filter(l => l.constructeur && l.constructeur.id) + .map(l => l.constructeur) + return resolveConstructeurs( + componentConstructeurIds.value, + linkConstructeurs, + constructeurs.value, + ) +}) + const formatConstructeurContact = (constructeur) => formatConstructeurContactSummary(constructeur) diff --git a/app/components/ConstructeurLinksTable.vue b/app/components/ConstructeurLinksTable.vue index b064f12..438b3cd 100644 --- a/app/components/ConstructeurLinksTable.vue +++ b/app/components/ConstructeurLinksTable.vue @@ -78,7 +78,9 @@ const getConstructeurContact = (link: ConstructeurLinkEntry): string => { const updateReference = (index: number, value: string) => { const updated = [...props.modelValue] - updated[index] = { ...updated[index], supplierReference: value || null } + const entry = updated[index] + if (!entry) return + updated[index] = { ...entry, supplierReference: value || null } emit('update:modelValue', updated) } @@ -86,6 +88,6 @@ const removeLink = (index: number) => { const removed = props.modelValue[index] const updated = props.modelValue.filter((_, i) => i !== index) emit('update:modelValue', updated) - emit('remove', removed.constructeurId) + if (removed) emit('remove', removed.constructeurId) } diff --git a/app/components/DetailHeader.vue b/app/components/DetailHeader.vue index d54869a..4a7d43c 100644 --- a/app/components/DetailHeader.vue +++ b/app/components/DetailHeader.vue @@ -15,9 +15,9 @@ {{ pieceData.prix }}€ @@ -122,6 +125,9 @@ > {{ constructeur.name }} + + — Réf. {{ supplierReferenceMap.get(constructeur.id) }} + { // --- Constructeurs --- const { constructeurs } = useConstructeurs() -const pieceConstructeurIds = computed(() => - uniqueConstructeurIds( - props.piece, +const pieceConstructeurLinks = computed(() => + parseConstructeurLinksFromApi( Array.isArray(props.piece.constructeurs) ? props.piece.constructeurs : [], - props.piece.constructeur ? [props.piece.constructeur] : [], ), ) -const pieceConstructeursDisplay = computed(() => - resolveConstructeurs( - pieceConstructeurIds.value, - Array.isArray(props.piece.constructeurs) ? props.piece.constructeurs : [], - props.piece.constructeur ? [props.piece.constructeur] : [], - constructeurs.value, - ), +const supplierReferenceMap = computed(() => { + const map = new Map() + pieceConstructeurLinks.value.forEach(l => { + if (l.supplierReference) map.set(l.constructeurId, l.supplierReference) + }) + return map +}) + +const pieceConstructeurIds = computed(() => + pieceConstructeurLinks.value.map(l => l.constructeurId).filter(Boolean), ) +const pieceConstructeursDisplay = computed(() => { + // Extract nested constructeur objects from link entries + const linkConstructeurs = pieceConstructeurLinks.value + .filter(l => l.constructeur && l.constructeur.id) + .map(l => l.constructeur) + return resolveConstructeurs( + pieceConstructeurIds.value, + linkConstructeurs, + constructeurs.value, + ) +}) + const formatConstructeurContact = (constructeur) => formatConstructeurContactSummary(constructeur) diff --git a/app/components/machine/MachineDetailHeader.vue b/app/components/machine/MachineDetailHeader.vue index f9b55f6..2613a96 100644 --- a/app/components/machine/MachineDetailHeader.vue +++ b/app/components/machine/MachineDetailHeader.vue @@ -32,6 +32,9 @@