Enable adding a component, piece, or product to a machine by selecting only the category (ModelType) without a specific entity. The link displays a red "À remplir" badge; clicking it reopens the modal pre-filled with the category so the user can associate an item later. Backend: entity FKs made nullable on the 3 link tables, modelType FK added, controller/audit/version/MCP normalization adapted for null entities. Frontend: modal accepts category-only confirm, page handles fill mode, hierarchy builder creates pending nodes, display components show clickable badge with event propagation through the full hierarchy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
74 lines
2.1 KiB
Vue
74 lines
2.1 KiB
Vue
<template>
|
|
<div class="card bg-base-100 shadow-sm">
|
|
<div class="card-body">
|
|
<div class="flex justify-between items-center mb-4">
|
|
<h2 class="card-title">Pièces de la machine</h2>
|
|
<button
|
|
type="button"
|
|
class="btn btn-ghost btn-sm gap-2"
|
|
@click="$emit('toggle-collapse')"
|
|
:title="collapsed ? 'Déplier toutes les pièces' : 'Replier toutes les pièces'"
|
|
>
|
|
<IconLucideChevronRight
|
|
class="w-5 h-5 transition-transform"
|
|
:class="collapsed ? 'rotate-0' : 'rotate-90'"
|
|
aria-hidden="true"
|
|
/>
|
|
<span class="text-sm">
|
|
{{ collapsed ? 'Tout déplier' : 'Tout replier' }}
|
|
</span>
|
|
</button>
|
|
</div>
|
|
|
|
<div v-if="pieces.length === 0" class="text-sm text-gray-500 py-4">
|
|
Aucune pièce associée à cette machine.
|
|
</div>
|
|
|
|
<div v-else class="space-y-2">
|
|
<div v-for="piece in pieces" :key="piece.id">
|
|
<PieceItem
|
|
:piece="piece"
|
|
:is-edit-mode="isEditMode"
|
|
:show-delete="isEditMode"
|
|
:collapse-all="collapsed"
|
|
:toggle-token="collapseToggleToken"
|
|
@update="$emit('update-piece', $event)"
|
|
@edit="$emit('edit-piece', $event)"
|
|
@delete="$emit('remove-piece', piece.linkId || piece.id)"
|
|
@fill-entity="(linkId, typeId) => $emit('fill-entity', linkId, typeId)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<button
|
|
v-if="isEditMode"
|
|
type="button"
|
|
class="btn btn-sm md:btn-md btn-primary"
|
|
@click="$emit('add-piece')"
|
|
>
|
|
Ajouter une pièce
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import IconLucideChevronRight from '~icons/lucide/chevron-right'
|
|
|
|
defineProps<{
|
|
pieces: any[]
|
|
isEditMode: boolean
|
|
collapsed: boolean
|
|
collapseToggleToken: number
|
|
}>()
|
|
|
|
defineEmits<{
|
|
'toggle-collapse': []
|
|
'update-piece': [piece: any]
|
|
'edit-piece': [piece: any]
|
|
'add-piece': []
|
|
'remove-piece': [linkId: string]
|
|
'fill-entity': [linkId: string, modelTypeId: string]
|
|
}>()
|
|
</script>
|