|
|
@ -1,13 +1,22 @@ |
|
|
|
import { ViewTypes } from 'nocodb-sdk' |
|
|
|
import {ViewTypes} from 'nocodb-sdk' |
|
|
|
import axios from 'axios' |
|
|
|
import axios from 'axios' |
|
|
|
import type { Api, ColumnType, FormColumnType, FormType, GalleryType, PaginatedType, TableType, ViewType } from 'nocodb-sdk' |
|
|
|
import type { |
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
Api, |
|
|
|
import { NavigateDir } from '#imports' |
|
|
|
ColumnType, |
|
|
|
|
|
|
|
FormColumnType, |
|
|
|
|
|
|
|
FormType, |
|
|
|
|
|
|
|
GalleryType, |
|
|
|
|
|
|
|
PaginatedType, |
|
|
|
|
|
|
|
TableType, |
|
|
|
|
|
|
|
ViewType |
|
|
|
|
|
|
|
} from 'nocodb-sdk' |
|
|
|
|
|
|
|
import type {ComputedRef, Ref} from 'vue' |
|
|
|
|
|
|
|
import {NavigateDir} from '#imports' |
|
|
|
|
|
|
|
|
|
|
|
const formatData = (list: Record<string, any>[]) => |
|
|
|
const formatData = (list: Record<string, any>[]) => |
|
|
|
list.map((row) => ({ |
|
|
|
list.map((row) => ({ |
|
|
|
row: { ...row }, |
|
|
|
row: {...row}, |
|
|
|
oldRow: { ...row }, |
|
|
|
oldRow: {...row}, |
|
|
|
rowMeta: {}, |
|
|
|
rowMeta: {}, |
|
|
|
})) |
|
|
|
})) |
|
|
|
|
|
|
|
|
|
|
@ -16,26 +25,26 @@ export function useViewData( |
|
|
|
viewMeta: Ref<ViewType | undefined> | ComputedRef<(ViewType & { id: string }) | undefined>, |
|
|
|
viewMeta: Ref<ViewType | undefined> | ComputedRef<(ViewType & { id: string }) | undefined>, |
|
|
|
where?: ComputedRef<string | undefined>, |
|
|
|
where?: ComputedRef<string | undefined>, |
|
|
|
) { |
|
|
|
) { |
|
|
|
const { activeTableId, activeTable } = storeToRefs(useTablesStore()) |
|
|
|
const {activeTableId, activeTable} = storeToRefs(useTablesStore()) |
|
|
|
|
|
|
|
|
|
|
|
const meta = computed(() => _meta.value || activeTable.value) |
|
|
|
const meta = computed(() => _meta.value || activeTable.value) |
|
|
|
const metaId = computed(() => _meta.value?.id || activeTableId.value) |
|
|
|
const metaId = computed(() => _meta.value?.id || activeTableId.value) |
|
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n() |
|
|
|
const {t} = useI18n() |
|
|
|
|
|
|
|
|
|
|
|
const optimisedQuery = useState('optimisedQuery', () => true) |
|
|
|
const optimisedQuery = useState('optimisedQuery', () => true) |
|
|
|
|
|
|
|
|
|
|
|
const { api, isLoading, error } = useApi() |
|
|
|
const {api, isLoading, error} = useApi() |
|
|
|
|
|
|
|
|
|
|
|
const router = useRouter() |
|
|
|
const router = useRouter() |
|
|
|
|
|
|
|
|
|
|
|
const route = router.currentRoute |
|
|
|
const route = router.currentRoute |
|
|
|
|
|
|
|
|
|
|
|
const { appInfo, gridViewPageSize } = useGlobal() |
|
|
|
const {appInfo, gridViewPageSize} = useGlobal() |
|
|
|
|
|
|
|
|
|
|
|
const appInfoDefaultLimit = gridViewPageSize.value || appInfo.value.defaultLimit || 25 |
|
|
|
const appInfoDefaultLimit = gridViewPageSize.value || appInfo.value.defaultLimit || 25 |
|
|
|
|
|
|
|
|
|
|
|
const _paginationData = ref<PaginatedType>({ page: 1, pageSize: appInfoDefaultLimit }) |
|
|
|
const _paginationData = ref<PaginatedType>({page: 1, pageSize: appInfoDefaultLimit}) |
|
|
|
|
|
|
|
|
|
|
|
const aggCommentCount = ref<{ row_id: string; count: string }[]>([]) |
|
|
|
const aggCommentCount = ref<{ row_id: string; count: string }[]>([]) |
|
|
|
|
|
|
|
|
|
|
@ -51,19 +60,19 @@ export function useViewData( |
|
|
|
|
|
|
|
|
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
|
|
|
|
|
|
|
|
const { base } = storeToRefs(useBase()) |
|
|
|
const {base} = storeToRefs(useBase()) |
|
|
|
|
|
|
|
|
|
|
|
const { sharedView, fetchSharedViewData, paginationData: sharedPaginationData } = useSharedView() |
|
|
|
const {sharedView, fetchSharedViewData, paginationData: sharedPaginationData} = useSharedView() |
|
|
|
|
|
|
|
|
|
|
|
const { $api } = useNuxtApp() |
|
|
|
const {$api} = useNuxtApp() |
|
|
|
|
|
|
|
|
|
|
|
const { sorts, nestedFilters } = useSmartsheetStoreOrThrow() |
|
|
|
const {sorts, nestedFilters} = useSmartsheetStoreOrThrow() |
|
|
|
|
|
|
|
|
|
|
|
const { isUIAllowed } = useRoles() |
|
|
|
const {isUIAllowed} = useRoles() |
|
|
|
|
|
|
|
|
|
|
|
const routeQuery = computed(() => route.value.query as Record<string, string>) |
|
|
|
const routeQuery = computed(() => route.value.query as Record<string, string>) |
|
|
|
|
|
|
|
|
|
|
|
const { isPaginationLoading } = storeToRefs(useViewsStore()) |
|
|
|
const {isPaginationLoading} = storeToRefs(useViewsStore()) |
|
|
|
|
|
|
|
|
|
|
|
const paginationData = computed({ |
|
|
|
const paginationData = computed({ |
|
|
|
get: () => (isPublic.value ? sharedPaginationData.value : _paginationData.value), |
|
|
|
get: () => (isPublic.value ? sharedPaginationData.value : _paginationData.value), |
|
|
@ -93,7 +102,7 @@ export function useViewData( |
|
|
|
})) |
|
|
|
})) |
|
|
|
|
|
|
|
|
|
|
|
async function syncCount() { |
|
|
|
async function syncCount() { |
|
|
|
const { count } = await $api.dbViewRow.count( |
|
|
|
const {count} = await $api.dbViewRow.count( |
|
|
|
NOCO, |
|
|
|
NOCO, |
|
|
|
base?.value?.id as string, |
|
|
|
base?.value?.id as string, |
|
|
|
metaId.value as string, |
|
|
|
metaId.value as string, |
|
|
@ -136,13 +145,14 @@ export function useViewData( |
|
|
|
if (isPublic.value) return |
|
|
|
if (isPublic.value) return |
|
|
|
|
|
|
|
|
|
|
|
const ids = formattedData.value |
|
|
|
const ids = formattedData.value |
|
|
|
?.filter(({ rowMeta: { new: isNew } }) => !isNew) |
|
|
|
?.filter(({rowMeta: {new: isNew}}) => !isNew) |
|
|
|
?.map(({ row }) => { |
|
|
|
?.map(({row}) => { |
|
|
|
return extractPkFromRow(row, meta?.value?.columns as ColumnType[]) |
|
|
|
return extractPkFromRow(row, meta?.value?.columns as ColumnType[]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if (!ids?.length || ids?.some((id) => !id)) return |
|
|
|
if (!ids?.length || ids?.some((id) => !id)) return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
aggCommentCount.value = await $api.utils.commentCount({ |
|
|
|
aggCommentCount.value = await $api.utils.commentCount({ |
|
|
|
ids, |
|
|
|
ids, |
|
|
|
fk_model_id: metaId.value as string, |
|
|
|
fk_model_id: metaId.value as string, |
|
|
@ -152,6 +162,9 @@ export function useViewData( |
|
|
|
const id = extractPkFromRow(row.row, meta.value?.columns as ColumnType[]) |
|
|
|
const id = extractPkFromRow(row.row, meta.value?.columns as ColumnType[]) |
|
|
|
row.rowMeta.commentCount = +(aggCommentCount.value?.find((c: Record<string, any>) => c.row_id === id)?.count || 0) |
|
|
|
row.rowMeta.commentCount = +(aggCommentCount.value?.find((c: Record<string, any>) => c.row_id === id)?.count || 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
console.error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const controller = ref() |
|
|
|
const controller = ref() |
|
|
@ -180,16 +193,16 @@ export function useViewData( |
|
|
|
{ |
|
|
|
{ |
|
|
|
...queryParams.value, |
|
|
|
...queryParams.value, |
|
|
|
...params, |
|
|
|
...params, |
|
|
|
...(isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(sorts.value) }), |
|
|
|
...(isUIAllowed('sortSync') ? {} : {sortArrJson: JSON.stringify(sorts.value)}), |
|
|
|
...(isUIAllowed('filterSync') ? {} : { filterArrJson: JSON.stringify(nestedFilters.value) }), |
|
|
|
...(isUIAllowed('filterSync') ? {} : {filterArrJson: JSON.stringify(nestedFilters.value)}), |
|
|
|
where: where?.value, |
|
|
|
where: where?.value, |
|
|
|
...(excludePageInfo.value ? { excludeCount: 'true' } : {}), |
|
|
|
...(excludePageInfo.value ? {excludeCount: 'true'} : {}), |
|
|
|
} as any, |
|
|
|
} as any, |
|
|
|
{ |
|
|
|
{ |
|
|
|
cancelToken: controller.value.token, |
|
|
|
cancelToken: controller.value.token, |
|
|
|
}, |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
: await fetchSharedViewData({ sortsArr: sorts.value, filtersArr: nestedFilters.value, where: where?.value }) |
|
|
|
: await fetchSharedViewData({sortsArr: sorts.value, filtersArr: nestedFilters.value, where: where?.value}) |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
// if the request is canceled, then do nothing
|
|
|
|
// if the request is canceled, then do nothing
|
|
|
|
if (error.code === 'ERR_CANCELED') { |
|
|
|
if (error.code === 'ERR_CANCELED') { |
|
|
@ -269,7 +282,7 @@ export function useViewData( |
|
|
|
async function loadFormView() { |
|
|
|
async function loadFormView() { |
|
|
|
if (!viewMeta?.value?.id) return |
|
|
|
if (!viewMeta?.value?.id) return |
|
|
|
try { |
|
|
|
try { |
|
|
|
const { columns, ...view } = await $api.dbView.formRead(viewMeta.value.id) |
|
|
|
const {columns, ...view} = await $api.dbView.formRead(viewMeta.value.id) |
|
|
|
let order = 1 |
|
|
|
let order = 1 |
|
|
|
const fieldById = (columns || []).reduce((o: Record<string, any>, f: Record<string, any>) => { |
|
|
|
const fieldById = (columns || []).reduce((o: Record<string, any>, f: Record<string, any>) => { |
|
|
|
if (order < f.order) { |
|
|
|
if (order < f.order) { |
|
|
@ -289,7 +302,7 @@ export function useViewData( |
|
|
|
fk_column_id: c.id, |
|
|
|
fk_column_id: c.id, |
|
|
|
fk_view_id: viewMeta.value?.id, |
|
|
|
fk_view_id: viewMeta.value?.id, |
|
|
|
...(fieldById[c.id!] ? fieldById[c.id!] : {}), |
|
|
|
...(fieldById[c.id!] ? fieldById[c.id!] : {}), |
|
|
|
meta: { validators: [], ...parseProp(fieldById[c.id!]?.meta), ...parseProp(c.meta) }, |
|
|
|
meta: {validators: [], ...parseProp(fieldById[c.id!]?.meta), ...parseProp(c.meta)}, |
|
|
|
order: (fieldById[c.id!] && fieldById[c.id!].order) || order++, |
|
|
|
order: (fieldById[c.id!] && fieldById[c.id!].order) || order++, |
|
|
|
id: fieldById[c.id!] && fieldById[c.id!].id, |
|
|
|
id: fieldById[c.id!] && fieldById[c.id!].id, |
|
|
|
})) |
|
|
|
})) |
|
|
|