From 92627f9163554f0ecca6b283dcd5c87964a3205b Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Tue, 20 Feb 2024 07:15:42 +0000 Subject: [PATCH] feat(nc-gui): week picker --- packages/nc-gui/components/nc/DatePicker.vue | 50 ++++++++++++++++---- packages/nc-gui/lang/en.json | 2 +- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/packages/nc-gui/components/nc/DatePicker.vue b/packages/nc-gui/components/nc/DatePicker.vue index 946962e9f5..31c5b1ff85 100644 --- a/packages/nc-gui/components/nc/DatePicker.vue +++ b/packages/nc-gui/components/nc/DatePicker.vue @@ -6,20 +6,29 @@ interface Props { pageDate?: Date; activeDates?: Date[]; isMondayFirst?: boolean; + weekPicker?: boolean; + startDate?: Date | null; + endDate?: Date | null; } -const emit = defineEmits(['change', 'update:selectedDate', 'update:pageDate']); +const emit = defineEmits(['change', 'update:selected-date', 'update:page-date', 'update:start-date', 'update:end-date']); const props = withDefaults(defineProps(), { selectedDate: null, isDisabled: false, isMondayFirst: false, pageDate: new Date(), + weekPicker: false, activeDates: [], + startDate: null, + endDate: null, }); const pageDate = useVModel(props, 'pageDate', emit); const selectedDate = useVModel(props, 'selectedDate', emit); const activeDates = useVModel(props, 'activeDates', emit); +const startDate = useVModel(props, 'startDate', emit); +const endDate = useVModel(props, 'endDate', emit); + const days = computed(() => { if (props.isMondayFirst) { @@ -82,6 +91,7 @@ const blankDaysAtEnd = computed((): any => { }); function isSelectedDate(dObj: Date): boolean { + if(!selectedDate.value) return false; const propDate = new Date(selectedDate.value); return props.selectedDate ? compareDates(propDate, dObj) : false; } @@ -109,6 +119,7 @@ interface DateObj { isSelected: boolean; timestamp: number; hasEvent: boolean; + inSelectedWeek: boolean; } const monthDays = computed((): DateObj[] => { @@ -123,6 +134,7 @@ const monthDays = computed((): DateObj[] => { date: dObj.getDate(), isSelected: isSelectedDate(dObj), hasEvent: isActiveDate(dObj), + inSelectedWeek: false, }); setDate(dObj, (dObj.getDate() + 1)); } @@ -137,14 +149,32 @@ const paginateMonth = (direction: 'next' | 'prev') => { newDate.setMonth(newDate.getMonth() - 1); } pageDate.value = newDate; - emit('update:pageDate', newDate); + emit('update:page-date', newDate); }; const selectDate = (day: number) => { - const date = new Date(pageDate.value); - date.setDate(day); - selectedDate.value = date; - emit('update:selectedDate', date); + if(props.weekPicker) { + const date = new Date(pageDate.value.getFullYear(), pageDate.value.getMonth(), day) + if(!startDate.value) { + console.log('setting start date') + startDate.value = date; + console.log(startDate.value) + emit('update:start-date', date); + } else if(!endDate.value) { + endDate.value = date; + emit('update:end-date', date); + } else { + startDate.value = date; + endDate.value = null; + emit('update:start-date', date); + emit('update:end-date', null); + } + } else { + const date = new Date(pageDate.value); + date.setDate(day); + selectedDate.value = date; + emit('update:selected-date', date); + } }; @@ -166,9 +196,11 @@ const selectDate = (day: number) => {
{{day.day}} diff --git a/packages/nc-gui/lang/en.json b/packages/nc-gui/lang/en.json index 1e94b0f021..efc94a117a 100644 --- a/packages/nc-gui/lang/en.json +++ b/packages/nc-gui/lang/en.json @@ -208,7 +208,7 @@ "page": "Page", "pages": "Pages", "record": "record", - "records": "records", + "records": "Records", "webhook": "Webhook", "webhooks": "Webhooks", "view": "View",