From d9ffc5e65496d54254b58d57c99c87d6855c57ef Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Tue, 20 Feb 2024 07:16:10 +0000 Subject: [PATCH] fix(nc-gui): some fixes --- .../calendar/WeekView/DateTimeField.vue | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue index 872d97ce50..51e93422d7 100644 --- a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue @@ -130,6 +130,7 @@ const recordsAcrossAllRange = computed<{ sortedFormattedData.forEach((record: Row) => { if (!toCol && fromCol) { const startDate = record.row[fromCol.title!] ? dayjs(record.row[fromCol.title!]) : null + if (!startDate) return const dateKey = startDate?.format('YYYY-MM-DD') const hourKey = startDate?.format('HH:mm') @@ -152,7 +153,7 @@ const recordsAcrossAllRange = computed<{ const dayIndex = dayjs(dateKey).day() - 1 const hourIndex = datesHours.value[dayIndex].findIndex((h) => h.format('HH:mm') === hourKey) - const style = { + const style: Partial = { left: `${dayIndex * perWidth}px`, top: `${hourIndex * perHeight}px`, } @@ -187,6 +188,7 @@ const recordsAcrossAllRange = computed<{ let endDate = record.row[toCol.title!] ? dayjs(record.row[toCol.title!]) : null if (!startDate?.isValid() || !endDate?.isValid()) return + if (startDate.isBefore(scheduleStart, 'minutes')) { startDate = scheduleStart } @@ -198,15 +200,9 @@ const recordsAcrossAllRange = computed<{ while (currentStartDate.isSameOrBefore(endDate!, 'day')) { const currentEndDate = currentStartDate.clone().endOf('day') - const recordStart = currentEndDate.isSame(startDate, 'day') ? startDate : currentStartDate + const recordStart: dayjs.Dayjs = currentEndDate.isSame(startDate, 'day') ? startDate : currentStartDate const recordEnd = currentEndDate.isSame(endDate, 'day') ? endDate : currentEndDate - console.log( - record.row[displayField.value.title], - recordStart.format('YYYY-MM-DD HH:mm'), - recordEnd.format('YYYY-MM-DD HH:mm'), - ) - const dateKey = recordStart.format('YYYY-MM-DD') let hour = recordStart?.clone().startOf('hour') @@ -228,36 +224,53 @@ const recordsAcrossAllRange = computed<{ hour = hour.add(1, 'hour') } - const dayIndex = dayjs(dateKey).day() - console.log('dayIndex', record.row[displayField.value.title], dayIndex) + let dayIndex = recordStart.day() + + if (dayIndex === -1) { + dayIndex = 7 + } let maxRecordCount = 0 - for (let i = 0; i < (datesHours.value[dayIndex] ?? []).length; i++) { - const hourKey = datesHours.value[dayIndex][i].format('HH:mm') + for (let i = 0; i < (datesHours.value[dayIndex - 1] ?? []).length; i++) { + const hourKey = datesHours.value[dayIndex - 1][i].format('HH:mm') if (recordsInDayHour[dateKey]?.[hourKey]?.count > maxRecordCount) { maxRecordCount = recordsInDayHour[dateKey][hourKey].count } } const startHourIndex = Math.max( - (datesHours.value[dayIndex] ?? []).findIndex((h) => h.format('HH:mm') === recordStart.format('HH:mm')), + (datesHours.value[dayIndex - 1] ?? []).findIndex((h) => h.format('HH:mm') === recordStart.format('HH:mm')), 0, ) const endHourIndex = Math.max( - (datesHours.value[dayIndex] ?? []).findIndex((h) => h.format('HH:mm') === recordEnd?.startOf('hour').format('HH:mm')), + (datesHours.value[dayIndex - 1] ?? []).findIndex( + (h) => h.format('HH:mm') === recordEnd?.startOf('hour').format('HH:mm'), + ), 0, ) + console.log( + record.row[displayField.value.title], + recordEnd?.startOf('hour').format('HH:mm'), + (datesHours.value[dayIndex - 1] ?? []).findIndex( + (h) => h.format('HH:mm') === recordEnd?.startOf('hour').format('HH:mm'), + ), + ) + const spanHours = endHourIndex - startHourIndex + 1 - console.log(record.row[displayField.value.title], dayIndex) + const left = (dayIndex - 1) * perWidth + + const top = startHourIndex * perRecordHeight + + const height = (endHourIndex - startHourIndex + 1) * perHeight - spanHours - 5 const style: Partial = { - left: `${(dayIndex - 1) * perWidth}px`, - top: `${startHourIndex * perHeight}px`, - height: `${(endHourIndex - startHourIndex + 1) * perHeight - spanHours - 5}px`, + left: `${left}px`, + top: `${top}px`, + height: `${height}px`, } recordsToDisplay.push({ @@ -592,10 +605,7 @@ const dropEvent = (event: DragEvent) => { {{ hour.format('h A') }}
+