From 01b4d0f97341203f64c5f2130f99032e3b076858 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Wed, 25 Mar 2026 15:19:33 +0100 Subject: [PATCH] Fix for missing Phases --- frontend/components/EntityEdit.vue | 38 +++++++++++++++++++++++++++++- frontend/stores/data.js | 23 +++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/frontend/components/EntityEdit.vue b/frontend/components/EntityEdit.vue index 083397e..f317818 100644 --- a/frontend/components/EntityEdit.vue +++ b/frontend/components/EntityEdit.vue @@ -240,9 +240,42 @@ const loadOptions = async () => { } } -loadOptions() normalizeLoadedSelectValues() +const initialProjecttype = props.type === "projects" ? item.value.projecttype : null +const lastAppliedProjecttype = ref(null) + +const syncProjectPhasesForProjecttype = () => { + if (props.type !== "projects") return + if (!item.value?.projecttype) return + if (!Array.isArray(loadedOptions.value.projecttypes) || !loadedOptions.value.projecttypes.length) return + + const projecttypeColumn = dataType.templateColumns.find((column) => column.key === "projecttype") + if (!projecttypeColumn?.inputChangeFunction) return + + const shouldSyncOnCreate = props.mode === "create" && lastAppliedProjecttype.value !== item.value.projecttype + const shouldSyncOnEdit = props.mode === "edit" + && item.value.projecttype !== initialProjecttype + && lastAppliedProjecttype.value !== item.value.projecttype + + if (!shouldSyncOnCreate && !shouldSyncOnEdit) return + + projecttypeColumn.inputChangeFunction(item.value, loadedOptions.value) + lastAppliedProjecttype.value = item.value.projecttype +} + +loadOptions().then(() => { + syncProjectPhasesForProjecttype() +}) + +watch( + () => [item.value?.projecttype, loadedOptions.value.projecttypes?.length || 0], + () => { + syncProjectPhasesForProjecttype() + }, + { immediate: true } +) + const contentChanged = (content, datapoint) => { if (datapoint.key.includes(".")) { item.value[datapoint.key.split('.')[0]][datapoint.key.split('.')[1]].html = content.html @@ -274,6 +307,9 @@ const getSelectSearchInput = (datapoint) => { const triggerInputChange = (datapoint) => { if (datapoint.inputChangeFunction) { datapoint.inputChangeFunction(item.value, loadedOptions.value) + if (datapoint.key === "projecttype") { + lastAppliedProjecttype.value = item.value.projecttype + } } } diff --git a/frontend/stores/data.js b/frontend/stores/data.js index 566ac8e..03003e4 100644 --- a/frontend/stores/data.js +++ b/frontend/stores/data.js @@ -1443,7 +1443,28 @@ export const useDataStore = defineStore('data', () => { selectOptionAttribute: "name", selectSearchAttributes: ['name'], inputChangeFunction: function (item,loadedOptions = {}) { - item.phases = loadedOptions.projecttypes.find(i => i.id === item.projecttype).initialPhases + const selectedProjectType = loadedOptions.projecttypes?.find(i => i.id === item.projecttype) + + if (!selectedProjectType || !Array.isArray(selectedProjectType.initialPhases)) { + item.phases = [] + item.active_phase = null + return + } + + const phases = selectedProjectType.initialPhases.map((phase, index) => ({ + key: phase?.key || crypto.randomUUID(), + icon: phase?.icon || '', + label: phase?.label || '', + optional: Boolean(phase?.optional), + description: phase?.description || '', + quickactions: Array.isArray(phase?.quickactions) ? phase.quickactions.map((quickaction) => ({ + ...quickaction + })) : [], + active: index === 0 + })) + + item.phases = phases + item.active_phase = phases.find(i => i.active)?.label || null }, sortable: true },{