|
|
@ -5,8 +5,16 @@ import type { Row } from '#imports' |
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['new-record', 'expand-record']) |
|
|
|
const emit = defineEmits(['new-record', 'expand-record']) |
|
|
|
|
|
|
|
|
|
|
|
const { selectedDate, selectedMonth, formattedData, displayField, calendarRange, calDataType, updateRowProperty } = |
|
|
|
const { |
|
|
|
useCalendarViewStoreOrThrow() |
|
|
|
selectedDate, |
|
|
|
|
|
|
|
selectedMonth, |
|
|
|
|
|
|
|
formattedData, |
|
|
|
|
|
|
|
formattedSideBarData, |
|
|
|
|
|
|
|
displayField, |
|
|
|
|
|
|
|
calendarRange, |
|
|
|
|
|
|
|
calDataType, |
|
|
|
|
|
|
|
updateRowProperty, |
|
|
|
|
|
|
|
} = useCalendarViewStoreOrThrow() |
|
|
|
|
|
|
|
|
|
|
|
const isMondayFirst = ref(true) |
|
|
|
const isMondayFirst = ref(true) |
|
|
|
|
|
|
|
|
|
|
@ -299,6 +307,21 @@ const dragStart = (event: DragEvent, record: Row) => { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dragEnter = (event: DragEvent) => { |
|
|
|
|
|
|
|
event.preventDefault() |
|
|
|
|
|
|
|
const { top, height, width, left } = calendarGridContainer.value.getBoundingClientRect() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const percentY = (event.clientY - top - window.scrollY) / height |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const percentX = (event.clientX - left - window.scrollX) / width |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const week = Math.floor(percentY * dates.value.length) |
|
|
|
|
|
|
|
const day = Math.floor(percentX * 7) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const currSelectedDate = dayjs(selectedDate.value).startOf('month').add(week, 'week').add(day, 'day') |
|
|
|
|
|
|
|
selectedDate.value = currSelectedDate.toDate() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const dropEvent = (event: DragEvent) => { |
|
|
|
const dropEvent = (event: DragEvent) => { |
|
|
|
event.preventDefault() |
|
|
|
event.preventDefault() |
|
|
|
const data = event.dataTransfer?.getData('text/plain') |
|
|
|
const data = event.dataTransfer?.getData('text/plain') |
|
|
@ -315,9 +338,11 @@ const dropEvent = (event: DragEvent) => { |
|
|
|
const { top, height, width, left } = calendarGridContainer.value.getBoundingClientRect() |
|
|
|
const { top, height, width, left } = calendarGridContainer.value.getBoundingClientRect() |
|
|
|
|
|
|
|
|
|
|
|
const percentY = (event.clientY - top - initialClickOffsetY - window.scrollY) / height |
|
|
|
const percentY = (event.clientY - top - initialClickOffsetY - window.scrollY) / height |
|
|
|
|
|
|
|
|
|
|
|
const percentX = (event.clientX - left - initialClickOffsetX - window.scrollX) / width |
|
|
|
const percentX = (event.clientX - left - initialClickOffsetX - window.scrollX) / width |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fromCol = record.rowMeta.range?.fk_from_col |
|
|
|
|
|
|
|
const toCol = record.rowMeta.range?.fk_to_col |
|
|
|
|
|
|
|
|
|
|
|
const week = Math.floor(percentY * dates.value.length) |
|
|
|
const week = Math.floor(percentY * dates.value.length) |
|
|
|
const day = Math.floor(percentX * 7) |
|
|
|
const day = Math.floor(percentX * 7) |
|
|
|
|
|
|
|
|
|
|
@ -329,39 +354,59 @@ const dropEvent = (event: DragEvent) => { |
|
|
|
...record, |
|
|
|
...record, |
|
|
|
row: { |
|
|
|
row: { |
|
|
|
...record.row, |
|
|
|
...record.row, |
|
|
|
[record.rowMeta.range.fk_from_col.title]: dayjs(newStartDate).format('YYYY-MM-DD'), |
|
|
|
[fromCol.title]: dayjs(newStartDate).format('YYYY-MM-DD'), |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const updateProperty = [record.rowMeta.range.fk_from_col.title] |
|
|
|
const updateProperty = [fromCol.title] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (toCol) { |
|
|
|
|
|
|
|
const fromDate = record.row[fromCol.title] ? dayjs(record.row[fromCol.title]) : null |
|
|
|
|
|
|
|
const toDate = record.row[toCol.title] ? dayjs(record.row[toCol.title]) : null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fromDate && toDate) { |
|
|
|
|
|
|
|
endDate = dayjs(newStartDate).add(toDate.diff(fromDate, 'day'), 'day') |
|
|
|
|
|
|
|
} else if (fromDate && !toDate) { |
|
|
|
|
|
|
|
endDate = dayjs(newStartDate).endOf('day') |
|
|
|
|
|
|
|
} else if (!fromDate && toDate) { |
|
|
|
|
|
|
|
endDate = dayjs(newStartDate).endOf('day') |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
endDate = newStartDate.clone() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (record.rowMeta.range.fk_to_col) { |
|
|
|
newRow.row[toCol.title] = dayjs(endDate).format('YYYY-MM-DD') |
|
|
|
const diffDays = dayjs(record.row[record.rowMeta.range.fk_to_col.title]).diff( |
|
|
|
|
|
|
|
record.row[record.rowMeta.range.fk_from_col.title], |
|
|
|
updateProperty.push(toCol.title) |
|
|
|
'day', |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
endDate = dayjs(newStartDate).add(diffDays, 'day') |
|
|
|
|
|
|
|
newRow.row[record.rowMeta.range.fk_to_col.title] = dayjs(endDate).format('YYYY-MM-DD') |
|
|
|
|
|
|
|
updateProperty.push(record.rowMeta.range.fk_to_col.title) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!newRow) return |
|
|
|
if (!newRow) return |
|
|
|
|
|
|
|
|
|
|
|
dragElement.value.style.boxShadow = 'none' |
|
|
|
if (dragElement.value) { |
|
|
|
dragElement.value.classList.remove('hide') |
|
|
|
formattedData.value = formattedData.value.map((r) => { |
|
|
|
|
|
|
|
const pk = extractPkFromRow(r.row, meta.value.columns) |
|
|
|
|
|
|
|
|
|
|
|
dragElement.value = null |
|
|
|
if (pk === extractPkFromRow(newRow.row, meta.value.columns)) { |
|
|
|
|
|
|
|
return newRow |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return r |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
formattedData.value = [...formattedData.value, newRow] |
|
|
|
|
|
|
|
formattedSideBarData.value = formattedSideBarData.value.filter((r) => { |
|
|
|
|
|
|
|
const pk = extractPkFromRow(r.row, meta.value.columns) |
|
|
|
|
|
|
|
|
|
|
|
updateRowProperty(newRow, updateProperty, false) |
|
|
|
return pk !== extractPkFromRow(newRow.row, meta.value.columns) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
formattedData.value = formattedData.value.map((r) => { |
|
|
|
if (dragElement.value) { |
|
|
|
const pk = extractPkFromRow(r.row, meta.value.columns) |
|
|
|
dragElement.value.style.boxShadow = 'none' |
|
|
|
|
|
|
|
dragElement.value.classList.remove('hide') |
|
|
|
|
|
|
|
|
|
|
|
if (pk === extractPkFromRow(newRow.row, meta.value.columns)) { |
|
|
|
dragElement.value = null |
|
|
|
return newRow |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return r |
|
|
|
updateRowProperty(newRow, updateProperty, false) |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -395,6 +440,7 @@ const isDateSelected = (date: Date) => { |
|
|
|
}" |
|
|
|
}" |
|
|
|
class="grid h-full pb-7.5" |
|
|
|
class="grid h-full pb-7.5" |
|
|
|
@drop="dropEvent" |
|
|
|
@drop="dropEvent" |
|
|
|
|
|
|
|
@dragenter.prevent="dragEnter" |
|
|
|
> |
|
|
|
> |
|
|
|
<div v-for="(week, weekIndex) in dates" :key="weekIndex" class="grid grid-cols-7 grow"> |
|
|
|
<div v-for="(week, weekIndex) in dates" :key="weekIndex" class="grid grid-cols-7 grow"> |
|
|
|
<div |
|
|
|
<div |
|
|
|