Merge pull request 'Hotfix: ZoneLocationsTree' (!995) from Fix-ZoneLocationsTree2 into master
gitea/salix-front/pipeline/pr-test This commit looks good Details
gitea/salix-front/pipeline/head This commit looks good Details

Reviewed-on: #995
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Jon Elias 2024-11-25 11:56:30 +00:00
commit 843c54fcc1
3 changed files with 35 additions and 35 deletions

View File

@ -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 = () => {

View File

@ -73,7 +73,6 @@ const exclusionCreate = async () => {
await axios.post(`Zones/${route.params.id}/exclusions`, {
dated: dated.value,
});
await refetchEvents();
};
@ -115,10 +114,15 @@ onMounted(() => {
@on-submit="onSubmit()"
:default-cancel-button="false"
:default-submit-button="false"
:submit-on-enter="false"
>
<template #form-inputs>
<VnRow class="row q-gutter-md q-mb-lg">
<VnInputDate :label="t('eventsInclusionForm.day')" v-model="dated" />
<VnInputDate
:label="t('eventsInclusionForm.day')"
v-model="dated"
:required="true"
/>
</VnRow>
<div class="column q-gutter-y-sm q-mb-md">
<QRadio
@ -178,6 +182,7 @@ onMounted(() => {
:label="isNew ? t('globals.add') : t('globals.save')"
type="submit"
color="primary"
@click="onSubmit()"
/>
</template>
</FormPopup>

View File

@ -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;
@ -74,6 +75,7 @@ const onNodeExpanded = async (nodeKeysArray) => {
if (response.data) {
node.childs = response.data.map((n) => {
if (n.sons > 0) n.childs = [{}];
n.selected = isSelected(n.selected);
return n;
});
}
@ -90,21 +92,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) {
@ -119,6 +116,10 @@ function getNodeIds(node) {
return ids;
}
function isSelected(selected) {
if (typeof selected === 'number') return !!selected;
}
watch(
() => store.data,
async (val) => {
@ -128,18 +129,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 +139,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 +157,13 @@ onUnmounted(() => {
v-if="showSearchBar"
v-model="store.userParams.search"
:placeholder="$t('globals.search')"
@update:model-value="reFetch()"
@keydown.enter.stop.prevent="reFetch"
>
<template #prepend>
<QBtn color="primary" icon="search" dense flat @click="reFetch()" />
</template>
</VnInput>
<VnSearchbar :data-key="datakey" :url="url" :redirect="false" />
<VnSearchbar v-if="!showSearchBar" :data-key="datakey" :url="url" :redirect="false" />
<QTree
ref="treeRef"
:nodes="nodes"