From 97da99155b239a36801d911e12e5b48c7bb5c942 Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Tue, 20 Feb 2024 07:16:09 +0000 Subject: [PATCH] fix(nc-gui): datetime overlap --- .../calendar/DayView/DateTimeField.vue | 196 +++++++++++++----- .../smartsheet/calendar/SideMenu.vue | 2 +- 2 files changed, 146 insertions(+), 52 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue index e1451462cd..33cc1432e7 100644 --- a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue @@ -53,11 +53,19 @@ const recordsAcrossAllRange = computed(() => { const endCol = range.fk_to_col if (fromCol && endCol) { for (const record of formattedData.value) { - const id = record.rowMeta.id ?? getRandomNumbers() - const startDate = dayjs(record.row[fromCol.title!]) - const endDate = dayjs(record.row[endCol.title!]) + const id = getRandomNumbers() + let startDate = dayjs(record.row[fromCol.title!]) + let endDate = dayjs(record.row[endCol.title!]) + + if (!startDate.isValid() || startDate.isAfter(endDate)) continue - if (!startDate.isValid()) continue + if (startDate.isBefore(scheduleStart)) { + startDate = scheduleStart + } + + if (endDate.isAfter(scheduleEnd)) { + endDate = scheduleEnd + } const topInPixels = (startDate.hour() + startDate.minute() / 60) * 80 const heightInPixels = Math.max((endDate.diff(startDate, 'minute') / 60) * 80, perRecordHeight) @@ -74,12 +82,14 @@ const recordsAcrossAllRange = computed(() => { overlaps[startMinutes] = [] } overlaps[startMinutes].push(id) - startMinutes += 15 + startMinutes += 10 } + const finalTopInPixels = topInPixels + startHour + 1 + const style: Partial = { - top: `${topInPixels + 10}px`, - height: `${heightInPixels}px`, + top: `${finalTopInPixels}px`, + height: `${heightInPixels - 5}px`, } let position = 'none' @@ -112,14 +122,29 @@ const recordsAcrossAllRange = computed(() => { } } else if (fromCol) { for (const record of formattedData.value) { + const id = getRandomNumbers() + const startDate = dayjs(record.row[fromCol.title!]) - const scaleMin = (scheduleEnd - scheduleStart) / 60000 + const endDate = dayjs(record.row[fromCol.title!]).add(1, 'hour') + + const startHour = startDate.hour() + const endHour = endDate.hour() - const startMinutes = Math.max((startDate - scheduleStart) / 60000, 0) - const endMinutes = Math.min((startDate - scheduleStart) / 60000, scaleMin) + let startMinutes = startDate.minute() + startHour * 60 + const endMinutes = endDate.minute() + endHour * 60 - const height = ((endMinutes - startMinutes) / scaleMin) * 100 - const top = (startMinutes / scaleMin) * 100 + while (startMinutes < endMinutes) { + if (!overlaps[startMinutes]) { + overlaps[startMinutes] = [] + } + overlaps[startMinutes].push(id) + startMinutes += 10 + } + + const topInPixels = (startDate.hour() + startDate.minute() / 60) * 80 + const heightInPixels = Math.max((endDate.diff(startDate, 'minute') / 60) * 80, perRecordHeight) + + const finalTopInPixels = topInPixels + startHour recordsByRange.push({ ...record, @@ -127,10 +152,10 @@ const recordsAcrossAllRange = computed(() => { ...record.rowMeta, range: range as any, style: { - width: '100%', - left: `${50}px`, - top: `${top}%`, + top: `${finalTopInPixels}px`, + height: `${heightInPixels - 5}px`, }, + id, position: 'rounded', }, }) @@ -144,23 +169,21 @@ const recordsAcrossAllRange = computed(() => { for (const minutes in overlaps) { if (overlaps[minutes].includes(record.rowMeta.id)) { maxOverlaps = Math.max(maxOverlaps, overlaps[minutes].length) - console.log( - record.row[displayField.value.title!], - maxOverlaps, - overlaps[minutes], - overlaps[minutes].indexOf(record.rowMeta.id), - ) + overlapIndex = Math.max(overlaps[minutes].indexOf(record.rowMeta.id), overlapIndex) } } - const width = 100 / maxOverlaps - const left = width * overlapIndex + const spacing = 1 + const widthPerRecord = (100 - spacing * (maxOverlaps - 1)) / maxOverlaps + const leftPerRecord = (widthPerRecord + spacing) * overlapIndex + + console.log('leftPerRecord', leftPerRecord, 'widthPerRecord', widthPerRecord) record.rowMeta.style = { ...record.rowMeta.style, - left: left === 0 ? '50px' : `calc(${left}% + 30px)`, - width: `${width}%`, + left: `${leftPerRecord}%`, + width: `calc(${widthPerRecord}%)`, } return record }) @@ -173,7 +196,7 @@ const recordsAcrossAllRange = computed(() => {
(() => { {{ dayjs(hour).format('H A') }}
+ + + + + + - +
- -
- - - +
+
+
+ + + +
+
diff --git a/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue b/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue index ee1fce7c89..422b3579ab 100644 --- a/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue +++ b/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue @@ -285,7 +285,7 @@ const sideBarListScrollHandle = useDebounceFn(async (e: Event) => { @scroll="sideBarListScrollHandle" >