From 736a8bccf900665696fb86ce6595b8bcfd35247c Mon Sep 17 00:00:00 2001 From: Matthieu Date: Mon, 23 Mar 2026 15:38:30 +0100 Subject: [PATCH] feat(documents) : wire DocumentEditModal and type select in all entity pages Co-Authored-By: Claude Opus 4.6 (1M context) --- app/components/ComponentItem.vue | 24 ++++++++++++++++++++++++ app/components/PieceItem.vue | 24 ++++++++++++++++++++++++ app/pages/component/[id]/edit.vue | 31 +++++++++++++++++++++++++++++++ app/pages/pieces/[id]/edit.vue | 31 +++++++++++++++++++++++++++++++ app/pages/product/[id]/edit.vue | 28 ++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+) diff --git a/app/components/ComponentItem.vue b/app/components/ComponentItem.vue index 39ae3e3..da8c2dc 100644 --- a/app/components/ComponentItem.vue +++ b/app/components/ComponentItem.vue @@ -6,6 +6,12 @@ :documents="componentDocuments" @close="closePreview" /> +
@@ -208,9 +214,11 @@
@@ -319,6 +327,7 @@ const { ensureDocumentsLoaded, handleFilesAdded, removeDocument, + editDocument, } = useEntityDocuments({ entity: () => props.component, entityType: 'composant' }) const { @@ -333,6 +342,21 @@ const { updateCustomField: updateComponentCustomField, } = useEntityCustomFields({ entity: () => props.component, entityType: 'composant' }) +// --- Document edit modal --- +const editingDocument = ref(null) +const editModalVisible = ref(false) + +const openEditModal = (doc) => { + editingDocument.value = doc + editModalVisible.value = true +} +const handleDocumentUpdated = async (data) => { + if (!editingDocument.value?.id) return + await editDocument(editingDocument.value.id, data) + editModalVisible.value = false + editingDocument.value = null +} + // --- Collapse state --- const isCollapsed = ref(true) diff --git a/app/components/PieceItem.vue b/app/components/PieceItem.vue index 9d6cd2b..4d72aeb 100644 --- a/app/components/PieceItem.vue +++ b/app/components/PieceItem.vue @@ -6,6 +6,12 @@ :documents="pieceDocuments" @close="closePreview" /> +
@@ -247,9 +253,11 @@
@@ -329,6 +337,7 @@ const { refreshDocuments, handleFilesAdded, removeDocument, + editDocument, } = useEntityDocuments({ entity: () => props.piece, entityType: 'piece' }) const { @@ -343,6 +352,21 @@ const { updateCustomField, } = useEntityCustomFields({ entity: () => props.piece, entityType: 'piece' }) +// --- Document edit modal --- +const editingDocument = ref(null) +const editModalVisible = ref(false) + +const openEditModal = (doc) => { + editingDocument.value = doc + editModalVisible.value = true +} +const handleDocumentUpdated = async (data) => { + if (!editingDocument.value?.id) return + await editDocument(editingDocument.value.id, data) + editModalVisible.value = false + editingDocument.value = null +} + // --- Collapse state --- const isCollapsed = ref(true) diff --git a/app/pages/component/[id]/edit.vue b/app/pages/component/[id]/edit.vue index c0387a6..3014a27 100644 --- a/app/pages/component/[id]/edit.vue +++ b/app/pages/component/[id]/edit.vue @@ -6,6 +6,12 @@ :documents="componentDocuments" @close="closePreview" /> +
@@ -334,10 +342,13 @@ diff --git a/app/pages/pieces/[id]/edit.vue b/app/pages/pieces/[id]/edit.vue index a04e158..0724c79 100644 --- a/app/pages/pieces/[id]/edit.vue +++ b/app/pages/pieces/[id]/edit.vue @@ -6,6 +6,12 @@ :documents="pieceDocuments" @close="closePreview" /> +
@@ -271,10 +279,13 @@ diff --git a/app/pages/product/[id]/edit.vue b/app/pages/product/[id]/edit.vue index 90b295f..8f19d7e 100644 --- a/app/pages/product/[id]/edit.vue +++ b/app/pages/product/[id]/edit.vue @@ -6,6 +6,12 @@ :documents="productDocuments" @close="closePreview" /> +
@@ -244,6 +252,7 @@ const { loadDocumentsByProduct, uploadDocuments: uploadProductDocuments, deleteDocument: deleteProductDocument, + updateDocument, } = useDocuments() const { ensureConstructeurs } = useConstructeurs() const { @@ -265,6 +274,8 @@ const loadingDocuments = ref(false) const productDocuments = ref([]) const previewDocument = ref(null) const previewVisible = ref(false) +const editingDocument = ref(null) +const editModalVisible = ref(false) const historyFieldLabels: Record = { name: 'Nom', @@ -307,6 +318,23 @@ const openPreview = (doc: any) => { } const closePreview = () => { previewVisible.value = false; previewDocument.value = null } +const openEditModal = (doc: any) => { + editingDocument.value = doc + editModalVisible.value = true +} +const handleDocumentUpdated = async (data: { name?: string; type?: string }) => { + if (!editingDocument.value?.id) return + const result = await updateDocument(editingDocument.value.id, data) + if (result.success) { + const idx = productDocuments.value.findIndex((d: any) => d.id === editingDocument.value?.id) + if (idx !== -1) { + productDocuments.value[idx] = { ...productDocuments.value[idx], ...data } + } + } + editModalVisible.value = false + editingDocument.value = null +} + const loadProduct = async () => { const id = route.params.id if (!id || typeof id !== 'string') {