From 268d723eb11182241aac08269761d10573346e4c Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 7 Mar 2025 12:29:03 +0100 Subject: [PATCH] refactor: refs #7869 merged changes with #8606 --- .../Zone/Card/ZoneEventExclusionForm.vue | 3 +- .../Zone/Card/ZoneEventInclusionForm.vue | 32 ++++++++++++-- src/pages/Zone/ZoneList.vue | 44 +++++++++---------- 3 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/pages/Zone/Card/ZoneEventExclusionForm.vue b/src/pages/Zone/Card/ZoneEventExclusionForm.vue index 8822b9657..3b33d5036 100644 --- a/src/pages/Zone/Card/ZoneEventExclusionForm.vue +++ b/src/pages/Zone/Card/ZoneEventExclusionForm.vue @@ -83,7 +83,8 @@ const exclusionCreate = async () => { const body = { dated: dated.value, }; - for (const id of props.zoneIds) { + const zoneIds = props.zoneIds?.length ? props.zoneIds : [route.params.id]; + for (const id of zoneIds) { const url = `Zones/${id}/exclusions`; let today = moment(dated.value); let lastDay = today.clone().add(4, 'months').endOf('month'); diff --git a/src/pages/Zone/Card/ZoneEventInclusionForm.vue b/src/pages/Zone/Card/ZoneEventInclusionForm.vue index dac71f513..bb329b0a3 100644 --- a/src/pages/Zone/Card/ZoneEventInclusionForm.vue +++ b/src/pages/Zone/Card/ZoneEventInclusionForm.vue @@ -3,6 +3,12 @@ import { ref, computed, onMounted } from 'vue'; import { useI18n } from 'vue-i18n'; import { useRoute } from 'vue-router'; import { useQuasar } from 'quasar'; +import axios from 'axios'; +import moment from 'moment'; + +import { useArrayData } from 'src/composables/useArrayData'; +import { useWeekdayStore } from 'src/stores/useWeekdayStore'; +import { useVnConfirm } from 'composables/useVnConfirm'; import VnRow from 'components/ui/VnRow.vue'; import FormPopup from 'components/FormPopup.vue'; @@ -10,10 +16,7 @@ import VnInputDate from 'src/components/common/VnInputDate.vue'; import VnWeekdayPicker from 'src/components/common/VnWeekdayPicker.vue'; import VnInputTime from 'components/common/VnInputTime.vue'; import VnInput from 'src/components/common/VnInput.vue'; -import { useArrayData } from 'src/composables/useArrayData'; -import { useWeekdayStore } from 'src/stores/useWeekdayStore'; -import { useVnConfirm } from 'composables/useVnConfirm'; -import axios from 'axios'; +import { toDateFormat } from 'src/filters/date'; const props = defineProps({ date: { @@ -79,6 +82,27 @@ const createEvent = async () => { const zoneIds = props.zoneIds?.length ? props.zoneIds : [route.params.id]; for (const id of zoneIds) { + let today = moment(eventInclusionFormData.value.dated); + let lastDay = today.clone().add(4, 'months').endOf('month'); + + const { data } = await axios.get(`Zones/getEventsFiltered`, { + params: { + zoneFk: id, + started: today, + ended: lastDay, + }, + }); + const existsExclusion = data.exclusions.find( + (exclusion) => + toDateFormat(exclusion.dated) === + toDateFormat(eventInclusionFormData.value.dated), + ); + if (existsExclusion) { + await axios.delete( + `Zones/${existsExclusion?.zoneFk}/exclusions/${existsExclusion?.id}`, + ); + } + if (isNew.value) await axios.post(`Zones/${id}/events`, eventInclusionFormData.value); else diff --git a/src/pages/Zone/ZoneList.vue b/src/pages/Zone/ZoneList.vue index 9eac801c0..8d7c4a165 100644 --- a/src/pages/Zone/ZoneList.vue +++ b/src/pages/Zone/ZoneList.vue @@ -213,28 +213,6 @@ const closeEventForm = () => {