From 5501b3b5ef5bf830c0b01e91c68683fa9b5b5d84 Mon Sep 17 00:00:00 2001 From: MatthieuTD <39524319+MatthieuTD@users.noreply.github.com> Date: Mon, 22 Sep 2025 11:12:00 +0200 Subject: [PATCH] feat: auto complete missing custom fields on machine page --- app/composables/useMachines.js | 33 +++- app/pages/machine/[id].vue | 327 ++++++++++++++++++++++++++++++++- 2 files changed, 355 insertions(+), 5 deletions(-) diff --git a/app/composables/useMachines.js b/app/composables/useMachines.js index 5b39196..31cc6ab 100644 --- a/app/composables/useMachines.js +++ b/app/composables/useMachines.js @@ -97,6 +97,34 @@ export function useMachines() { } } + const addMissingCustomFields = async (machineId, { showToast: shouldShowToast = true } = {}) => { + if (!machineId) { + const error = 'Identifiant de machine manquant' + if (shouldShowToast) { + showError(error) + } + return { success: false, error } + } + + try { + const result = await post(`/machines/${machineId}/add-custom-fields`) + if (result.success) { + if (shouldShowToast) { + showSuccess('Champs personnalisés complétés avec succès') + } + } else if (shouldShowToast && result.error) { + showError(result.error) + } + return result + } catch (error) { + console.error('Erreur lors de l’ajout des champs personnalisés manquants:', error) + if (shouldShowToast) { + showError('Erreur lors de la complétion des champs personnalisés') + } + return { success: false, error: error.message } + } + } + const deleteMachine = async (id) => { loading.value = true try { @@ -143,6 +171,7 @@ export function useMachines() { getMachinesBySite, getMachinesByType, getMachines, - isLoading + isLoading, + addMissingCustomFields } -} +} diff --git a/app/pages/machine/[id].vue b/app/pages/machine/[id].vue index c34f8da..eb19ff4 100644 --- a/app/pages/machine/[id].vue +++ b/app/pages/machine/[id].vue @@ -43,6 +43,20 @@ > Modifier les éléments du squelette +