|
|
@ -19,6 +19,7 @@ export function useKanbanViewData( |
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
|
const groupingFieldColOptions = useState<Record<string, any>[]>('KanbanGroupingFieldColOptions', () => []) |
|
|
|
const groupingFieldColOptions = useState<Record<string, any>[]>('KanbanGroupingFieldColOptions', () => []) |
|
|
|
const kanbanMetaData = useState<KanbanType>('KanbanMetaData', () => ({})) |
|
|
|
const kanbanMetaData = useState<KanbanType>('KanbanMetaData', () => ({})) |
|
|
|
|
|
|
|
// formattedData structure
|
|
|
|
// {
|
|
|
|
// {
|
|
|
|
// [val1] : [
|
|
|
|
// [val1] : [
|
|
|
|
// {row: {...}, oldRow: {...}, rowMeta: {...}},
|
|
|
|
// {row: {...}, oldRow: {...}, rowMeta: {...}},
|
|
|
@ -47,17 +48,35 @@ export function useKanbanViewData( |
|
|
|
// TODO: handle share view case
|
|
|
|
// TODO: handle share view case
|
|
|
|
if ((!project?.value?.id || !meta?.value?.id || !viewMeta?.value?.id) && !isPublic.value) return |
|
|
|
if ((!project?.value?.id || !meta?.value?.id || !viewMeta?.value?.id) && !isPublic.value) return |
|
|
|
|
|
|
|
|
|
|
|
// reset formattedData to avoid storing previous data
|
|
|
|
// reset formattedData to avoid storing previous data after changing grouping field
|
|
|
|
// after changing grouping field
|
|
|
|
|
|
|
|
formattedData.value = {} |
|
|
|
formattedData.value = {} |
|
|
|
|
|
|
|
|
|
|
|
// grouping field column options
|
|
|
|
const { grp_column_id, stack_meta } = kanbanMetaData.value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const stackMetaObj = JSON.parse(stack_meta as string) || {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stack_meta && grp_column_id && stackMetaObj[grp_column_id]) { |
|
|
|
|
|
|
|
// the target stack meta exists, use it directly
|
|
|
|
|
|
|
|
groupingFieldColOptions.value = stackMetaObj[grp_column_id] |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// retrieve the grouping field column
|
|
|
|
const groupingFieldColumn = meta?.value?.columns?.filter((f) => f.title === groupingField.value)[0] as Record<string, any> |
|
|
|
const groupingFieldColumn = meta?.value?.columns?.filter((f) => f.title === groupingField.value)[0] as Record<string, any> |
|
|
|
|
|
|
|
// build stack meta
|
|
|
|
groupingFieldColOptions.value = [ |
|
|
|
groupingFieldColOptions.value = [ |
|
|
|
...(groupingFieldColumn?.colOptions?.options ?? []), |
|
|
|
...(groupingFieldColumn?.colOptions?.options ?? []), |
|
|
|
|
|
|
|
// enrich uncategorized stack
|
|
|
|
{ id: 'uncategorized', title: 'Uncategorized', order: 0 }, |
|
|
|
{ id: 'uncategorized', title: 'Uncategorized', order: 0 }, |
|
|
|
].sort((a: Record<string, any>, b: Record<string, any>) => a.order - b.order) |
|
|
|
].sort((a: Record<string, any>, b: Record<string, any>) => a.order - b.order) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if grouping column id is present, add the grouping field column options to stackMetaObj
|
|
|
|
|
|
|
|
if (grp_column_id) { |
|
|
|
|
|
|
|
stackMetaObj[grp_column_id] = groupingFieldColOptions.value |
|
|
|
|
|
|
|
await updateKanbanMeta({ |
|
|
|
|
|
|
|
stack_meta: stackMetaObj, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await Promise.all( |
|
|
|
await Promise.all( |
|
|
|
groupingFieldColOptions.value.map(async (option) => { |
|
|
|
groupingFieldColOptions.value.map(async (option) => { |
|
|
|
let where = `(${groupingField.value},eq,${option.title})` |
|
|
|
let where = `(${groupingField.value},eq,${option.title})` |
|
|
@ -83,6 +102,15 @@ export function useKanbanViewData( |
|
|
|
groupingField.value = groupingFieldCol?.title as string |
|
|
|
groupingField.value = groupingFieldCol?.title as string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function updateKanbanMeta(updateObj: Partial<KanbanType>) { |
|
|
|
|
|
|
|
if (!viewMeta?.value?.id) return |
|
|
|
|
|
|
|
await $api.dbView.kanbanUpdate(viewMeta.value.id, { |
|
|
|
|
|
|
|
...kanbanMetaData.value, |
|
|
|
|
|
|
|
...updateObj, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
await loadKanbanMeta() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function insertRow(row: Record<string, any>, rowIndex = formattedData.value.uncatgorized?.length) { |
|
|
|
async function insertRow(row: Record<string, any>, rowIndex = formattedData.value.uncatgorized?.length) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const insertObj = meta?.value?.columns?.reduce((o: any, col) => { |
|
|
|
const insertObj = meta?.value?.columns?.reduce((o: any, col) => { |
|
|
@ -172,6 +200,7 @@ export function useKanbanViewData( |
|
|
|
return { |
|
|
|
return { |
|
|
|
loadKanbanData, |
|
|
|
loadKanbanData, |
|
|
|
loadKanbanMeta, |
|
|
|
loadKanbanMeta, |
|
|
|
|
|
|
|
updateKanbanMeta, |
|
|
|
kanbanMetaData, |
|
|
|
kanbanMetaData, |
|
|
|
formattedData, |
|
|
|
formattedData, |
|
|
|
groupingField, |
|
|
|
groupingField, |
|
|
|