Browse Source

feat(nc-gui): add countByStack logic

pull/3818/head
Wing-Kam Wong 2 years ago
parent
commit
0151e5aee6
  1. 10
      packages/nc-gui/components/smartsheet/Kanban.vue
  2. 25
      packages/nc-gui/composables/useKanbanViewData.ts

10
packages/nc-gui/components/smartsheet/Kanban.vue

@ -43,6 +43,7 @@ const {
groupingFieldColOptions,
groupingField,
groupingFieldColumn,
countByStack,
} = useKanbanViewData(meta, view as any)
const { isUIAllowed } = useUIPermission()
@ -143,7 +144,10 @@ async function onMove(event: any, stackKey: string) {
if (event.added) {
const ele = event.added.element
ele.row[groupingField.value] = stackKey === 'Uncategorized' ? null : stackKey
countByStack.value[stackKey] += 1
await updateOrSaveRow(ele)
} else if (event.removed) {
countByStack.value[stackKey] -= 1
}
}
@ -282,11 +286,11 @@ openNewRecordFormHook?.on(async () => {
</div>
</a-layout-content>
<a-layout-footer>
<div v-if="formattedData[stack.title]" class="mt-5 text-center">
<div v-if="formattedData[stack.title] && countByStack[stack.title] >= 0" class="mt-5 text-center">
<mdi-plus class="text-pint-500 text-lg text-primary cursor-pointer" @click="openNewRecordFormHook.trigger()" />
<div class="nc-kanban-data-count">
{{ formattedData[stack.title].length }}
{{ formattedData[stack.title].length !== 1 ? $t('objects.records') : $t('objects.record') }}
{{ formattedData[stack.title].length }} / {{ countByStack[stack.title] }}
{{ countByStack[stack.title] !== 1 ? $t('objects.records') : $t('objects.record') }}
</div>
</div>
</a-layout-footer>

25
packages/nc-gui/composables/useKanbanViewData.ts

@ -33,6 +33,7 @@ export function useKanbanViewData(
// ],
// }
const formattedData = useState<Record<string, Row[]>>('KanbanFormattedData', () => ({}))
const countByStack = useState<Record<string, Row[]>>('KanbanCountByStack', () => ({}))
const groupingField = useState<string>('KanbanGroupingField', () => '')
const groupingFieldColumn = useState<Record<string, any>>('KanbanGroupingFieldColumn', () => ({}))
@ -46,21 +47,30 @@ export function useKanbanViewData(
async function loadKanbanData() {
if ((!project?.value?.id || !meta?.value?.id || !viewMeta?.value?.id) && !isPublic.value) return
// reset formattedData to avoid storing previous data after changing grouping field
// reset formattedData & countByStack to avoid storing previous data after changing grouping field
formattedData.value = {}
countByStack.value = {}
await Promise.all(
groupingFieldColOptions.value.map(async (option) => {
let where = `(${groupingField.value},eq,${option.title})`
if (option.title === 'Uncategorized') {
where = `(${groupingField.value},is,null)`
}
const response = await api.dbViewRow.list('noco', project.value.id!, meta!.value.id!, viewMeta!.value.id, {
const where =
option.title === 'Uncategorized' ? `(${groupingField.value},is,null)` : `(${groupingField.value},eq,${option.title})`
formattedData.value[option.title] = formatData(
(
await api.dbViewRow.list('noco', project.value.id!, meta!.value.id!, viewMeta!.value.id, {
...(isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(sorts.value) }),
...(isUIAllowed('filterSync') ? {} : { filterArrJson: JSON.stringify(nestedFilters.value) }),
where,
})
formattedData.value[option.title] = formatData(response.list)
).list,
)
countByStack.value[option.title] =
(
await api.dbViewRow.count('noco', project.value.id!, meta!.value.id!, viewMeta!.value.id, {
where,
})
).count || 0
}),
)
}
@ -230,6 +240,7 @@ export function useKanbanViewData(
updateKanbanMeta,
kanbanMetaData,
formattedData,
countByStack,
groupingField,
groupingFieldColOptions,
groupingFieldColumn,

Loading…
Cancel
Save