From c5f2c568b6c1254f481a21eaf0a9f8122217e6cb Mon Sep 17 00:00:00 2001 From: MatthieuTD <39524319+MatthieuTD@users.noreply.github.com> Date: Thu, 2 Oct 2025 16:29:50 +0200 Subject: [PATCH] chore: retire legacy model catalogs --- app/app.vue | 82 +- app/components/ComponentHierarchy.vue | 16 +- app/components/ComponentItem.vue | 155 +- app/components/PieceItem.vue | 120 +- .../SkeletonComponentNodeSelector.vue | 199 --- app/components/model-types/EditModal.vue | 154 +- app/components/model-types/ManagementView.vue | 24 +- app/composables/useComponentModels.js | 131 -- app/composables/useComponentTypes.js | 6 +- app/composables/usePieceModels.js | 131 -- app/composables/usePieceTypes.js | 6 +- app/pages/component-catalog.vue | 407 +---- app/pages/machine/[id].vue | 1351 ++++----------- app/pages/machines/new.vue | 1467 +++++------------ app/pages/models/index.vue | 30 +- app/pages/pieces-catalog.vue | 372 +---- app/services/modelTypes.ts | 25 +- app/shared/modelUtils.ts | 128 ++ app/shared/types/inventory.ts | 27 + 19 files changed, 1234 insertions(+), 3597 deletions(-) delete mode 100644 app/components/SkeletonComponentNodeSelector.vue delete mode 100644 app/composables/useComponentModels.js delete mode 100644 app/composables/usePieceModels.js diff --git a/app/app.vue b/app/app.vue index 914a547..51188c9 100644 --- a/app/app.vue +++ b/app/app.vue @@ -75,7 +75,7 @@ @keydown.enter.prevent="toggleDropdown('pieces-mobile')" @keydown.space.prevent="toggleDropdown('pieces-mobile')" :class=" - isActive('/pieces-catalog') || isActive('/piece-category') + isActive('/piece-category') ? 'bg-primary text-primary-content font-semibold shadow-sm' : 'text-base-content hover:bg-primary/10 hover:text-primary' " @@ -99,19 +99,6 @@ Catégorie de pièce -
  • - - Catalogue de pièce - -
  • - Catalogue de composant - -
  • - Pièces - + : 'text-base-content hover:bg-primary/10 hover:text-primary' + " + > + Pièces +
  • - Composant - + isActive('/component-category') + ? 'bg-primary text-primary-content font-semibold shadow-sm' + : 'text-base-content hover:bg-primary/10 hover:text-primary' + " + > + Composant +
  • @@ -40,16 +34,8 @@ defineProps({ toggleToken: { type: Number, default: 0 - }, - componentModelOptionsProvider: { - type: Function, - default: () => [] - }, - pieceModelOptionsProvider: { - type: Function, - default: () => [] } }) -defineEmits(['update', 'edit-piece', 'assign-model', 'assign-piece-model', 'custom-field-update', 'create-model-from-component']) +defineEmits(['update', 'edit-piece', 'custom-field-update']) diff --git a/app/components/ComponentItem.vue b/app/components/ComponentItem.vue index 1aeca6a..76ca5b2 100644 --- a/app/components/ComponentItem.vue +++ b/app/components/ComponentItem.vue @@ -34,12 +34,6 @@ > Groupe : {{ component.typeMachineComponentRequirement.label || component.typeMachineComponentRequirement.typeComposant?.name || 'Non défini' }} - - Modèle : {{ component.composantModel.name }} - @@ -108,45 +102,6 @@ -
    -
    - -
    - - -
    -
    -
    @@ -314,7 +269,6 @@ @update="updatePiece" @edit="editPiece" @custom-field-update="updatePieceCustomField" - @assign-model="emitAssignPieceModel" /> @@ -332,13 +286,9 @@ :is-edit-mode="isEditMode" :collapse-all="collapseAll" :toggle-token="toggleToken" - :component-model-options="componentModelOptionsProvider(subComponent)" - :component-model-options-provider="componentModelOptionsProvider" - :piece-model-options-provider="pieceModelOptionsProvider" @update="$emit('update', $event)" @edit-piece="$emit('edit-piece', $event)" - @assign-model="$emit('assign-model', $event)" - @assign-piece-model="$emit('assign-piece-model', $event)" + @custom-field-update="$emit('custom-field-update', $event)" /> @@ -375,28 +325,13 @@ const props = defineProps({ toggleToken: { type: Number, default: 0 - }, - componentModelOptions: { - type: Array, - default: () => [] - }, - componentModelOptionsProvider: { - type: Function, - default: () => [] - }, - pieceModelOptionsProvider: { - type: Function, - default: () => [] } }) const emit = defineEmits([ 'update', 'edit-piece', - 'custom-field-update', - 'assign-model', - 'assign-piece-model', - 'create-model-from-component' + 'custom-field-update' ]) const isCollapsed = ref(true) @@ -409,16 +344,19 @@ const documentIcon = doc => getFileIcon({ name: doc.filename || doc.name, mime: const previewDocument = ref(null) const previewVisible = ref(false) -const selectedComponentModelId = computed(() => props.component.composantModelId || props.component.composantModel?.id || '') -const componentModelOptionsList = computed(() => { - const provided = props.componentModelOptionsProvider(props.component) - return Array.isArray(provided) && provided.length ? provided : props.componentModelOptions -}) -const pieceModelOptionsList = computed(() => props.pieceModelOptionsProvider(props.component) || []) const childComponents = computed(() => { const list = props.component.subcomponents || props.component.subComponents || [] return Array.isArray(list) ? list : [] }) + +const extractStructureCustomFields = (structure) => { + if (!structure || typeof structure !== 'object') { + return [] + } + const customFields = structure.customFields + return Array.isArray(customFields) ? customFields : [] +} + function fieldKeyFromNameAndType(name, type) { const normalizedName = typeof name === 'string' ? name : '' const normalizedType = typeof type === 'string' ? type : '' @@ -520,24 +458,49 @@ function mergeFieldDefinitionsWithValues(definitions, values) { return merged } +const componentDefinitionSources = computed(() => { + const requirement = props.component.typeMachineComponentRequirement || {} + const type = requirement.typeComposant || props.component.typeComposant || {} + + const definitions = [] + const pushFields = (collection) => { + if (Array.isArray(collection)) { + definitions.push(...collection) + } + } + + pushFields(props.component.customFields) + pushFields(props.component.definition?.customFields) + pushFields(type.customFields) + pushFields(requirement.customFields) + pushFields(requirement.definition?.customFields) + + ;[ + props.component.definition?.structure, + type.structure, + type.componentSkeleton, + requirement.structure, + requirement.componentSkeleton, + ].forEach((structure) => { + const fields = extractStructureCustomFields(structure) + if (fields.length) { + definitions.push(...fields) + } + }) + + return definitions +}) + const displayedCustomFields = computed(() => mergeFieldDefinitionsWithValues( - props.component.customFields, + componentDefinitionSources.value, props.component.customFieldValues, ), ) -const candidateCustomFields = computed(() => { - const sources = [ - props.component.customFieldValues?.map((value) => value?.customField), - props.component.typeComposant?.customFields, - props.component.typeMachineComponentRequirement?.typeComposant?.customFields, - props.component.composantModel?.customFields, - props.component.typeMachineComponentRequirement?.customFields, - props.component.customFields, - ] +const candidateCustomFields = computed(() => { const map = new Map() - sources.forEach((collection) => { + const register = (collection) => { if (!Array.isArray(collection)) { return } @@ -553,7 +516,10 @@ const candidateCustomFields = computed(() => { } map.set(key, item) }) - }) + } + + register(props.component.customFieldValues?.map((value) => value?.customField)) + register(componentDefinitionSources.value) return Array.from(map.values()) }) @@ -838,25 +804,6 @@ const updatePieceCustomField = (fieldUpdate) => { emit('edit-piece', { ...fieldUpdate, type: 'custom-field-update' }) } -const assignComponentModel = (value) => { - const previousModelId = props.component.composantModelId || props.component.composantModel?.id || null - const previousModel = props.component.composantModel || null - props.component.composantModelId = value || null - if (!value) { - props.component.composantModel = null - } - emit('assign-model', { - componentId: props.component.id, - composantModelId: value || null, - previousModelId, - previousModel - }) -} - -const emitAssignPieceModel = (payload) => { - emit('assign-piece-model', payload) -} - const ensureDocumentsLoaded = async () => { if (documentsLoaded.value || !props.component?.id) { return } await refreshDocuments() diff --git a/app/components/PieceItem.vue b/app/components/PieceItem.vue index b44345d..b6782bd 100644 --- a/app/components/PieceItem.vue +++ b/app/components/PieceItem.vue @@ -36,12 +36,6 @@ "Non défini" }} - - Modèle : {{ piece.pieceModel.name }} - -
    - - -
    -
    [], - }, }); const emit = defineEmits([ "update", "edit", "custom-field-update", - "assign-model", ]); // Données locales isolées pour cette pièce @@ -412,10 +374,13 @@ const documentIcon = (doc) => getFileIcon({ name: doc.filename || doc.name, mime: doc.mimeType }); const previewDocument = ref(null); const previewVisible = ref(false); -const selectedPieceModelId = computed( - () => props.piece.pieceModelId || props.piece.pieceModel?.id || "" -); -const pieceModelOptions = computed(() => props.pieceModelOptions || []); +const extractStructureCustomFields = (structure) => { + if (!structure || typeof structure !== "object") { + return []; + } + const customFields = structure.customFields; + return Array.isArray(customFields) ? customFields : []; +}; function fieldKeyFromNameAndType(name, type) { const normalizedName = typeof name === 'string' ? name : ''; const normalizedType = typeof type === 'string' ? type : ''; @@ -529,25 +494,53 @@ function mergeFieldDefinitionsWithValues(definitions, values) { return merged; } +const pieceDefinitionSources = computed(() => { + const requirement = props.piece.typeMachinePieceRequirement || {}; + const type = requirement.typePiece || props.piece.typePiece || {}; + + const definitions = []; + const pushFields = (collection) => { + if (Array.isArray(collection)) { + definitions.push(...collection); + } + }; + + pushFields(props.piece.customFields); + pushFields(props.piece.definition?.customFields); + pushFields(props.piece.typePiece?.customFields); + pushFields(type.customFields); + pushFields(requirement.typePiece?.customFields); + pushFields(requirement.customFields); + pushFields(requirement.definition?.customFields); + + [ + props.piece.definition?.structure, + props.piece.typePiece?.structure, + type.structure, + type.pieceSkeleton, + props.piece.typePiece?.pieceSkeleton, + requirement.structure, + requirement.pieceSkeleton, + ].forEach((structure) => { + const fields = extractStructureCustomFields(structure); + if (fields.length) { + definitions.push(...fields); + } + }); + + return definitions; +}); + const displayedCustomFields = computed(() => mergeFieldDefinitionsWithValues( - props.piece.customFields, + pieceDefinitionSources.value, props.piece.customFieldValues, ), ); const candidateCustomFields = computed(() => { - const sources = [ - props.piece.customFieldValues?.map((value) => value?.customField), - props.piece.typePiece?.customFields, - props.piece.typeMachinePieceRequirement?.typePiece?.customFields, - props.piece.typeMachinePieceRequirement?.customFields, - props.piece.pieceModel?.customFields, - props.piece.customFields, - ]; - const map = new Map(); - sources.forEach((collection) => { + const register = (collection) => { if (!Array.isArray(collection)) { return; } @@ -563,7 +556,10 @@ const candidateCustomFields = computed(() => { } map.set(key, item); }); - }); + }; + + register(props.piece.customFieldValues?.map((value) => value?.customField)); + register(pieceDefinitionSources.value); return Array.from(map.values()); }); @@ -827,22 +823,6 @@ const updatePiece = () => { }); }; -const assignPieceModel = (value) => { - const previousModelId = - props.piece.pieceModelId || props.piece.pieceModel?.id || null; - const previousModel = props.piece.pieceModel || null; - props.piece.pieceModelId = value || null; - if (!value) { - props.piece.pieceModel = null; - } - emit("assign-model", { - pieceId: props.piece.id, - pieceModelId: value || null, - previousModelId, - previousModel, - }); -}; - const updateCustomFieldValue = async (fieldValueId, field) => { if (!field || resolveFieldReadOnly(field)) { return; diff --git a/app/components/SkeletonComponentNodeSelector.vue b/app/components/SkeletonComponentNodeSelector.vue deleted file mode 100644 index 867c317..0000000 --- a/app/components/SkeletonComponentNodeSelector.vue +++ /dev/null @@ -1,199 +0,0 @@ - - - diff --git a/app/components/model-types/EditModal.vue b/app/components/model-types/EditModal.vue index 1448c3f..5ccc6ab 100644 --- a/app/components/model-types/EditModal.vue +++ b/app/components/model-types/EditModal.vue @@ -9,7 +9,7 @@ Les champs marqués d'un astérisque sont obligatoires.

    -
    +
    +
    + +
    +
    +

    + Structure du squelette +

    +

    + Définissez la structure canonique appliquée lors de la création des composants ou pièces de cette catégorie. +

    +
    + +
    + + Chargement du squelette… +
    + + +
    + @@ -95,6 +144,18 @@ diff --git a/app/pages/machine/[id].vue b/app/pages/machine/[id].vue index 35ae8aa..aad9041 100644 --- a/app/pages/machine/[id].vue +++ b/app/pages/machine/[id].vue @@ -347,10 +347,6 @@ class="flex flex-wrap items-center gap-2 text-sm" > {{ component.name }} - - Modèle : {{ component.composantModel.name }} - - Défini manuellement (Sous-composant) @@ -399,10 +395,6 @@ class="flex flex-wrap items-center gap-2 text-sm" > {{ piece.name }} - - Modèle : {{ piece.pieceModel.name }} - - Définie manuellement (Rattachée à {{ piece.parentComponentName }}) @@ -449,19 +441,14 @@
    - @@ -474,16 +461,14 @@
    -
    @@ -561,99 +546,13 @@
    -
    - - -
    - -
    -
    -
    - - -

    Chargement des modèles...

    -

    - Aucun modèle disponible pour ce type. -

    -
    -
    - -
    - -
    -
    - - -
    -
    - - -
    -
    - -
    +
    + + Type appliqué : + {{ resolveComponentRequirementTypeLabel(requirement, entry) }} +
    + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    @@ -705,44 +653,13 @@
    -
    -
    - - -

    Chargement des modèles...

    -

    - Aucun modèle disponible pour ce type. -

    -

    - Ancienne pièce : {{ entry.legacyName }} — sélectionner un modèle. -

    -
    -
    - -
    +
    + + Type appliqué : + {{ resolvePieceRequirementTypeLabel(requirement, entry) }} +
    + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    @@ -804,72 +770,7 @@ @deselect-all="setAllPrintSelection(false)" /> - - - + diff --git a/app/pages/pieces-catalog.vue b/app/pages/pieces-catalog.vue index 8058bfa..e2f1900 100644 --- a/app/pages/pieces-catalog.vue +++ b/app/pages/pieces-catalog.vue @@ -1,363 +1,29 @@