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. 33
      packages/nc-gui/composables/useKanbanViewData.ts

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

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

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

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

Loading…
Cancel
Save