From a1aa9337c8fd79f2da24899c100468030712c2ec Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 25 Nov 2024 09:21:20 +0100 Subject: [PATCH 1/4] fix: show data and fixed search button when excluding a location --- src/components/FormPopup.vue | 23 ++++---- .../Zone/Card/ZoneEventExclusionForm.vue | 52 +++++++------------ src/pages/Zone/Card/ZoneLocationsTree.vue | 43 +++++---------- 3 files changed, 48 insertions(+), 70 deletions(-) diff --git a/src/components/FormPopup.vue b/src/components/FormPopup.vue index d7f744984..893ee8393 100644 --- a/src/components/FormPopup.vue +++ b/src/components/FormPopup.vue @@ -4,7 +4,7 @@ import { useI18n } from 'vue-i18n'; const emit = defineEmits(['onSubmit']); -defineProps({ +const $props = defineProps({ title: { type: String, default: '', @@ -25,16 +25,21 @@ defineProps({ type: String, default: '', }, + submitOnEnter: { + type: Boolean, + default: true, + }, }); const { t } = useI18n(); - const closeButton = ref(null); const isLoading = ref(false); const onSubmit = () => { - emit('onSubmit'); - closeForm(); + if ($props.submitOnEnter) { + emit('onSubmit'); + closeForm(); + } }; const closeForm = () => { @@ -52,12 +57,12 @@ const closeForm = () => { -

{{ title }}

-

{{ subtitle }}

+

{{ $props.title }}

+

{{ $props.subtitle }}

{ v-close-popup /> { - try { - const params = { - zoneFk: parseInt(route.params.id), - date: dated.value, - geoIds: tickedNodes.value, - }; - await axios.post('Zones/exclusionGeo', params); - await refetchEvents(); - } catch (err) { - console.error('Error creating exclusion geo: ', err); - } + const params = { + zoneFk: parseInt(route.params.id), + date: dated.value, + geoIds: tickedNodes.value, + }; + await axios.post('Zones/exclusionGeo', params); + await refetchEvents(); }; const exclusionCreate = async () => { - try { - if (isNew.value) - await axios.post(`Zones/${route.params.id}/exclusions`, [ - { dated: dated.value }, - ]); - else - await axios.post(`Zones/${route.params.id}/exclusions`, { - dated: dated.value, - }); - - await refetchEvents(); - } catch (err) { - console.error('Error creating exclusion: ', err); - } + if (isNew.value) + await axios.post(`Zones/${route.params.id}/exclusions`, [{ dated: dated.value }]); + else + await axios.post(`Zones/${route.params.id}/exclusions`, { + dated: dated.value, + }); + await refetchEvents(); }; const onSubmit = async () => { @@ -93,13 +82,9 @@ const onSubmit = async () => { }; const deleteEvent = async () => { - try { - if (!props.event) return; - await axios.delete(`Zones/${route.params.id}/exclusions`); - await refetchEvents(); - } catch (err) { - console.error('Error deleting event: ', err); - } + if (!props.event) return; + await axios.delete(`Zones/${route.params.id}/exclusions`); + await refetchEvents(); }; const closeForm = () => emit('closeForm'); @@ -129,6 +114,7 @@ onMounted(() => { @on-submit="onSubmit()" :default-cancel-button="false" :default-submit-button="false" + :submit-on-enter="false" > diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue index 23a37ef7c..d0d4b18b8 100644 --- a/src/pages/Zone/Card/ZoneLocationsTree.vue +++ b/src/pages/Zone/Card/ZoneLocationsTree.vue @@ -38,6 +38,7 @@ const datakey = 'ZoneLocations'; const url = computed(() => `Zones/${route.params.id}/getLeaves`); const arrayData = useArrayData(datakey, { url: url.value, + limit: null, }); const store = arrayData.store; @@ -90,21 +91,16 @@ const onNodeExpanded = async (nodeKeysArray) => { previousExpandedNodes.value = nodeKeysSet; }; -const formatNodeSelected = (node) => { - if (node.selected === 1) node.selected = true; - else if (node.selected === 0) node.selected = false; - - if (node.sons > 0 && !node.childs) node.childs = [{}]; -}; - const fetchNodeLeaves = async (nodeKey) => { if (!treeRef.value) return; const node = treeRef.value?.getNodeByKey(nodeKey); - if (node.selected === 1) node.selected = true; - else if (node.selected === 0) node.selected = false; + if (typeof node.selected === 'number') node.selected = !!node.selected; + if (node.sons > 0 && !node.childs) { + node.childs = [{}]; + const index = expanded.value.indexOf(node.id); + expanded.value.splice(index, 1); + } if (!node || node.sons === 0) return; - - state.set('Tree', node); }; function getNodeIds(node) { @@ -128,18 +124,9 @@ watch( nodes.value[0].childs = [...val]; const fetchedNodeKeys = val.flatMap(getNodeIds); state.set('Tree', [...fetchedNodeKeys]); - - if (!store.userParams?.search) { - val.forEach((n) => { - formatNodeSelected(n); - }); - store.data = null; - expanded.value = [null]; - } else { - for (let n of state.get('Tree')) { - await fetchNodeLeaves(n); - } - expanded.value = [null, ...fetchedNodeKeys]; + expanded.value = [null, ...fetchedNodeKeys]; + for (let n of state.get('Tree')) { + await fetchNodeLeaves(n); } previousExpandedNodes.value = new Set(expanded.value); }, @@ -147,13 +134,11 @@ watch( ); const reFetch = async () => { - const { data } = await arrayData.fetch({ append: false }); - nodes.value = data; - expanded.value = [null]; + await arrayData.fetch({}); }; onMounted(async () => { - if (store.userParams?.search) await arrayData.fetch({}); + await reFetch(); }); onUnmounted(() => { @@ -167,13 +152,13 @@ onUnmounted(() => { v-if="showSearchBar" v-model="store.userParams.search" :placeholder="$t('globals.search')" - @update:model-value="reFetch()" + @keyup.enter="reFetch" > - + Date: Mon, 25 Nov 2024 11:12:11 +0100 Subject: [PATCH 2/4] refactor: requested changes --- src/components/FormPopup.vue | 10 +++++----- src/pages/Zone/Card/ZoneEventExclusionForm.vue | 11 ----------- src/pages/Zone/Card/ZoneLocationsTree.vue | 2 +- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/components/FormPopup.vue b/src/components/FormPopup.vue index 893ee8393..e1c15fcf4 100644 --- a/src/components/FormPopup.vue +++ b/src/components/FormPopup.vue @@ -57,12 +57,12 @@ const closeForm = () => { -

{{ $props.title }}

-

{{ $props.subtitle }}

+

{{ title }}

+

{{ subtitle }}

{ v-close-popup /> { }; await axios.post('Zones/exclusionGeo', params); await refetchEvents(); - const params = { - zoneFk: parseInt(route.params.id), - date: dated.value, - geoIds: tickedNodes.value, - }; - await axios.post('Zones/exclusionGeo', params); - await refetchEvents(); }; const exclusionCreate = async () => { @@ -92,9 +85,6 @@ const deleteEvent = async () => { if (!props.event) return; await axios.delete(`Zones/${route.params.id}/exclusions`); await refetchEvents(); - if (!props.event) return; - await axios.delete(`Zones/${route.params.id}/exclusions`); - await refetchEvents(); }; const closeForm = () => emit('closeForm'); @@ -131,7 +121,6 @@ onMounted(() => { diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue index d0d4b18b8..cc84b3665 100644 --- a/src/pages/Zone/Card/ZoneLocationsTree.vue +++ b/src/pages/Zone/Card/ZoneLocationsTree.vue @@ -152,7 +152,7 @@ onUnmounted(() => { v-if="showSearchBar" v-model="store.userParams.search" :placeholder="$t('globals.search')" - @keyup.enter="reFetch" + @keydown.enter="reFetch" >