feat(machine) : afficher quantité pièces + pièces incluses des composants
- MachinePiecesCard : passer isEditMode au PieceItem + forward event update - useMachineHierarchy : mapper quantity depuis le backend + construire les pièces de structure du composant en lecture seule - useMachineDetailUpdates : PATCH MachinePieceLink.quantity + fix reference null - ComponentItem : séparer pièces liées / pièces incluses par défaut - useEntityDocuments : skip chargement documents pour pièces de structure Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -215,14 +215,14 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Component Pieces -->
|
<!-- Component Pieces (real MachinePieceLinks) -->
|
||||||
<div v-if="component.pieces && component.pieces.length > 0" class="space-y-2">
|
<div v-if="linkedPieces.length > 0" class="space-y-2">
|
||||||
<p class="text-xs font-semibold text-base-content/50 uppercase tracking-wide">
|
<p class="text-xs font-semibold text-base-content/50 uppercase tracking-wide">
|
||||||
Pièces du composant
|
Pièces du composant
|
||||||
</p>
|
</p>
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<PieceItem
|
<PieceItem
|
||||||
v-for="piece in component.pieces"
|
v-for="piece in linkedPieces"
|
||||||
:key="piece.id"
|
:key="piece.id"
|
||||||
:piece="piece"
|
:piece="piece"
|
||||||
:is-edit-mode="isEditMode"
|
:is-edit-mode="isEditMode"
|
||||||
@@ -233,6 +233,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Structure pieces (read-only, from composant definition) -->
|
||||||
|
<div v-if="structurePieces.length > 0" class="space-y-2">
|
||||||
|
<p class="text-xs font-semibold text-base-content/50 uppercase tracking-wide">
|
||||||
|
Pièces incluses par défaut
|
||||||
|
</p>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<PieceItem
|
||||||
|
v-for="piece in structurePieces"
|
||||||
|
:key="piece.id"
|
||||||
|
:piece="piece"
|
||||||
|
:is-edit-mode="false"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Sub Components -->
|
<!-- Sub Components -->
|
||||||
<div v-if="childComponents.length > 0" class="space-y-2">
|
<div v-if="childComponents.length > 0" class="space-y-2">
|
||||||
<p class="text-xs font-semibold text-base-content/50 uppercase tracking-wide">
|
<p class="text-xs font-semibold text-base-content/50 uppercase tracking-wide">
|
||||||
@@ -341,6 +356,14 @@ const childComponents = computed(() => {
|
|||||||
return Array.isArray(list) ? list : []
|
return Array.isArray(list) ? list : []
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// --- Pieces split: real links vs structure definitions ---
|
||||||
|
const allPieces = computed(() => {
|
||||||
|
const list = props.component.pieces
|
||||||
|
return Array.isArray(list) ? list : []
|
||||||
|
})
|
||||||
|
const linkedPieces = computed(() => allPieces.value.filter((p) => !p._structurePiece))
|
||||||
|
const structurePieces = computed(() => allPieces.value.filter((p) => p._structurePiece))
|
||||||
|
|
||||||
// --- Constructeurs ---
|
// --- Constructeurs ---
|
||||||
const { constructeurs } = useConstructeurs()
|
const { constructeurs } = useConstructeurs()
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,11 @@
|
|||||||
<div v-for="piece in pieces" :key="piece.id">
|
<div v-for="piece in pieces" :key="piece.id">
|
||||||
<PieceItem
|
<PieceItem
|
||||||
:piece="piece"
|
:piece="piece"
|
||||||
:is-edit-mode="false"
|
:is-edit-mode="isEditMode"
|
||||||
:show-delete="isEditMode"
|
:show-delete="isEditMode"
|
||||||
:collapse-all="collapsed"
|
:collapse-all="collapsed"
|
||||||
:toggle-token="collapseToggleToken"
|
:toggle-token="collapseToggleToken"
|
||||||
|
@update="$emit('update-piece', $event)"
|
||||||
@edit="$emit('edit-piece', $event)"
|
@edit="$emit('edit-piece', $event)"
|
||||||
@delete="$emit('remove-piece', piece.linkId || piece.id)"
|
@delete="$emit('remove-piece', piece.linkId || piece.id)"
|
||||||
/>
|
/>
|
||||||
@@ -62,6 +63,7 @@ defineProps<{
|
|||||||
|
|
||||||
defineEmits<{
|
defineEmits<{
|
||||||
'toggle-collapse': []
|
'toggle-collapse': []
|
||||||
|
'update-piece': [piece: any]
|
||||||
'edit-piece': [piece: any]
|
'edit-piece': [piece: any]
|
||||||
'add-piece': []
|
'add-piece': []
|
||||||
'remove-piece': [linkId: string]
|
'remove-piece': [linkId: string]
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export function useEntityDocuments(deps: EntityDocumentsDeps) {
|
|||||||
// CRUD operations
|
// CRUD operations
|
||||||
const refreshDocuments = async () => {
|
const refreshDocuments = async () => {
|
||||||
const e = entity()
|
const e = entity()
|
||||||
if (!e?.id) return
|
if (!e?.id || e._structurePiece) return
|
||||||
loadingDocuments.value = true
|
loadingDocuments.value = true
|
||||||
try {
|
try {
|
||||||
const result: any = await loadDocumentsFn(e.id, { updateStore: false })
|
const result: any = await loadDocumentsFn(e.id, { updateStore: false })
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export function useMachineDetailData(machineId: string) {
|
|||||||
const { componentTypes, loadComponentTypes } = useComponentTypes()
|
const { componentTypes, loadComponentTypes } = useComponentTypes()
|
||||||
const { pieceTypes, loadPieceTypes } = usePieceTypes()
|
const { pieceTypes, loadPieceTypes } = usePieceTypes()
|
||||||
const { upsertCustomFieldValue } = useCustomFields()
|
const { upsertCustomFieldValue } = useCustomFields()
|
||||||
const { get } = useApi()
|
const { get, patch: apiPatch } = useApi()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { constructeurs, loadConstructeurs } = useConstructeurs()
|
const { constructeurs, loadConstructeurs } = useConstructeurs()
|
||||||
const { sites, loadSites } = useSites()
|
const { sites, loadSites } = useSites()
|
||||||
@@ -274,6 +274,7 @@ export function useMachineDetailData(machineId: string) {
|
|||||||
updateMachineApi,
|
updateMachineApi,
|
||||||
updateComposantApi: updateComposantApi,
|
updateComposantApi: updateComposantApi,
|
||||||
updatePieceApi,
|
updatePieceApi,
|
||||||
|
apiPatch,
|
||||||
toast,
|
toast,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export interface UseMachineDetailUpdatesDeps {
|
|||||||
updateMachineApi: (id: string, data: any) => Promise<unknown>
|
updateMachineApi: (id: string, data: any) => Promise<unknown>
|
||||||
updateComposantApi: (id: string, data: any) => Promise<unknown>
|
updateComposantApi: (id: string, data: any) => Promise<unknown>
|
||||||
updatePieceApi: (id: string, data: any) => Promise<unknown>
|
updatePieceApi: (id: string, data: any) => Promise<unknown>
|
||||||
|
apiPatch: (endpoint: string, data?: unknown) => Promise<any>
|
||||||
toast: { showInfo: (msg: string) => void }
|
toast: { showInfo: (msg: string) => void }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
|||||||
updateMachineApi,
|
updateMachineApi,
|
||||||
updateComposantApi,
|
updateComposantApi,
|
||||||
updatePieceApi,
|
updatePieceApi,
|
||||||
|
apiPatch,
|
||||||
toast,
|
toast,
|
||||||
} = deps
|
} = deps
|
||||||
|
|
||||||
@@ -147,7 +149,7 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
|||||||
|
|
||||||
const result: any = await updatePieceApi(updatedPiece.id as string, {
|
const result: any = await updatePieceApi(updatedPiece.id as string, {
|
||||||
name: updatedPiece.name,
|
name: updatedPiece.name,
|
||||||
reference: updatedPiece.reference,
|
reference: updatedPiece.reference || null,
|
||||||
constructeurIds: cIds,
|
constructeurIds: cIds,
|
||||||
prix: Number.isNaN(prix) ? null : prix,
|
prix: Number.isNaN(prix) ? null : prix,
|
||||||
productId,
|
productId,
|
||||||
@@ -187,6 +189,13 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
|||||||
const updatePieceInfo = async (updatedPiece: AnyRecord) => {
|
const updatePieceInfo = async (updatedPiece: AnyRecord) => {
|
||||||
try {
|
try {
|
||||||
await _buildAndUpdatePiece(updatedPiece)
|
await _buildAndUpdatePiece(updatedPiece)
|
||||||
|
|
||||||
|
// Update link quantity if this is a direct machine piece
|
||||||
|
const linkId = updatedPiece.linkId || updatedPiece.machinePieceLinkId
|
||||||
|
const quantity = typeof updatedPiece.quantity === 'number' ? Math.max(1, updatedPiece.quantity) : null
|
||||||
|
if (linkId && quantity !== null) {
|
||||||
|
await apiPatch(`/machine_piece_links/${linkId}`, { quantity })
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur lors de la mise à jour de la pièce:', error)
|
console.error('Erreur lors de la mise à jour de la pièce:', error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ export const buildMachineHierarchyFromLinks = (
|
|||||||
parentLinkId: resolveIdentifier(link.parentLinkId, link.parentMachinePieceLinkId, appliedPiece.parentLinkId),
|
parentLinkId: resolveIdentifier(link.parentLinkId, link.parentMachinePieceLinkId, appliedPiece.parentLinkId),
|
||||||
parentPieceLinkId: resolveIdentifier(link.parentPieceLinkId, appliedPiece.parentPieceLinkId),
|
parentPieceLinkId: resolveIdentifier(link.parentPieceLinkId, appliedPiece.parentPieceLinkId),
|
||||||
parentPieceId: resolveIdentifier(appliedPiece.parentPieceId, link.parentPieceId),
|
parentPieceId: resolveIdentifier(appliedPiece.parentPieceId, link.parentPieceId),
|
||||||
|
quantity: typeof link.quantity === 'number' ? link.quantity : 1,
|
||||||
definition: appliedPiece.definition || originalPiece?.definition || {},
|
definition: appliedPiece.definition || originalPiece?.definition || {},
|
||||||
customFields: appliedPiece.customFields || [],
|
customFields: appliedPiece.customFields || [],
|
||||||
}
|
}
|
||||||
@@ -214,10 +215,38 @@ export const buildMachineHierarchyFromLinks = (
|
|||||||
|
|
||||||
const componentName = (compOverrides?.name || appliedComponent.name || (appliedComponent.definition as AnyRecord)?.alias || (appliedComponent.definition as AnyRecord)?.name || originalComponent?.name || 'Composant') as string
|
const componentName = (compOverrides?.name || appliedComponent.name || (appliedComponent.definition as AnyRecord)?.alias || (appliedComponent.definition as AnyRecord)?.name || originalComponent?.name || 'Composant') as string
|
||||||
|
|
||||||
const pieces = Array.isArray(link.pieceLinks)
|
const linkedPieces = Array.isArray(link.pieceLinks)
|
||||||
? (link.pieceLinks as AnyRecord[]).map((pl) => createPieceNode(pl, componentName)).filter(Boolean) as AnyRecord[]
|
? (link.pieceLinks as AnyRecord[]).map((pl) => createPieceNode(pl, componentName)).filter(Boolean) as AnyRecord[]
|
||||||
: []
|
: []
|
||||||
|
|
||||||
|
// If no linked pieces exist, build read-only entries from the composant's structure
|
||||||
|
const structurePieceDefs = (!linkedPieces.length && appliedComponent.structure && typeof appliedComponent.structure === 'object')
|
||||||
|
? (Array.isArray((appliedComponent.structure as AnyRecord).pieces) ? (appliedComponent.structure as AnyRecord).pieces as AnyRecord[] : [])
|
||||||
|
: []
|
||||||
|
const structurePieces = structurePieceDefs.map((def, index) => {
|
||||||
|
const definition = (def.definition && typeof def.definition === 'object' ? def.definition : def) as AnyRecord
|
||||||
|
const resolved = (def.resolvedPiece && typeof def.resolvedPiece === 'object' ? def.resolvedPiece : null) as AnyRecord | null
|
||||||
|
const quantity = typeof definition.quantity === 'number' ? definition.quantity : (typeof def.quantity === 'number' ? def.quantity : 1)
|
||||||
|
return {
|
||||||
|
...(resolved || {}),
|
||||||
|
id: resolved?.id || `structure-piece-${composantId}-${index}`,
|
||||||
|
pieceId: resolved?.id || null,
|
||||||
|
name: resolved?.name || definition.role || definition.name || def.role || def.name || `Pièce ${index + 1}`,
|
||||||
|
reference: resolved?.reference || definition.reference || def.reference || null,
|
||||||
|
prix: resolved?.prix ?? null,
|
||||||
|
constructeurs: resolved?.constructeurs || [],
|
||||||
|
documents: [],
|
||||||
|
quantity,
|
||||||
|
typePieceId: resolved?.typePieceId || definition.typePieceId || def.typePieceId || null,
|
||||||
|
typePiece: resolved?.typePiece || null,
|
||||||
|
parentComponentLinkId: machineComponentLinkId,
|
||||||
|
parentComponentName: componentName,
|
||||||
|
_structurePiece: true,
|
||||||
|
}
|
||||||
|
}) as AnyRecord[]
|
||||||
|
|
||||||
|
const pieces = linkedPieces.length ? linkedPieces : structurePieces
|
||||||
|
|
||||||
const subComponents = Array.isArray(link.childLinks)
|
const subComponents = Array.isArray(link.childLinks)
|
||||||
? (link.childLinks as AnyRecord[]).map(createComponentNode).filter(Boolean) as AnyRecord[]
|
? (link.childLinks as AnyRecord[]).map(createComponentNode).filter(Boolean) as AnyRecord[]
|
||||||
: []
|
: []
|
||||||
|
|||||||
Reference in New Issue
Block a user