Browse Source

fix(nc-gui): enable multiple range creation

pull/7611/head
DarkPhoenix2704 9 months ago
parent
commit
e0bced0dfc
  1. 25
      packages/nc-gui/components/dlg/ViewCreate.vue
  2. 6
      packages/nc-gui/components/smartsheet/calendar/index.vue
  3. 33
      packages/nc-gui/components/smartsheet/toolbar/CalendarRange.vue

25
packages/nc-gui/components/dlg/ViewCreate.vue

@ -225,6 +225,13 @@ async function onSubmit() {
} }
} }
const addCalendarRange = async () => {
form.calendarRange.push({
fk_from_column_id: viewSelectFieldOptions.value[0],
fk_to_column_id: null,
})
}
const isMetaLoading = ref(false) const isMetaLoading = ref(false)
onMounted(async () => { onMounted(async () => {
@ -424,7 +431,7 @@ onMounted(async () => {
/> />
</a-form-item> </a-form-item>
<template v-if="form.type === ViewTypes.CALENDAR"> <template v-if="form.type === ViewTypes.CALENDAR">
<div v-for="(range, index) in form.calendarRange" :key="`range-${index}`" class="flex w-full items-center gap-2"> <div v-for="(range, index) in form.calendarRange" :key="`range-${index}`" class="flex w-full mb-2 items-center gap-2">
<span> <span>
{{ $t('labels.organiseBy') }} {{ $t('labels.organiseBy') }}
</span> </span>
@ -474,7 +481,23 @@ onMounted(async () => {
</NcButton> </NcButton>
</div> </div>
</template> </template>
<NcButton
v-if="index !== 0"
size="small"
type="secondary"
@click="
() => {
form.calendarRange = form.calendarRange.filter((_, i) => i !== index)
}
"
>
<component :is="iconMap.close" />
</NcButton>
</div> </div>
<NcButton class="mt-2" size="small" type="secondary" @click="addCalendarRange">
<component :is="iconMap.plus" />
Add another date field
</NcButton>
</template> </template>
</a-form> </a-form>
<div v-else-if="!isNecessaryColumnsPresent" class="flex flex-row p-4 border-gray-200 border-1 gap-x-4 rounded-lg w-full"> <div v-else-if="!isNecessaryColumnsPresent" class="flex flex-row p-4 border-gray-200 border-1 gap-x-4 rounded-lg w-full">

6
packages/nc-gui/components/smartsheet/calendar/index.vue

@ -57,6 +57,8 @@ const {
const showSideMenu = ref(true) const showSideMenu = ref(true)
const calendarRangeDropdown = ref(false)
const router = useRouter() const router = useRouter()
const route = useRoute() const route = useRoute()
@ -152,7 +154,7 @@ const headerText = computed(() => {
</NcButton> </NcButton>
</NcTooltip> </NcTooltip>
<NcDropdown :auto-close="false"> <NcDropdown v-model:visible="calendarRangeDropdown" :auto-close="false" :trigger="['click']">
<NcButton size="small" type="secondary"> <NcButton size="small" type="secondary">
<div class="flex gap-2 items-center"> <div class="flex gap-2 items-center">
<span class="font-bold text-center text-brand-500">{{ headerText }}</span> <span class="font-bold text-center text-brand-500">{{ headerText }}</span>
@ -161,7 +163,7 @@ const headerText = computed(() => {
</NcButton> </NcButton>
<template #overlay> <template #overlay>
<div class="min-w-[22.1rem]"> <div v-if="calendarRangeDropdown" class="min-w-[22.1rem]" @click.stop>
<NcDateWeekSelector <NcDateWeekSelector
v-if="activeCalendarView === ('day' as const)" v-if="activeCalendarView === ('day' as const)"
v-model:active-dates="activeDates" v-model:active-dates="activeDates"

33
packages/nc-gui/components/smartsheet/toolbar/CalendarRange.vue

@ -79,14 +79,6 @@ const saveCalendarRanges = async () => {
} }
} }
// To add new calendar range
const addCalendarRange = async () => {
_calendar_ranges.value.push({
fk_from_column_id: '',
fk_to_column_id: undefined,
})
}
const dateFieldOptions = computed<SelectProps['options']>(() => { const dateFieldOptions = computed<SelectProps['options']>(() => {
return ( return (
meta.value?.columns meta.value?.columns
@ -98,6 +90,20 @@ const dateFieldOptions = computed<SelectProps['options']>(() => {
})) ?? [] })) ?? []
) )
}) })
// To add new calendar range
const addCalendarRange = async () => {
_calendar_ranges.value.push({
fk_from_column_id: dateFieldOptions.value[0],
fk_to_column_id: null,
})
}
const removeRange = async (id: number) => {
_calendar_ranges.value = _calendar_ranges.value.filter((_, i) => i !== id)
await saveCalendarRanges()
}
</script> </script>
<template> <template>
@ -113,8 +119,8 @@ const dateFieldOptions = computed<SelectProps['options']>(() => {
</a-button> </a-button>
</div> </div>
<template #overlay> <template #overlay>
<div v-if="calendarRangeDropdown" class="flex flex-col w-full p-6 w-[35rem]" @click.stop> <div v-if="calendarRangeDropdown" class="w-full p-6 w-[35rem]" @click.stop>
<div v-for="(range, id) in _calendar_ranges" :key="id" class="flex w-full gap-2 items-center"> <div v-for="(range, id) in _calendar_ranges" :key="id" class="flex w-full gap-2 mb-2 items-center">
<span> <span>
{{ $t('labels.organiseBy') }} {{ $t('labels.organiseBy') }}
</span> </span>
@ -184,7 +190,14 @@ const dateFieldOptions = computed<SelectProps['options']>(() => {
</NcButton> </NcButton>
</div> </div>
</template> </template>
<NcButton v-if="id !== 0" size="small" type="secondary" @click="removeRange(id)">
<component :is="iconMap.close" />
</NcButton>
</div> </div>
<NcButton class="mt-2" size="small" type="secondary" @click="addCalendarRange">
<component :is="iconMap.plus" />
Add another date field
</NcButton>
</div> </div>
</template> </template>
</NcDropdown> </NcDropdown>

Loading…
Cancel
Save