From 8dd8c2a2ef1e004107331db1c30050d8a523b5c1 Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Tue, 20 Feb 2024 07:16:22 +0000 Subject: [PATCH] fix(nc-gui): new week view design --- .../calendar/DayView/DateTimeField.vue | 4 +- .../calendar/WeekView/DateTimeField.vue | 238 ++++++++++-------- 2 files changed, 131 insertions(+), 111 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue index fde862c284..8be4cbd654 100644 --- a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue @@ -474,9 +474,7 @@ const onResizeStart = (direction: 'right' | 'left', _event: MouseEvent, record: } const onDrag = (event: MouseEvent) => { - if (!isUIAllowed('dataEdit')) return - if (!container.value || !dragRecord.value) return - + if (!isUIAllowed('dataEdit') || !container.value || !dragRecord.value) return const { top, bottom } = container.value.getBoundingClientRect() if (event.clientY > bottom - 20) { diff --git a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue index a2b89b5c7a..8719673e3b 100644 --- a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue @@ -22,6 +22,8 @@ const { const container = ref(null) +const scrollContainer = ref(null) + const { width: containerWidth } = useElementSize(container) const { isUIAllowed } = useRoles() @@ -68,7 +70,7 @@ const recordsAcrossAllRange = computed<{ }>(() => { if (!formattedData.value || !calendarRange.value || !container.value) return { records: [], count: {} } - const { scrollHeight } = container.value + const { scrollHeight } = scrollContainer.value const perWidth = containerWidth.value / 7 const perHeight = scrollHeight / 24 @@ -164,8 +166,8 @@ const recordsAcrossAllRange = computed<{ style = { ...style, - top: `${hourIndex * perHeight}px`, - height: `${perHeight / 1.5}px`, + top: `${hourIndex * perHeight - hourIndex + 3}px`, + height: `${perHeight - 4}px`, } recordsToDisplay.push({ @@ -367,7 +369,7 @@ const useDebouncedRowUpdate = useDebounceFn((row: Row, updateProperty: string[], }, 500) const onResize = (event: MouseEvent) => { - if (!isUIAllowed('dataEdit') || !container.value || !resizeRecord.value) return + if (!isUIAllowed('dataEdit') || !container.value || !resizeRecord.value || !scrollContainer.value) return const { width, left, top, bottom } = container.value.getBoundingClientRect() @@ -398,7 +400,7 @@ const onResize = (event: MouseEvent) => { const hour = Math.floor(percentY * 23) let updateProperty: string[] = [] - let newRow: Row + let newRow: Row = resizeRecord.value if (resizeDirection.value === 'right') { let newEndDate = dayjs(selectedDateRange.value.start).add(day, 'day').add(hour, 'hour') @@ -464,7 +466,14 @@ const onResizeStart = (direction: 'right' | 'left', event: MouseEvent, record: R // We calculate the new row based on the mouse position and update the record // We also update the sidebar data if the dropped from the sidebar -const calculateNewRow = (event: MouseEvent, updateSideBar?: boolean) => { +const calculateNewRow = ( + event: MouseEvent, + updateSideBar?: boolean, +): { + newRow: Row | null + updatedProperty: string[] +} => { + if (!isUIAllowed('dataEdit') || !container.value || !dragRecord.value) return { newRow: null, updatedProperty: [] } const { width, left, top } = container.value.getBoundingClientRect() const { scrollHeight } = container.value @@ -475,13 +484,15 @@ const calculateNewRow = (event: MouseEvent, updateSideBar?: boolean) => { const fromCol = dragRecord.value.rowMeta.range?.fk_from_col const toCol = dragRecord.value.rowMeta.range?.fk_to_col - if (!fromCol) return + if (!fromCol) return { newRow: null, updatedProperty: [] } - const day = Math.floor(percentX * 7) - const hour = Math.floor(percentY * 23) + const day = Math.max(0, Math.min(6, Math.floor(percentX * 7))) + const hour = Math.max(0, Math.min(23, Math.floor(percentY * 24))) + + console.log('day', day, 'hour', hour) const newStartDate = dayjs(selectedDateRange.value.start).add(day, 'day').add(hour, 'hour') - if (!newStartDate) return + if (!newStartDate) return { newRow: null, updatedProperty: [] } let endDate const updatedProperty = [fromCol.title!] @@ -533,15 +544,15 @@ const calculateNewRow = (event: MouseEvent, updateSideBar?: boolean) => { } const onDrag = (event: MouseEvent) => { - if (!isUIAllowed('dataEdit') || !container.value || !dragRecord.value) return - const { top, bottom } = container.value.getBoundingClientRect() + if (!isUIAllowed('dataEdit') || !scrollContainer.value || !dragRecord.value) return - // If the mouse is near the bottom of the container, we scroll down - // If the mouse is near the top of the container, we scroll up - if (event.clientY > bottom - 20) { - container.value.scrollTop += 10 - } else if (event.clientY < top + 20) { - container.value.scrollTop -= 10 + const containerRect = scrollContainer.value.getBoundingClientRect() + const scrollBottomThreshold = 20 + + if (event.clientY > containerRect.bottom - scrollBottomThreshold) { + scrollContainer.value.scrollTop += 10 + } else if (event.clientY < containerRect.top + scrollBottomThreshold) { + scrollContainer.value.scrollTop -= 10 } calculateNewRow(event) @@ -567,7 +578,9 @@ const stopDrag = (event: MouseEvent) => { dragElement.value = null } - updateRowProperty(newRow, updatedProperty, false) + if (newRow) { + updateRowProperty(newRow, updatedProperty, false) + } document.removeEventListener('mousemove', onDrag) document.removeEventListener('mouseup', stopDrag) @@ -631,7 +644,9 @@ const dropEvent = (event: DragEvent) => { const { newRow, updatedProperty } = calculateNewRow(event, true) - updateRowProperty(newRow, updatedProperty, false) + if (newRow) { + updateRowProperty(newRow, updatedProperty, false) + } } } @@ -644,103 +659,110 @@ const viewMore = (hour: dayjs.Dayjs) => {