|
|
@ -91,7 +91,7 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const sideBarxWhere = computed(() => { |
|
|
|
const sideBarxWhere = computed(() => { |
|
|
|
if (!calendarRange.value) return '' |
|
|
|
if (!calendarRange.value || !calendarRange.value[0].fk_from_col) return '' |
|
|
|
let whereClause = '' |
|
|
|
let whereClause = '' |
|
|
|
if (activeCalendarView.value === 'day') { |
|
|
|
if (activeCalendarView.value === 'day') { |
|
|
|
switch (sideBarFilterOption.value) { |
|
|
|
switch (sideBarFilterOption.value) { |
|
|
@ -202,7 +202,7 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const xWhere = computed(() => { |
|
|
|
const xWhere = computed(() => { |
|
|
|
if (!meta.value || !meta.value.columns || !calendarMetaData.value || !calendarMetaData.value.calendar_range) return '' |
|
|
|
if (!meta.value || !meta.value.columns || !calendarRange.value || !calendarRange.value[0].fk_from_col) return '' |
|
|
|
// If CalendarView, then we need to add the date filter to the where clause
|
|
|
|
// If CalendarView, then we need to add the date filter to the where clause
|
|
|
|
let whereClause = where?.value ?? '' |
|
|
|
let whereClause = where?.value ?? '' |
|
|
|
if (whereClause.length > 0) { |
|
|
|
if (whereClause.length > 0) { |
|
|
@ -236,11 +236,12 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
// Set of Dates that have data
|
|
|
|
// Set of Dates that have data
|
|
|
|
const activeDates = computed(() => { |
|
|
|
const activeDates = computed(() => { |
|
|
|
const dates = new Set<Date>() |
|
|
|
const dates = new Set<Date>() |
|
|
|
|
|
|
|
if (!formattedData.value || !calendarRange.value || !calendarRange.value[0].fk_from_col) return [] |
|
|
|
formattedData.value.forEach((row) => { |
|
|
|
formattedData.value.forEach((row) => { |
|
|
|
const start = row.row[calendarRange.value[0].fk_from_col.title] |
|
|
|
const start = row.row[calendarRange.value[0].fk_from_col?.title ?? ''] |
|
|
|
let end |
|
|
|
let end |
|
|
|
if (calendarRange.value[0].fk_to_col) { |
|
|
|
if (calendarRange.value[0].fk_to_col) { |
|
|
|
end = row.row[calendarRange.value[0].fk_to_col.title] |
|
|
|
end = row.row[calendarRange.value[0].fk_to_col.title ?? ''] |
|
|
|
} |
|
|
|
} |
|
|
|
if (start && end) { |
|
|
|
if (start && end) { |
|
|
|
const startDate = dayjs(start) |
|
|
|
const startDate = dayjs(start) |
|
|
@ -262,7 +263,9 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
activeCalendarView.value = view |
|
|
|
activeCalendarView.value = view |
|
|
|
await updateCalendarMeta({ |
|
|
|
await updateCalendarMeta({ |
|
|
|
meta: { |
|
|
|
meta: { |
|
|
|
...JSON.parse(calendarMetaData.value?.meta ?? '{}'), |
|
|
|
...(typeof calendarMetaData.value.meta === 'string' |
|
|
|
|
|
|
|
? JSON.parse(calendarMetaData.value.meta) |
|
|
|
|
|
|
|
: calendarMetaData.value.meta), |
|
|
|
active_view: view, |
|
|
|
active_view: view, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}) |
|
|
|
}) |
|
|
@ -275,10 +278,10 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
async function loadCalendarMeta() { |
|
|
|
async function loadCalendarMeta() { |
|
|
|
if (!viewMeta?.value?.id || !meta?.value?.columns) return |
|
|
|
if (!viewMeta?.value?.id || !meta?.value?.columns) return |
|
|
|
// TODO: Fetch Calendar Meta
|
|
|
|
// TODO: Fetch Calendar Meta
|
|
|
|
calendarMetaData.value = isPublic.value |
|
|
|
const res = isPublic.value ? (sharedView.value?.view as CalendarType) : await $api.dbView.calendarRead(viewMeta.value.id) |
|
|
|
? (sharedView.value?.view as CalendarType) |
|
|
|
calendarMetaData.value = res |
|
|
|
: await $api.dbView.calendarRead(viewMeta.value.id) |
|
|
|
activeCalendarView.value = |
|
|
|
activeCalendarView.value = JSON.parse(calendarMetaData.value?.meta ?? '{}')?.active_view ?? 'month' |
|
|
|
typeof res.meta === 'string' ? JSON.parse(res.meta)?.active_view : res.meta?.active_view ?? 'month' |
|
|
|
calDataType.value = calendarRange.value[0].fk_from_col.uidt |
|
|
|
calDataType.value = calendarRange.value[0].fk_from_col.uidt |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -297,23 +300,31 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const filteredData = computed(() => { |
|
|
|
const filteredData = computed(() => { |
|
|
|
if (!formattedData.value) return [] |
|
|
|
if (!formattedData.value || !calendarRange.value) return [] |
|
|
|
|
|
|
|
const startField = calendarRange.value[0].fk_from_col?.title ?? '' |
|
|
|
|
|
|
|
const endField = calendarRange.value[0].fk_to_col?.title |
|
|
|
if (activeCalendarView.value === 'week') { |
|
|
|
if (activeCalendarView.value === 'week') { |
|
|
|
return formattedData.value.filter((row) => { |
|
|
|
return formattedData.value.filter((row) => { |
|
|
|
const startDate = dayjs(row.row[calendarRange.value[0].fk_from_col.title]) |
|
|
|
const startDate = dayjs(row.row[startField]) |
|
|
|
const endDate = dayjs(row.row[calendarRange.value[0].fk_to_col.title]) |
|
|
|
let endDate |
|
|
|
return startDate.isSameOrBefore(selectedDateRange.value.end) && endDate.isSameOrAfter(selectedDateRange.value.start) |
|
|
|
if (endField) { |
|
|
|
|
|
|
|
endDate = dayjs(row.row[endField]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return startDate.isSameOrBefore(selectedDateRange.value.end) && endDate?.isSameOrAfter(selectedDateRange.value.start) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else if (activeCalendarView.value === 'day') { |
|
|
|
} else if (activeCalendarView.value === 'day') { |
|
|
|
return formattedData.value.filter((row) => { |
|
|
|
return formattedData.value.filter((row) => { |
|
|
|
const startDate = dayjs(row.row[calendarRange.value[0].fk_from_col.title]) |
|
|
|
const startDate = dayjs(row.row[startField]) |
|
|
|
return startDate.isSame(selectedDate.value) |
|
|
|
return startDate.isSame(selectedDate.value) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else if (activeCalendarView.value === 'month') { |
|
|
|
} else if (activeCalendarView.value === 'month') { |
|
|
|
return formattedData.value.filter((row) => { |
|
|
|
return formattedData.value.filter((row) => { |
|
|
|
const startDate = dayjs(row.row[calendarRange.value[0].fk_from_col.title]) |
|
|
|
const startDate = dayjs(row.row[startField]) |
|
|
|
const endDate = dayjs(row.row[calendarRange.value[0].fk_to_col.title]) |
|
|
|
let endDate |
|
|
|
return startDate.isSameOrBefore(selectedDate.value) && endDate.isSameOrAfter(selectedDate.value) |
|
|
|
if (endField) { |
|
|
|
|
|
|
|
endDate = dayjs(row.row[endField]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return startDate.isSameOrBefore(selectedDate.value) && endDate?.isSameOrAfter(selectedDate.value) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|