|
|
@ -36,6 +36,7 @@ export function useKanbanViewData( |
|
|
|
const countByStack = useState<Record<string, number>>('KanbanCountByStack', () => ({})) |
|
|
|
const countByStack = useState<Record<string, number>>('KanbanCountByStack', () => ({})) |
|
|
|
const groupingField = useState<string>('KanbanGroupingField', () => '') |
|
|
|
const groupingField = useState<string>('KanbanGroupingField', () => '') |
|
|
|
const groupingFieldColumn = useState<Record<string, any>>('KanbanGroupingFieldColumn', () => ({})) |
|
|
|
const groupingFieldColumn = useState<Record<string, any>>('KanbanGroupingFieldColumn', () => ({})) |
|
|
|
|
|
|
|
const stackMetaObj = ref<Record<string, any>>({}) |
|
|
|
|
|
|
|
|
|
|
|
const formatData = (list: Record<string, any>[]) => |
|
|
|
const formatData = (list: Record<string, any>[]) => |
|
|
|
list.map((row) => ({ |
|
|
|
list.map((row) => ({ |
|
|
@ -89,22 +90,27 @@ export function useKanbanViewData( |
|
|
|
|
|
|
|
|
|
|
|
const { grp_column_id, stack_meta } = kanbanMetaData.value |
|
|
|
const { grp_column_id, stack_meta } = kanbanMetaData.value |
|
|
|
|
|
|
|
|
|
|
|
const stackMetaObj = stack_meta ? JSON.parse(stack_meta as string) : {} |
|
|
|
stackMetaObj.value = stack_meta ? JSON.parse(stack_meta as string) : {} |
|
|
|
|
|
|
|
|
|
|
|
if (stackMetaObj && grp_column_id && stackMetaObj[grp_column_id] && groupingFieldColumn.value?.colOptions?.options) { |
|
|
|
if ( |
|
|
|
|
|
|
|
stackMetaObj.value && |
|
|
|
|
|
|
|
grp_column_id && |
|
|
|
|
|
|
|
stackMetaObj.value[grp_column_id] && |
|
|
|
|
|
|
|
groupingFieldColumn.value?.colOptions?.options |
|
|
|
|
|
|
|
) { |
|
|
|
// keep the existing order (index of the array) but update the values
|
|
|
|
// keep the existing order (index of the array) but update the values
|
|
|
|
for (const option of groupingFieldColumn.value.colOptions.options) { |
|
|
|
for (const option of groupingFieldColumn.value.colOptions.options) { |
|
|
|
const idx = stackMetaObj[grp_column_id].findIndex((ele: Record<string, any>) => ele.id === option.id) |
|
|
|
const idx = stackMetaObj.value[grp_column_id].findIndex((ele: Record<string, any>) => ele.id === option.id) |
|
|
|
if (idx !== -1) { |
|
|
|
if (idx !== -1) { |
|
|
|
// update the option in stackMetaObj
|
|
|
|
// update the option in stackMetaObj
|
|
|
|
stackMetaObj[grp_column_id][idx] = { |
|
|
|
stackMetaObj.value[grp_column_id][idx] = { |
|
|
|
...stackMetaObj[grp_column_id][idx], |
|
|
|
...stackMetaObj.value[grp_column_id][idx], |
|
|
|
...option, |
|
|
|
...option, |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// new option found
|
|
|
|
// new option found
|
|
|
|
const len = stackMetaObj[grp_column_id].length |
|
|
|
const len = stackMetaObj.value[grp_column_id].length |
|
|
|
stackMetaObj[grp_column_id][len] = { |
|
|
|
stackMetaObj.value[grp_column_id][len] = { |
|
|
|
...option, |
|
|
|
...option, |
|
|
|
collapsed: false, |
|
|
|
collapsed: false, |
|
|
|
} |
|
|
|
} |
|
|
@ -112,15 +118,15 @@ export function useKanbanViewData( |
|
|
|
} |
|
|
|
} |
|
|
|
// handle deleted options
|
|
|
|
// handle deleted options
|
|
|
|
const columnOptionIds = groupingFieldColumn.value.colOptions.options.map(({ id }) => id) |
|
|
|
const columnOptionIds = groupingFieldColumn.value.colOptions.options.map(({ id }) => id) |
|
|
|
stackMetaObj[grp_column_id] |
|
|
|
stackMetaObj.value[grp_column_id] |
|
|
|
.filter(({ id }) => id !== 'uncategorized' && !columnOptionIds.includes(id)) |
|
|
|
.filter(({ id }) => id !== 'uncategorized' && !columnOptionIds.includes(id)) |
|
|
|
.forEach(({ id }) => { |
|
|
|
.forEach(({ id }) => { |
|
|
|
const idx = stackMetaObj[grp_column_id].map((ele: Record<string, any>) => ele.id).indexOf(id) |
|
|
|
const idx = stackMetaObj.value[grp_column_id].map((ele: Record<string, any>) => ele.id).indexOf(id) |
|
|
|
if (idx !== -1) { |
|
|
|
if (idx !== -1) { |
|
|
|
stackMetaObj[grp_column_id].splice(idx, 1) |
|
|
|
stackMetaObj.value[grp_column_id].splice(idx, 1) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
groupingFieldColOptions.value = stackMetaObj[grp_column_id] |
|
|
|
groupingFieldColOptions.value = stackMetaObj.value[grp_column_id] |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// build stack meta
|
|
|
|
// build stack meta
|
|
|
|
groupingFieldColOptions.value = [ |
|
|
|
groupingFieldColOptions.value = [ |
|
|
@ -136,11 +142,15 @@ export function useKanbanViewData( |
|
|
|
collapsed: false, |
|
|
|
collapsed: false, |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
// if grouping column id is present, add the grouping field column options to stackMetaObj
|
|
|
|
await updateKanbanStackMeta() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function updateKanbanStackMeta() { |
|
|
|
|
|
|
|
const { grp_column_id } = kanbanMetaData.value |
|
|
|
if (grp_column_id) { |
|
|
|
if (grp_column_id) { |
|
|
|
stackMetaObj[grp_column_id] = groupingFieldColOptions.value |
|
|
|
stackMetaObj.value[grp_column_id] = groupingFieldColOptions.value |
|
|
|
await updateKanbanMeta({ |
|
|
|
await updateKanbanMeta({ |
|
|
|
stack_meta: stackMetaObj, |
|
|
|
stack_meta: stackMetaObj.value, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -288,5 +298,6 @@ export function useKanbanViewData( |
|
|
|
updateOrSaveRow, |
|
|
|
updateOrSaveRow, |
|
|
|
addEmptyRow, |
|
|
|
addEmptyRow, |
|
|
|
deleteStack, |
|
|
|
deleteStack, |
|
|
|
|
|
|
|
updateKanbanStackMeta, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|