From d07092df947df24237fd3f06933c75d3dc912d7c Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Wed, 28 Feb 2024 10:11:40 +0000 Subject: [PATCH] feat(nc-gui): granularity update --- .../smartsheet/calendar/DayView/DateTimeField.vue | 9 +++++++-- .../smartsheet/calendar/WeekView/DateTimeField.vue | 14 +++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue index b56d3db627..a6e0be0c10 100644 --- a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue @@ -205,7 +205,12 @@ const recordsAcrossAllRange = computed<{ const id = generateRandomNumber() const startDate = dayjs(record.row[fromCol.title!]) - const endDate = dayjs(record.row[fromCol.title!]).add(1, 'hour') + + let endDate = dayjs(record.row[fromCol.title!]).add(1, 'hour') + + if (endDate.isAfter(scheduleEnd, 'minutes')) { + endDate = scheduleEnd + } const startHour = startDate.hour() @@ -336,8 +341,8 @@ const calculateNewRow = (event: MouseEvent) => { // We calculate the hour based on the percentage of the mouse position in the scroll container // It can be between 0 and 23 (inclusive) const hour = Math.max(Math.floor(percentY * 23), 0) - const minutes = Math.max(0, Math.min(59, Math.floor(((percentY * 22 - hour) * 60) / 15 + 0.5) * 15)) + const minutes = Math.min(Math.max(Math.round(Math.floor((percentY * 23 - hour) * 60) / 15) * 15, 0), 60) // We calculate the new startDate by adding the hour to the start of the selected date const newStartDate = dayjs(selectedDate.value).startOf('day').add(hour, 'hour').add(minutes, 'minute') if (!newStartDate || !fromCol) return { newRow: null, updateProperty: [] } diff --git a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue index 19130bc362..8fa6fa072b 100644 --- a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue @@ -140,7 +140,11 @@ const recordsAcrossAllRange = computed<{ const ogStartDate = record.row[fromCol.title!] ? dayjs(record.row[fromCol.title!]) : null if (!ogStartDate) return - const endDate = ogStartDate.clone().add(1, 'hour') + let endDate = ogStartDate.clone().add(1, 'hour') + + if (endDate.isAfter(scheduleEnd, 'minutes')) { + endDate = scheduleEnd + } const id = record.rowMeta.id ?? generateRandomNumber() @@ -518,7 +522,7 @@ const calculateNewRow = ( const { scrollHeight } = container.value const percentX = (event.clientX - left - window.scrollX) / width - const percentY = (event.clientY - top + container.value.scrollTop) / scrollHeight + const percentY = (event.clientY - top + container.value.scrollTop - 36.8) / scrollHeight const fromCol = dragRecord.value.rowMeta.range?.fk_from_col const toCol = dragRecord.value.rowMeta.range?.fk_to_col @@ -528,7 +532,7 @@ const calculateNewRow = ( const day = Math.max(0, Math.min(6, Math.floor(percentX * 7))) const hour = Math.max(0, Math.min(23, Math.floor(percentY * 24))) - const minutes = Math.max(0, Math.min(59, Math.floor(((percentY * 22 - hour) * 60) / 15 + 0.5) * 15)) + const minutes = Math.round(((percentY * 24 * 60) % 60) / 15) * 15 const newStartDate = dayjs(selectedDateRange.value.start).add(day, 'day').add(hour, 'hour').add(minutes, 'minute') if (!newStartDate) return { newRow: null, updatedProperty: [] } @@ -755,14 +759,14 @@ const isOverflowAcrossHourRange = (hour: dayjs.Dayjs) => {
-
+