0
0
Fork 0

feat: refs #6480 setArrayData

This commit is contained in:
Jorge Penadés 2024-04-18 13:33:21 +02:00
parent 75975b631e
commit f8da680e98
3 changed files with 56 additions and 66 deletions

View File

@ -1,26 +1,52 @@
<script setup> <script setup>
import { computed, onBeforeMount } from 'vue';
import { useRoute, onBeforeRouteUpdate } from 'vue-router';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useArrayData } from 'src/composables/useArrayData';
import { useStateStore } from 'stores/useStateStore'; import { useStateStore } from 'stores/useStateStore';
import useCardSize from 'src/composables/useCardSize'; import useCardSize from 'src/composables/useCardSize';
import VnSubToolbar from '../ui/VnSubToolbar.vue'; import VnSubToolbar from '../ui/VnSubToolbar.vue';
import LeftMenu from 'components/LeftMenu.vue';
import VnSearchbar from 'components/ui/VnSearchbar.vue'; import VnSearchbar from 'components/ui/VnSearchbar.vue';
import LeftMenu from 'components/LeftMenu.vue';
defineProps({ const props = defineProps({
dataKey: { type: String, default: null },
baseUrl: { type: String, default: null },
model: { type: String, default: null },
filter: { type: Object, default: null },
descriptor: { type: Object, required: true }, descriptor: { type: Object, required: true },
searchbarProps: { type: Object, required: true }, searchbarDataKey: { type: String, required: true },
searchbarUrl: { type: String, required: true },
searchbarLabel: { type: String, required: true },
searchbarInfo: { type: String, required: true },
}); });
const { t } = useI18n(); const { t } = useI18n();
const stateStore = useStateStore(); const stateStore = useStateStore();
const route = useRoute();
const url = computed(() => `${props.baseUrl}/${route.params.id}`);
let arrayData;
if (props.dataKey) {
arrayData = useArrayData(props.dataKey, { url, filter: props.filter });
onBeforeMount(async () => await arrayData.fetch({ append: false }));
onBeforeRouteUpdate(async (to, from) => {
if (!to.params.id !== from.params.id) {
arrayData.store.url = url;
await arrayData.fetch({ append: false });
}
});
}
</script> </script>
<template> <template>
<Teleport to="#searchbar" v-if="stateStore.isHeaderMounted()"> <Teleport to="#searchbar" v-if="stateStore.isHeaderMounted()">
<VnSearchbar <VnSearchbar
:data-key="searchbarProps.dataKey" :data-key="props.searchbarDataKey"
:url="searchbarProps.url" :url="props.searchbarUrl"
:label="t(searchbarProps.label)" :label="t(`${props.model}.searchbar.${props.searchbarLabel}`)"
:info="t(searchbarProps.info)" :info="t(props.searchbarInfo)"
/> />
</Teleport> </Teleport>
<QDrawer v-model="stateStore.leftDrawer" show-if-above :width="256"> <QDrawer v-model="stateStore.leftDrawer" show-if-above :width="256">

View File

@ -1,16 +1,6 @@
<script setup> <script setup>
import { useI18n } from 'vue-i18n';
import { useStateStore } from 'stores/useStateStore';
import InvoiceInDescriptor from './InvoiceInDescriptor.vue';
import VnSearchbar from 'components/ui/VnSearchbar.vue';
import { useArrayData } from 'src/composables/useArrayData';
import { onMounted, watch } from 'vue';
import { useRoute } from 'vue-router';
import VnCard from 'components/common/VnCard.vue'; import VnCard from 'components/common/VnCard.vue';
import InvoiceInDescriptor from './InvoiceInDescriptor.vue';
const stateStore = useStateStore();
const { t } = useI18n();
const route = useRoute();
const filter = { const filter = {
include: [ include: [
@ -19,51 +9,27 @@ const filter = {
scope: { scope: {
include: { include: {
relation: 'contacts', relation: 'contacts',
scope: { scope: { where: { email: { neq: null } } },
where: {
email: { neq: null },
}, },
}, },
}, },
}, { relation: 'invoiceInDueDay' },
}, { relation: 'company' },
{ { relation: 'currency' },
relation: 'invoiceInDueDay',
},
{
relation: 'company',
},
{
relation: 'currency',
},
], ],
}; };
const arrayData = useArrayData('InvoiceIn', {
url: `InvoiceIns/${route.params.id}`,
filter,
});
onMounted(async () => await arrayData.fetch({ append: false }));
watch(
() => route.params.id,
async (newId) => {
if (newId) {
arrayData.store.url = `InvoiceIns/${newId}`;
await arrayData.fetch({ append: false });
}
}
);
</script> </script>
<template> <template>
<Teleport to="#searchbar" v-if="stateStore.isHeaderMounted()"> <VnCard
<VnSearchbar data-key="InvoiceIn"
data-key="InvoiceInList" base-url="InvoiceIns"
url="InvoiceIns/filter" :filter="filter"
:label="t('Search invoice')" :descriptor="InvoiceInDescriptor"
:info="t('You can search by invoice reference')" searchbar-data-key="InvoiceInList"
searchbar-url="InvoiceIns/filter"
searchbar-label="Search invoice"
searchbar-info="You can search by invoice reference"
/> />
</Teleport>
<VnCard :descriptor="InvoiceInDescriptor" />
</template> </template>
<i18n> <i18n>
es: es:

View File

@ -1,18 +1,16 @@
<script setup> <script setup>
import InvoiceOutDescriptor from './InvoiceOutDescriptor.vue'; import InvoiceOutDescriptor from './InvoiceOutDescriptor.vue';
import VnCard from 'components/common/VnCard.vue'; import VnCard from 'components/common/VnCard.vue';
const searchbar = {
dataKey: 'InvoiceOutList',
url: 'InvoiceOuts/filter',
label: 'Search invoice',
info: 'You can search by invoice reference',
};
</script> </script>
<template> <template>
<VnCard :descriptor="InvoiceOutDescriptor" :searchbar-props="searchbar" /> <VnCard
:descriptor="InvoiceOutDescriptor"
searchbar-data-key="InvoiceOutList"
searchbar-url="InvoiceOuts/filter"
searchbar-label="Search invoice"
searchbar-info="You can search by invoice reference"
/>
</template> </template>
<i18n> <i18n>
es: es:
Search invoice: Buscar factura emitida Search invoice: Buscar factura emitida