Browse Source

fix(nc-gui): wire new apis

pull/7716/head
DarkPhoenix2704 10 months ago
parent
commit
79a5de198e
  1. 241
      packages/nc-gui/composables/useCalendarViewStore.ts
  2. 53
      packages/nc-gui/composables/useSharedView.ts
  3. 8
      packages/nocodb/src/schema/swagger.json

241
packages/nc-gui/composables/useCalendarViewStore.ts

@ -97,7 +97,7 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
const { sorts, nestedFilters } = useSmartsheetStoreOrThrow() const { sorts, nestedFilters } = useSmartsheetStoreOrThrow()
const { sharedView, fetchSharedViewData, fetchSharedViewActiveDate } = useSharedView() const { sharedView, fetchSharedViewData, fetchSharedViewActiveDate, fetchSharedCalendarViewData } = useSharedView()
const calendarMetaData = ref<CalendarType>({}) const calendarMetaData = ref<CalendarType>({})
@ -219,7 +219,6 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
} }
fromDate = fromDate!.format('YYYY-MM-DD HH:mm:ssZ') fromDate = fromDate!.format('YYYY-MM-DD HH:mm:ssZ')
toDate = toDate!.format('YYYY-MM-DD HH:mm:ssZ')
prevDate = prevDate!.format('YYYY-MM-DD HH:mm:ssZ') prevDate = prevDate!.format('YYYY-MM-DD HH:mm:ssZ')
nextDate = nextDate!.format('YYYY-MM-DD HH:mm:ssZ') nextDate = nextDate!.format('YYYY-MM-DD HH:mm:ssZ')
@ -337,112 +336,6 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
} }
} }
const filterJSON = computed(() => {
if (!calendarRange.value) return []
const combinedFilters: any = {
is_group: true,
logical_op: 'and',
children: [],
}
let prevDate: string | null | dayjs.Dayjs = null
let fromDate: dayjs.Dayjs | null | string = null
let toDate: dayjs.Dayjs | null | string = null
let nextDate: string | null | dayjs.Dayjs = null
switch (activeCalendarView.value) {
case 'week':
fromDate = selectedDateRange.value.start.startOf('day')
toDate = selectedDateRange.value.end.endOf('day')
prevDate = selectedDateRange.value.start.subtract(1, 'day').endOf('day')
nextDate = selectedDateRange.value.end.add(1, 'day').startOf('day')
break
case 'month': {
const startOfMonth = selectedMonth.value.startOf('month')
const endOfMonth = selectedMonth.value.endOf('month')
const daysToDisplay = Math.max(endOfMonth.diff(startOfMonth, 'day') + 1, 35)
fromDate = startOfMonth.subtract((startOfMonth.day() + 7) % 7, 'day')
toDate = fromDate.add(daysToDisplay, 'day')
prevDate = fromDate.subtract(1, 'day').endOf('day')
nextDate = toDate.add(1, 'day').startOf('day')
break
}
case 'year':
fromDate = selectedDate.value.startOf('year')
toDate = selectedDate.value.endOf('year')
prevDate = fromDate.subtract(1, 'day').endOf('day')
nextDate = toDate.add(1, 'day').startOf('day')
break
case 'day':
fromDate = selectedDate.value.startOf('day')
toDate = selectedDate.value.endOf('day')
prevDate = selectedDate.value.subtract(1, 'day').endOf('day')
nextDate = selectedDate.value.add(1, 'day').startOf('day')
break
}
fromDate = fromDate!.format('YYYY-MM-DD HH:mm:ssZ')
toDate = toDate!.format('YYYY-MM-DD HH:mm:ssZ')
prevDate = prevDate!.format('YYYY-MM-DD HH:mm:ssZ')
nextDate = nextDate!.format('YYYY-MM-DD HH:mm:ssZ')
calendarRange.value.forEach((range) => {
const fromCol = range.fk_from_col
const toCol = range.fk_to_col
let rangeFilter: any = []
if (fromCol && toCol) {
rangeFilter = [
{
is_group: true,
logical_op: 'and',
children: [
{
fk_column_id: fromCol.id,
comparison_op: 'lt',
comparison_sub_op: 'exactDate',
value: nextDate,
},
{
fk_column_id: toCol.id,
comparison_op: 'gt',
comparison_sub_op: 'exactDate',
value: prevDate,
},
],
},
{
fk_column_id: fromCol.id,
comparison_op: 'eq',
logical_op: 'or',
comparison_sub_op: 'exactDate',
value: fromDate,
},
]
} else if (fromCol) {
rangeFilter = [
{
fk_column_id: fromCol.id,
comparison_op: 'lt',
comparison_sub_op: 'exactDate',
value: nextDate,
},
{
fk_column_id: fromCol.id,
comparison_op: 'gt',
comparison_sub_op: 'exactDate',
value: prevDate,
},
]
}
if (rangeFilter.length > 0) {
combinedFilters.children.push(rangeFilter)
}
})
return combinedFilters.children.length > 0 ? [combinedFilters] : []
})
const fetchActiveDates = async () => { const fetchActiveDates = async () => {
if (!base?.value?.id || !meta.value?.id || !viewMeta.value?.id || !calendarRange.value) return if (!base?.value?.id || !meta.value?.id || !viewMeta.value?.id || !calendarRange.value) return
let prevDate: dayjs.Dayjs | string | null = null let prevDate: dayjs.Dayjs | string | null = null
@ -459,85 +352,31 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
prevDate = fromDate.subtract(1, 'day').endOf('day') prevDate = fromDate.subtract(1, 'day').endOf('day')
nextDate = toDate.add(1, 'day').startOf('day') nextDate = toDate.add(1, 'day').startOf('day')
} else if (activeCalendarView.value === 'year') { } else if (activeCalendarView.value === 'year') {
fromDate = selectedDate.value.startOf('year')
prevDate = selectedDate.value.startOf('year').subtract(1, 'day').endOf('day') prevDate = selectedDate.value.startOf('year').subtract(1, 'day').endOf('day')
nextDate = selectedDate.value.endOf('year').add(1, 'day').startOf('day') nextDate = selectedDate.value.endOf('year').add(1, 'day').startOf('day')
} }
prevDate = prevDate!.format('YYYY-MM-DD HH:mm:ssZ') prevDate = prevDate!.format('YYYY-MM-DD HH:mm:ssZ')
nextDate = nextDate!.format('YYYY-MM-DD HH:mm:ssZ') nextDate = nextDate!.format('YYYY-MM-DD HH:mm:ssZ')
fromDate = fromDate!.format('YYYY-MM-DD HH:mm:ssZ')
const activeDateFilter: Array<any> = [] const activeDateFilter: Array<any> = []
calendarRange.value.forEach((range) => {
const fromCol = range.fk_from_col
const toCol = range.fk_to_col
let rangeFilter: any = []
if (fromCol && toCol) {
rangeFilter = [
{
is_group: true,
logical_op: 'and',
children: [
{
fk_column_id: fromCol.id,
comparison_op: 'lt',
comparison_sub_op: 'exactDate',
value: nextDate,
},
{
fk_column_id: toCol.id,
comparison_op: 'gt',
comparison_sub_op: 'exactDate',
value: prevDate,
},
],
},
{
fk_column_id: fromCol.id,
comparison_op: 'eq',
logical_op: 'or',
comparison_sub_op: 'exactDate',
value: fromDate,
},
]
} else if (fromCol) {
rangeFilter = [
{
fk_column_id: fromCol.id,
comparison_op: 'lt',
comparison_sub_op: 'exactDate',
value: nextDate,
},
{
fk_column_id: fromCol.id,
comparison_op: 'gt',
comparison_sub_op: 'exactDate',
value: prevDate,
},
]
}
activeDateFilter.push(rangeFilter)
})
if (!base?.value?.id || !meta.value?.id || !viewMeta.value?.id) return if (!base?.value?.id || !meta.value?.id || !viewMeta.value?.id) return
try { try {
const res = !isPublic.value const res = !isPublic.value
? await api.dbViewRow.calendarCount('noco', base.value.id!, meta.value!.id!, viewMeta.value.id, { ? await api.dbCalendarViewRowCount.dbCalendarViewRowCount('noco', base.value.id!, meta.value!.id!, viewMeta.value.id, {
...queryParams.value, ...queryParams.value,
...{}, from_date: prevDate,
...{}, to_date: nextDate,
...{ filterArrJson: JSON.stringify([...activeDateFilter]) },
}) })
: await fetchSharedViewActiveDate({ : await fetchSharedViewActiveDate({
from_date: prevDate,
to_date: nextDate,
sortsArr: sorts.value, sortsArr: sorts.value,
filtersArr: activeDateFilter, filtersArr: activeDateFilter,
}) })
activeDates.value = res.map((dateObj: unknown) => dayjs(dateObj)) activeDates.value = res.dates.map((dateObj: unknown) => dayjs(dateObj))
} catch (e) { } catch (e) {
activeDates.value = [] activeDates.value = []
message.error(`${t('msg.error.fetchingActiveDates')} ${await extractSdkResponseErrorMsg(e)}`) message.error(`${t('msg.error.fetchingActiveDates')} ${await extractSdkResponseErrorMsg(e)}`)
@ -585,30 +424,74 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
} }
async function loadCalendarData() { async function loadCalendarData() {
if ((!base?.value?.id || !meta.value?.id || !viewMeta.value?.id || !filterJSON.value) && !isPublic?.value) return if ((!base?.value?.id || !meta.value?.id || !viewMeta.value?.id) && !isPublic?.value) return
let prevDate: string | null | dayjs.Dayjs = null
let fromDate: dayjs.Dayjs | null | string = null
let toDate: dayjs.Dayjs | null | string = null
let nextDate: string | null | dayjs.Dayjs = null
switch (activeCalendarView.value) {
case 'week':
fromDate = selectedDateRange.value.start.startOf('day')
toDate = selectedDateRange.value.end.endOf('day')
prevDate = selectedDateRange.value.start.subtract(1, 'day').endOf('day')
nextDate = selectedDateRange.value.end.add(1, 'day').startOf('day')
break
case 'month': {
const startOfMonth = selectedMonth.value.startOf('month')
const endOfMonth = selectedMonth.value.endOf('month')
const daysToDisplay = Math.max(endOfMonth.diff(startOfMonth, 'day') + 1, 35)
fromDate = startOfMonth.subtract((startOfMonth.day() + 7) % 7, 'day')
toDate = fromDate.add(daysToDisplay, 'day')
prevDate = fromDate.subtract(1, 'day').endOf('day')
nextDate = toDate.add(1, 'day').startOf('day')
break
}
case 'year':
fromDate = selectedDate.value.startOf('year')
toDate = selectedDate.value.endOf('year')
prevDate = fromDate.subtract(1, 'day').endOf('day')
nextDate = toDate.add(1, 'day').startOf('day')
break
case 'day':
fromDate = selectedDate.value.startOf('day')
toDate = selectedDate.value.endOf('day')
prevDate = selectedDate.value.subtract(1, 'day').endOf('day')
nextDate = selectedDate.value.add(1, 'day').startOf('day')
break
}
prevDate = prevDate!.format('YYYY-MM-DD HH:mm:ssZ')
nextDate = nextDate!.format('YYYY-MM-DD HH:mm:ssZ')
try { try {
isCalendarDataLoading.value = true isCalendarDataLoading.value = true
const res = !isPublic.value const res = !isPublic.value
? await api.dbViewRow.list( ? await api.dbCalendarViewRow.list(
'noco', 'noco',
base.value.id!, base.value.id!,
meta.value!.id!, meta.value!.id!,
viewMeta.value!.id!, viewMeta.value!.id!,
{ {
...queryParams.value, from_date: prevDate,
...(isUIAllowed('filterSync') to_date: nextDate,
? { filterArrJson: JSON.stringify([...filterJSON.value]) }
: { filterArrJson: JSON.stringify([nestedFilters.value, ...filterJSON.value]) }),
where: where?.value ?? '',
}, },
{ {
headers: { ...queryParams.value,
'xc-ignore-pagination': true, ...(isUIAllowed('filterSync') ? { filterArrJson: [] } : { filterArrJson: JSON.stringify([nestedFilters.value]) }),
}, where: where?.value ?? '',
filterArrJson: JSON.stringify([...nestedFilters.value]),
}, },
) )
: await fetchSharedViewData({ sortsArr: sorts.value, filtersArr: filterJSON.value }) : await fetchSharedCalendarViewData({
sortsArr: sorts.value,
from_date: prevDate,
to_date: nextDate,
filtersArr: nestedFilters.value,
where: where?.value ?? '',
})
formattedData.value = formatData(res!.list) formattedData.value = formatData(res!.list)
} catch (e) { } catch (e) {
message.error(`${t('msg.error.fetchingCalendarData')} ${await extractSdkResponseErrorMsg(e)}`) message.error(`${t('msg.error.fetchingCalendarData')} ${await extractSdkResponseErrorMsg(e)}`)

53
packages/nc-gui/composables/useSharedView.ts

@ -110,8 +110,7 @@ export function useSharedView() {
} }
} }
const fetchSharedViewData = async ( const fetchSharedViewData = async (param: {
param: {
sortsArr: SortType[] sortsArr: SortType[]
filtersArr: FilterType[] filtersArr: FilterType[]
fields?: any[] fields?: any[]
@ -120,11 +119,47 @@ export function useSharedView() {
/** Query params for nested data */ /** Query params for nested data */
nested?: any nested?: any
offset?: number offset?: number
}) => {
if (!sharedView.value)
return {
list: [],
pageInfo: {},
}
if (!param.offset) {
const page = paginationData.value.page || 1
const pageSize = paginationData.value.pageSize || appInfoDefaultLimit
param.offset = (page - 1) * pageSize
}
return await $api.public.dataList(
sharedView.value.uuid!,
{
limit: sharedView.value?.type === ViewTypes.MAP ? 1000 : undefined,
...param,
filterArrJson: JSON.stringify(param.filtersArr ?? nestedFilters.value),
sortArrJson: JSON.stringify(param.sortsArr ?? sorts.value),
} as any,
{
headers: {
'xc-password': password.value,
}, },
headers?: {
ignorePagination?: boolean
}, },
) => { )
}
const fetchSharedCalendarViewData = async (param: {
from_date: string
to_date: string
sortsArr: SortType[]
filtersArr: FilterType[]
fields?: any[]
sort?: any[]
where?: string
/** Query params for nested data */
nested?: any
offset?: number
}) => {
if (!sharedView.value) if (!sharedView.value)
return { return {
list: [], list: [],
@ -137,7 +172,7 @@ export function useSharedView() {
param.offset = (page - 1) * pageSize param.offset = (page - 1) * pageSize
} }
return await $api.public.dataList( return await $api.dbCalendarViewRow.publicDataCalendarRowList(
sharedView.value.uuid!, sharedView.value.uuid!,
{ {
limit: sharedView.value?.type === ViewTypes.MAP ? 1000 : undefined, limit: sharedView.value?.type === ViewTypes.MAP ? 1000 : undefined,
@ -148,13 +183,14 @@ export function useSharedView() {
{ {
headers: { headers: {
'xc-password': password.value, 'xc-password': password.value,
'xc-ignore-pagination': headers?.ignorePagination ? 'true' : 'false',
}, },
}, },
) )
} }
const fetchSharedViewActiveDate = async (param: { const fetchSharedViewActiveDate = async (param: {
from_date: string
to_date: string
sortsArr: SortType[] sortsArr: SortType[]
filtersArr: FilterType[] filtersArr: FilterType[]
sort?: any[] sort?: any[]
@ -166,7 +202,7 @@ export function useSharedView() {
pageInfo: {}, pageInfo: {},
} }
return await $api.public.calendarCount( return await $api.public.dataCalendarRowCount(
sharedView.value.uuid!, sharedView.value.uuid!,
{ {
...param, ...param,
@ -234,6 +270,7 @@ export function useSharedView() {
nestedFilters, nestedFilters,
fetchSharedViewData, fetchSharedViewData,
fetchSharedViewActiveDate, fetchSharedViewActiveDate,
fetchSharedCalendarViewData,
fetchSharedViewGroupedData, fetchSharedViewGroupedData,
paginationData, paginationData,
sorts, sorts,

8
packages/nocodb/src/schema/swagger.json

@ -9955,10 +9955,10 @@
], ],
"get": { "get": {
"summary": "Count of Records in Dates in Calendar View", "summary": "Count of Records in Dates in Calendar View",
"operationId": "db-view-row-calendar-count", "operationId": "db-calendar-view-row-count",
"description": "Get the count of table view rows grouped by the dates", "description": "Get the count of table view rows grouped by the dates",
"tags": [ "tags": [
"DB View Row" "DB Calendar View Row Count"
], ],
"parameters": [ "parameters": [
{ {
@ -10049,7 +10049,7 @@
], ],
"get": { "get": {
"summary": "List rows in Calendar View of a Table", "summary": "List rows in Calendar View of a Table",
"operationId": "db-calendar-view-row-list", "operationId": "public-data-calendar-row-list",
"description": "List all rows in Calendar View of a Table", "description": "List all rows in Calendar View of a Table",
"tags": [ "tags": [
"DB Calendar View Row" "DB Calendar View Row"
@ -10231,7 +10231,7 @@
], ],
"get": { "get": {
"summary": "Count of Records in Dates in Calendar View", "summary": "Count of Records in Dates in Calendar View",
"operationId": "public-calendar-count", "operationId": "public-data-calendar-row-count",
"parameters": [ "parameters": [
{ {
"schema": { "schema": {

Loading…
Cancel
Save