forked from verdnatura/salix-front
Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix-front into dev
This commit is contained in:
commit
655a76ff62
|
@ -4,7 +4,7 @@ import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
const emit = defineEmits(['onSubmit']);
|
const emit = defineEmits(['onSubmit']);
|
||||||
|
|
||||||
defineProps({
|
const $props = defineProps({
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -25,16 +25,21 @@ defineProps({
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
submitOnEnter: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const closeButton = ref(null);
|
const closeButton = ref(null);
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
|
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
|
if ($props.submitOnEnter) {
|
||||||
emit('onSubmit');
|
emit('onSubmit');
|
||||||
closeForm();
|
closeForm();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeForm = () => {
|
const closeForm = () => {
|
||||||
|
|
|
@ -132,10 +132,24 @@ const addFilter = async (filter, params) => {
|
||||||
|
|
||||||
async function fetch(params) {
|
async function fetch(params) {
|
||||||
useArrayData(props.dataKey, params);
|
useArrayData(props.dataKey, params);
|
||||||
arrayData.reset(['filter.skip', 'skip']);
|
arrayData.reset(['filter.skip', 'skip', 'page']);
|
||||||
await arrayData.fetch({ append: false });
|
await arrayData.fetch({ append: false });
|
||||||
if (!store.hasMoreData) isLoading.value = false;
|
return emitStoreData();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function update(params) {
|
||||||
|
useArrayData(props.dataKey, params);
|
||||||
|
const { limit, skip } = store;
|
||||||
|
store.limit = limit + skip;
|
||||||
|
store.skip = 0;
|
||||||
|
await arrayData.fetch({ append: false });
|
||||||
|
store.limit = limit;
|
||||||
|
store.skip = skip;
|
||||||
|
return emitStoreData();
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitStoreData() {
|
||||||
|
if (!store.hasMoreData) isLoading.value = false;
|
||||||
emit('onFetch', store.data);
|
emit('onFetch', store.data);
|
||||||
return store.data;
|
return store.data;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +195,7 @@ async function onLoad(index, done) {
|
||||||
done(isDone);
|
done(isDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({ fetch, addFilter, paginate });
|
defineExpose({ fetch, update, addFilter, paginate });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -95,6 +95,7 @@ const columns = computed(() => [
|
||||||
optionLabel: 'description',
|
optionLabel: 'description',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
orderBy: 'priority',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
align: 'right',
|
align: 'right',
|
||||||
|
|
|
@ -350,7 +350,7 @@ const openTab = (id) =>
|
||||||
class="q-mr-sm"
|
class="q-mr-sm"
|
||||||
dense
|
dense
|
||||||
flat
|
flat
|
||||||
@click="$refs.tableRef.reload()"
|
@click="tableRef.CrudModelRef.vnPaginateRef.update()"
|
||||||
>
|
>
|
||||||
<QTooltip>{{ $t('globals.refresh') }}</QTooltip>
|
<QTooltip>{{ $t('globals.refresh') }}</QTooltip>
|
||||||
</QBtn>
|
</QBtn>
|
||||||
|
|
|
@ -43,7 +43,7 @@ const { t } = useI18n();
|
||||||
const { openConfirmationModal } = useVnConfirm();
|
const { openConfirmationModal } = useVnConfirm();
|
||||||
|
|
||||||
const isNew = computed(() => props.isNewMode);
|
const isNew = computed(() => props.isNewMode);
|
||||||
const dated = ref(null);
|
const dated = ref(props.date);
|
||||||
const tickedNodes = ref();
|
const tickedNodes = ref();
|
||||||
|
|
||||||
const _excludeType = ref('all');
|
const _excludeType = ref('all');
|
||||||
|
@ -73,7 +73,6 @@ const exclusionCreate = async () => {
|
||||||
await axios.post(`Zones/${route.params.id}/exclusions`, {
|
await axios.post(`Zones/${route.params.id}/exclusions`, {
|
||||||
dated: dated.value,
|
dated: dated.value,
|
||||||
});
|
});
|
||||||
|
|
||||||
await refetchEvents();
|
await refetchEvents();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,13 +114,14 @@ onMounted(() => {
|
||||||
@on-submit="onSubmit()"
|
@on-submit="onSubmit()"
|
||||||
:default-cancel-button="false"
|
:default-cancel-button="false"
|
||||||
:default-submit-button="false"
|
:default-submit-button="false"
|
||||||
|
:submit-on-enter="false"
|
||||||
>
|
>
|
||||||
<template #form-inputs>
|
<template #form-inputs>
|
||||||
<VnRow class="row q-gutter-md q-mb-lg">
|
<VnRow class="row q-gutter-md q-mb-lg">
|
||||||
<VnInputDate
|
<VnInputDate
|
||||||
:label="t('eventsInclusionForm.day')"
|
:label="t('eventsInclusionForm.day')"
|
||||||
v-model="dated"
|
v-model="dated"
|
||||||
:model-value="props.date"
|
:required="true"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
<div class="column q-gutter-y-sm q-mb-md">
|
<div class="column q-gutter-y-sm q-mb-md">
|
||||||
|
@ -182,6 +182,7 @@ onMounted(() => {
|
||||||
:label="isNew ? t('globals.add') : t('globals.save')"
|
:label="isNew ? t('globals.add') : t('globals.save')"
|
||||||
type="submit"
|
type="submit"
|
||||||
color="primary"
|
color="primary"
|
||||||
|
@click="onSubmit()"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</FormPopup>
|
</FormPopup>
|
||||||
|
|
|
@ -38,6 +38,7 @@ const datakey = 'ZoneLocations';
|
||||||
const url = computed(() => `Zones/${route.params.id}/getLeaves`);
|
const url = computed(() => `Zones/${route.params.id}/getLeaves`);
|
||||||
const arrayData = useArrayData(datakey, {
|
const arrayData = useArrayData(datakey, {
|
||||||
url: url.value,
|
url: url.value,
|
||||||
|
limit: null,
|
||||||
});
|
});
|
||||||
const store = arrayData.store;
|
const store = arrayData.store;
|
||||||
|
|
||||||
|
@ -74,6 +75,7 @@ const onNodeExpanded = async (nodeKeysArray) => {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
node.childs = response.data.map((n) => {
|
node.childs = response.data.map((n) => {
|
||||||
if (n.sons > 0) n.childs = [{}];
|
if (n.sons > 0) n.childs = [{}];
|
||||||
|
n.selected = isSelected(n.selected);
|
||||||
return n;
|
return n;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -90,21 +92,16 @@ const onNodeExpanded = async (nodeKeysArray) => {
|
||||||
previousExpandedNodes.value = nodeKeysSet;
|
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) => {
|
const fetchNodeLeaves = async (nodeKey) => {
|
||||||
if (!treeRef.value) return;
|
if (!treeRef.value) return;
|
||||||
const node = treeRef.value?.getNodeByKey(nodeKey);
|
const node = treeRef.value?.getNodeByKey(nodeKey);
|
||||||
if (node.selected === 1) node.selected = true;
|
if (typeof node.selected === 'number') node.selected = !!node.selected;
|
||||||
else if (node.selected === 0) node.selected = false;
|
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;
|
if (!node || node.sons === 0) return;
|
||||||
|
|
||||||
state.set('Tree', node);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getNodeIds(node) {
|
function getNodeIds(node) {
|
||||||
|
@ -119,6 +116,10 @@ function getNodeIds(node) {
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isSelected(selected) {
|
||||||
|
if (typeof selected === 'number') return !!selected;
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => store.data,
|
() => store.data,
|
||||||
async (val) => {
|
async (val) => {
|
||||||
|
@ -128,32 +129,21 @@ watch(
|
||||||
nodes.value[0].childs = [...val];
|
nodes.value[0].childs = [...val];
|
||||||
const fetchedNodeKeys = val.flatMap(getNodeIds);
|
const fetchedNodeKeys = val.flatMap(getNodeIds);
|
||||||
state.set('Tree', [...fetchedNodeKeys]);
|
state.set('Tree', [...fetchedNodeKeys]);
|
||||||
|
expanded.value = [null, ...fetchedNodeKeys];
|
||||||
if (!store.userParams?.search) {
|
|
||||||
val.forEach((n) => {
|
|
||||||
formatNodeSelected(n);
|
|
||||||
});
|
|
||||||
store.data = null;
|
|
||||||
expanded.value = [null];
|
|
||||||
} else {
|
|
||||||
for (let n of state.get('Tree')) {
|
for (let n of state.get('Tree')) {
|
||||||
await fetchNodeLeaves(n);
|
await fetchNodeLeaves(n);
|
||||||
}
|
}
|
||||||
expanded.value = [null, ...fetchedNodeKeys];
|
|
||||||
}
|
|
||||||
previousExpandedNodes.value = new Set(expanded.value);
|
previousExpandedNodes.value = new Set(expanded.value);
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
const reFetch = async () => {
|
const reFetch = async () => {
|
||||||
const { data } = await arrayData.fetch({ append: false });
|
await arrayData.fetch({});
|
||||||
nodes.value = data;
|
|
||||||
expanded.value = [null];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (store.userParams?.search) await arrayData.fetch({});
|
await reFetch();
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
@ -167,13 +157,13 @@ onUnmounted(() => {
|
||||||
v-if="showSearchBar"
|
v-if="showSearchBar"
|
||||||
v-model="store.userParams.search"
|
v-model="store.userParams.search"
|
||||||
:placeholder="$t('globals.search')"
|
:placeholder="$t('globals.search')"
|
||||||
@update:model-value="reFetch()"
|
@keydown.enter.stop.prevent="reFetch"
|
||||||
>
|
>
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<QBtn color="primary" icon="search" dense flat @click="reFetch()" />
|
<QBtn color="primary" icon="search" dense flat @click="reFetch()" />
|
||||||
</template>
|
</template>
|
||||||
</VnInput>
|
</VnInput>
|
||||||
<VnSearchbar :data-key="datakey" :url="url" :redirect="false" />
|
<VnSearchbar v-if="!showSearchBar" :data-key="datakey" :url="url" :redirect="false" />
|
||||||
<QTree
|
<QTree
|
||||||
ref="treeRef"
|
ref="treeRef"
|
||||||
:nodes="nodes"
|
:nodes="nodes"
|
||||||
|
|
Loading…
Reference in New Issue