Fix for missing Phases
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
},{
|
||||
|
||||
Reference in New Issue
Block a user