|
|
@ -72,6 +72,8 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
|
|
|
|
|
|
|
|
const isSidebarLoading = ref<boolean>(false) |
|
|
|
const isSidebarLoading = ref<boolean>(false) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const activeDates = ref<dayjs.Dayjs[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
const sideBarFilterOption = ref<string>(activeCalendarView.value ?? 'allRecords') |
|
|
|
const sideBarFilterOption = ref<string>(activeCalendarView.value ?? 'allRecords') |
|
|
|
|
|
|
|
|
|
|
|
const { api } = useApi() |
|
|
|
const { api } = useApi() |
|
|
@ -431,39 +433,79 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
return combinedFilters.children.length > 0 ? [combinedFilters] : [] |
|
|
|
return combinedFilters.children.length > 0 ? [combinedFilters] : [] |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// Set of Dates that have data
|
|
|
|
const fetchActiveDates = async () => { |
|
|
|
const activeDates = computed(() => { |
|
|
|
if (!base?.value?.id || !meta.value?.id || !viewMeta.value?.id || !calendarRange.value) return |
|
|
|
if (!formattedData.value || !calendarRange.value) return [] |
|
|
|
let prevDate: dayjs.Dayjs | string | null = null |
|
|
|
const dates = new Set<dayjs.Dayjs>() |
|
|
|
let nextDate: dayjs.Dayjs | string | null = null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (activeCalendarView.value === 'week' || activeCalendarView.value === 'day' || activeCalendarView.value === 'month') { |
|
|
|
|
|
|
|
prevDate = pageDate.value.subtract(1, 'day').endOf('day') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nextDate = pageDate.value.add(1, 'day').startOf('day') |
|
|
|
|
|
|
|
} else if (activeCalendarView.value === 'year') { |
|
|
|
|
|
|
|
prevDate = selectedDate.value.startOf('year').subtract(1, 'day').endOf('day') |
|
|
|
|
|
|
|
nextDate = selectedDate.value.endOf('year').add(1, 'day').startOf('day') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const activeDateFilter: Array<any> = [] |
|
|
|
|
|
|
|
|
|
|
|
calendarRange.value.forEach((range) => { |
|
|
|
calendarRange.value.forEach((range) => { |
|
|
|
formattedData.value.forEach((row) => { |
|
|
|
const fromCol = range.fk_from_col |
|
|
|
const start = row.row[range.fk_from_col?.title ?? ''] |
|
|
|
const toCol = range.fk_to_col |
|
|
|
let end |
|
|
|
let rangeFilter: any = [] |
|
|
|
if (range.fk_to_col) { |
|
|
|
|
|
|
|
end = row.row[range.fk_to_col.title ?? ''] |
|
|
|
if (fromCol && toCol) { |
|
|
|
} |
|
|
|
rangeFilter = [ |
|
|
|
if (start && end) { |
|
|
|
{ |
|
|
|
const startDate = dayjs(start) |
|
|
|
is_group: true, |
|
|
|
let endDate = dayjs(end) |
|
|
|
logical_op: 'and', |
|
|
|
let currentDate = startDate |
|
|
|
children: [ |
|
|
|
// We have to check whether the start is after the end date, if so, loop through the end date
|
|
|
|
{ |
|
|
|
if (startDate.isAfter(endDate)) { |
|
|
|
fk_column_id: fromCol.id, |
|
|
|
endDate = startDate |
|
|
|
comparison_op: 'lt', |
|
|
|
currentDate = endDate |
|
|
|
comparison_sub_op: 'exactDate', |
|
|
|
} |
|
|
|
value: nextDate, |
|
|
|
while (currentDate.isSameOrBefore(endDate)) { |
|
|
|
}, |
|
|
|
dates.add(currentDate) |
|
|
|
{ |
|
|
|
currentDate = currentDate.add(1, 'day') |
|
|
|
fk_column_id: toCol.id, |
|
|
|
} |
|
|
|
comparison_op: 'gt', |
|
|
|
} else if (start) { |
|
|
|
comparison_sub_op: 'exactDate', |
|
|
|
dates.add(dayjs(start)) |
|
|
|
value: prevDate, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
} 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) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return Array.from(dates) |
|
|
|
if (!base?.value?.id || !meta.value?.id || !viewMeta.value?.id) return |
|
|
|
|
|
|
|
const res = await api.dbViewRow.calendarCount('noco', base.value.id!, meta.value!.id!, viewMeta.value.id, { |
|
|
|
|
|
|
|
...queryParams.value, |
|
|
|
|
|
|
|
...{}, |
|
|
|
|
|
|
|
...{}, |
|
|
|
|
|
|
|
...{ filterArrJson: JSON.stringify([...filterJSON.value, ...activeDateFilter]) }, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
if (res) { |
|
|
|
|
|
|
|
activeDates.value = res.map((dateObj: unknown) => dayjs(dateObj.date)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const changeCalendarView = async (view: 'month' | 'year' | 'day' | 'week') => { |
|
|
|
const changeCalendarView = async (view: 'month' | 'year' | 'day' | 'week') => { |
|
|
|
try { |
|
|
|
try { |
|
|
@ -669,7 +711,7 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
watch(selectedDate, async () => { |
|
|
|
watch(selectedDate, async (value, oldValue) => { |
|
|
|
if (activeCalendarView.value === 'month' || activeCalendarView.value === 'week') { |
|
|
|
if (activeCalendarView.value === 'month' || activeCalendarView.value === 'week') { |
|
|
|
if (sideBarFilterOption.value === 'selectedDate') { |
|
|
|
if (sideBarFilterOption.value === 'selectedDate') { |
|
|
|
await loadSidebarData() |
|
|
|
await loadSidebarData() |
|
|
@ -677,6 +719,10 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
await Promise.all([loadCalendarData(), loadSidebarData()]) |
|
|
|
await Promise.all([loadCalendarData(), loadSidebarData()]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (activeCalendarView.value === 'year' && value.year() !== oldValue.year()) { |
|
|
|
|
|
|
|
await fetchActiveDates() |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
watch(selectedTime, async () => { |
|
|
|
watch(selectedTime, async () => { |
|
|
@ -726,7 +772,7 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
sideBarFilterOption.value = activeCalendarView.value ?? 'allRecords' |
|
|
|
sideBarFilterOption.value = activeCalendarView.value ?? 'allRecords' |
|
|
|
await Promise.all([loadCalendarData(), loadSidebarData()]) |
|
|
|
await Promise.all([loadCalendarData(), loadSidebarData(), fetchActiveDates()]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
watch(sideBarFilterOption, async () => { |
|
|
|
watch(sideBarFilterOption, async () => { |
|
|
@ -737,6 +783,11 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
await loadSidebarData() |
|
|
|
await loadSidebarData() |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
watch(pageDate, async () => { |
|
|
|
|
|
|
|
if (activeCalendarView.value === 'year') return |
|
|
|
|
|
|
|
await fetchActiveDates() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
formattedSideBarData, |
|
|
|
formattedSideBarData, |
|
|
|
loadMoreSidebarData, |
|
|
|
loadMoreSidebarData, |
|
|
|