refactor: refs #7524 remove limit and sort parameters from FetchData components
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Jorge Penadés 2025-02-06 13:28:46 +01:00
parent f9ba0642e1
commit 68d2b97ced
9 changed files with 25 additions and 143 deletions

View File

@ -21,14 +21,11 @@ const postcodeFormData = reactive({
provinceFk: null, provinceFk: null,
townFk: null, townFk: null,
}); });
const townsFetchDataRef = ref(false);
const townFilter = ref({}); const townFilter = ref({});
const countriesRef = ref(false); const countriesRef = ref(false);
const provincesOptions = ref([]); const provincesOptions = ref([]);
const townsOptions = ref([]);
const town = ref({}); const town = ref({});
const countryFilter = ref({});
function onDataSaved(formData) { function onDataSaved(formData) {
const newPostcode = { const newPostcode = {
@ -51,7 +48,6 @@ async function setCountry(countryFk, data) {
data.townFk = null; data.townFk = null;
data.provinceFk = null; data.provinceFk = null;
data.countryFk = countryFk; data.countryFk = countryFk;
await fetchTowns();
} }
// Province // Province
@ -60,22 +56,11 @@ async function setProvince(id, data) {
const newProvince = provincesOptions.value.find((province) => province.id == id); const newProvince = provincesOptions.value.find((province) => province.id == id);
if (newProvince) data.countryFk = newProvince.countryFk; if (newProvince) data.countryFk = newProvince.countryFk;
postcodeFormData.provinceFk = id; postcodeFormData.provinceFk = id;
await fetchTowns();
} }
async function onProvinceCreated(data) { async function onProvinceCreated(data) {
postcodeFormData.provinceFk = data.id; postcodeFormData.provinceFk = data.id;
} }
function provinceByCountry(countryFk = postcodeFormData.countryFk) {
return provincesOptions.value
.filter((province) => province.countryFk === countryFk)
.map(({ id }) => id);
}
// Town
async function handleTowns(data) {
townsOptions.value = data;
}
function setTown(newTown, data) { function setTown(newTown, data) {
town.value = newTown; town.value = newTown;
data.provinceFk = newTown?.provinceFk ?? newTown; data.provinceFk = newTown?.provinceFk ?? newTown;
@ -88,18 +73,6 @@ async function onCityCreated(newTown, formData) {
formData.townFk = newTown; formData.townFk = newTown;
setTown(newTown, formData); setTown(newTown, formData);
} }
async function fetchTowns(countryFk = postcodeFormData.countryFk) {
if (!countryFk) return;
const provinces = postcodeFormData.provinceFk
? [postcodeFormData.provinceFk]
: provinceByCountry();
townFilter.value.where = {
provinceFk: {
inq: provinces,
},
};
await townsFetchDataRef.value?.fetch();
}
async function filterTowns(name) { async function filterTowns(name) {
if (name !== '') { if (name !== '') {
@ -108,22 +81,11 @@ async function filterTowns(name) {
like: `%${name}%`, like: `%${name}%`,
}, },
}; };
await townsFetchDataRef.value?.fetch();
} }
} }
</script> </script>
<template> <template>
<FetchData
ref="townsFetchDataRef"
:sort-by="['name ASC']"
:limit="30"
:filter="townFilter"
@on-fetch="handleTowns"
auto-load
url="Towns/location"
/>
<FormModelPopup <FormModelPopup
url-create="postcodes" url-create="postcodes"
model="postcode" model="postcode"
@ -149,14 +111,13 @@ async function filterTowns(name) {
@filter="filterTowns" @filter="filterTowns"
:tooltip="t('Create city')" :tooltip="t('Create city')"
v-model="data.townFk" v-model="data.townFk"
:options="townsOptions" url="Towns/location"
option-label="name"
option-value="id"
:rules="validate('postcode.city')" :rules="validate('postcode.city')"
:acls="[{ model: 'Town', props: '*', accessType: 'WRITE' }]" :acls="[{ model: 'Town', props: '*', accessType: 'WRITE' }]"
:emit-value="false" :emit-value="false"
required required
data-cy="locationTown" data-cy="locationTown"
sort-by="name"
> >
<template #option="{ itemProps, opt }"> <template #option="{ itemProps, opt }">
<QItem v-bind="itemProps"> <QItem v-bind="itemProps">
@ -197,16 +158,12 @@ async function filterTowns(name) {
/> />
<VnSelect <VnSelect
ref="countriesRef" ref="countriesRef"
:limit="30"
:filter="countryFilter"
:sort-by="['name ASC']" :sort-by="['name ASC']"
auto-load auto-load
url="Countries" url="Countries"
required required
:label="t('Country')" :label="t('Country')"
hide-selected hide-selected
option-label="name"
option-value="id"
v-model="data.countryFk" v-model="data.countryFk"
:rules="validate('postcode.countryFk')" :rules="validate('postcode.countryFk')"
@update:model-value="(value) => setCountry(value, data)" @update:model-value="(value) => setCountry(value, data)"

View File

@ -62,12 +62,9 @@ const where = computed(() => {
auto-load auto-load
:where="where" :where="where"
url="Autonomies/location" url="Autonomies/location"
:sort-by="['name ASC']" sort-by="name"
:limit="30"
:label="t('Autonomy')" :label="t('Autonomy')"
hide-selected hide-selected
option-label="name"
option-value="id"
v-model="data.autonomyFk" v-model="data.autonomyFk"
:rules="validate('province.autonomyFk')" :rules="validate('province.autonomyFk')"
> >

View File

@ -31,7 +31,6 @@ const props = defineProps({
const route = useRoute(); const route = useRoute();
const itemTypesOptions = ref([]); const itemTypesOptions = ref([]);
const suppliersOptions = ref([]);
const tagOptions = ref([]); const tagOptions = ref([]);
const tagValues = ref([]); const tagValues = ref([]);
const categoryList = ref(null); const categoryList = ref(null);
@ -123,7 +122,6 @@ const removeTag = (index, params, search) => {
}; };
const setCategoryList = (data) => { const setCategoryList = (data) => {
categoryList.value = (data || []) categoryList.value = (data || [])
.filter((category) => category.display)
.map((category) => ({ .map((category) => ({
...category, ...category,
icon: `vn:${(category.icon || '').split('-')[1]}`, icon: `vn:${(category.icon || '').split('-')[1]}`,
@ -133,19 +131,11 @@ const setCategoryList = (data) => {
</script> </script>
<template> <template>
<FetchData url="ItemCategories" limit="30" auto-load @on-fetch="setCategoryList" /> <FetchData url="ItemCategories" auto-load @on-fetch="setCategoryList" :where="{display: {neq: 0}}"/>
<FetchData
url="Suppliers"
limit="30"
auto-load
:filter="{ fields: ['id', 'name', 'nickname'], order: 'name ASC', limit: 30 }"
@on-fetch="(data) => (suppliersOptions = data)"
/>
<FetchData <FetchData
url="Tags" url="Tags"
:filter="{ fields: ['id', 'name', 'isFree'] }" :filter="{ fields: ['id', 'name', 'isFree'] }"
auto-load auto-load
limit="30"
@on-fetch="(data) => (tagOptions = data)" @on-fetch="(data) => (tagOptions = data)"
/> />
<VnFilterPanel <VnFilterPanel
@ -203,8 +193,6 @@ const setCategoryList = (data) => {
:label="t('components.itemsFilterPanel.typeFk')" :label="t('components.itemsFilterPanel.typeFk')"
v-model="params.typeFk" v-model="params.typeFk"
:options="itemTypesOptions" :options="itemTypesOptions"
option-value="id"
option-label="name"
dense dense
outlined outlined
rounded rounded
@ -242,7 +230,6 @@ const setCategoryList = (data) => {
:label="t('globals.tag')" :label="t('globals.tag')"
v-model="value.selectedTag" v-model="value.selectedTag"
:options="tagOptions" :options="tagOptions"
option-label="name"
dense dense
outlined outlined
rounded rounded

View File

@ -1,8 +1,6 @@
<script setup> <script setup>
import { ref } from 'vue'; import { ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import FetchData from 'components/FetchData.vue';
import VnInputDate from 'src/components/common/VnInputDate.vue'; import VnInputDate from 'src/components/common/VnInputDate.vue';
import VnInput from 'components/common/VnInput.vue'; import VnInput from 'components/common/VnInput.vue';
import VnSelect from 'components/common/VnSelect.vue'; import VnSelect from 'components/common/VnSelect.vue';
@ -17,26 +15,10 @@ defineProps({
}, },
}); });
const itemTypeWorkersOptions = ref([]);
const suppliersOptions = ref([]);
const tagValues = ref([]); const tagValues = ref([]);
</script> </script>
<template> <template>
<FetchData
url="TicketRequests/getItemTypeWorker"
limit="30"
auto-load
:filter="{ fields: ['id', 'nickname'], order: 'nickname ASC', limit: 30 }"
@on-fetch="(data) => (itemTypeWorkersOptions = data)"
/>
<FetchData
url="Suppliers"
limit="30"
auto-load
:filter="{ fields: ['id', 'name', 'nickname'], order: 'name ASC', limit: 30 }"
@on-fetch="(data) => (suppliersOptions = data)"
/>
<ItemsFilterPanel :data-key="dataKey" :custom-tags="['tags']"> <ItemsFilterPanel :data-key="dataKey" :custom-tags="['tags']">
<template #body="{ params, searchFn }"> <template #body="{ params, searchFn }">
<QItem class="q-my-md"> <QItem class="q-my-md">
@ -44,9 +26,10 @@ const tagValues = ref([]);
<VnSelect <VnSelect
:label="t('components.itemsFilterPanel.salesPersonFk')" :label="t('components.itemsFilterPanel.salesPersonFk')"
v-model="params.salesPersonFk" v-model="params.salesPersonFk"
:options="itemTypeWorkersOptions" url="TicketRequests/getItemTypeWorker"
option-value="id"
option-label="nickname" option-label="nickname"
:fields=" ['id', 'nickname']"
sort-by="nickname"
dense dense
outlined outlined
rounded rounded
@ -60,9 +43,9 @@ const tagValues = ref([]);
<VnSelect <VnSelect
:label="t('globals.params.supplierFk')" :label="t('globals.params.supplierFk')"
v-model="params.supplierFk" v-model="params.supplierFk"
:options="suppliersOptions" url="Suppliers"
option-value="id" :fields="['id', 'name', 'nickname']"
option-label="name" sort-by="name"
dense dense
outlined outlined
rounded rounded

View File

@ -7,7 +7,6 @@ import { toDate } from 'src/filters';
import { useArrayData } from 'src/composables/useArrayData'; import { useArrayData } from 'src/composables/useArrayData';
import { getTotal } from 'src/composables/getTotal'; import { getTotal } from 'src/composables/getTotal';
import CrudModel from 'src/components/CrudModel.vue'; import CrudModel from 'src/components/CrudModel.vue';
import FetchData from 'src/components/FetchData.vue';
import VnSelect from 'src/components/common/VnSelect.vue'; import VnSelect from 'src/components/common/VnSelect.vue';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
import VnInputDate from 'src/components/common/VnInputDate.vue'; import VnInputDate from 'src/components/common/VnInputDate.vue';
@ -21,7 +20,6 @@ const invoiceIn = computed(() => arrayData.store.data);
const currency = computed(() => invoiceIn.value?.currency?.code); const currency = computed(() => invoiceIn.value?.currency?.code);
const rowsSelected = ref([]); const rowsSelected = ref([]);
const banks = ref([]);
const invoiceInFormRef = ref(); const invoiceInFormRef = ref();
const invoiceId = +route.params.id; const invoiceId = +route.params.id;
const filter = { where: { invoiceInFk: invoiceId } }; const filter = { where: { invoiceInFk: invoiceId } };
@ -40,10 +38,9 @@ const columns = computed(() => [
name: 'bank', name: 'bank',
label: t('Bank'), label: t('Bank'),
field: (row) => row.bankFk, field: (row) => row.bankFk,
options: banks.value,
model: 'bankFk', model: 'bankFk',
optionValue: 'id',
optionLabel: 'bank', optionLabel: 'bank',
url: 'Accountings',
sortable: true, sortable: true,
tabIndex: 2, tabIndex: 2,
align: 'left', align: 'left',
@ -75,12 +72,6 @@ async function insert() {
} }
</script> </script>
<template> <template>
<FetchData
url="Accountings"
auto-load
limit="30"
@on-fetch="(data) => (banks = data)"
/>
<CrudModel <CrudModel
v-if="invoiceIn" v-if="invoiceIn"
ref="invoiceInFormRef" ref="invoiceInFormRef"
@ -110,8 +101,7 @@ async function insert() {
<QTd> <QTd>
<VnSelect <VnSelect
v-model="row[col.model]" v-model="row[col.model]"
:options="col.options" :url="col.url"
:option-value="col.optionValue"
:option-label="col.optionLabel" :option-label="col.optionLabel"
> >
<template #option="scope"> <template #option="scope">
@ -186,8 +176,7 @@ async function insert() {
:label="t('Bank')" :label="t('Bank')"
class="full-width" class="full-width"
v-model="props.row['bankFk']" v-model="props.row['bankFk']"
:options="banks" url="Accountings"
option-value="id"
option-label="bank" option-label="bank"
> >
<template #option="scope"> <template #option="scope">

View File

@ -1,8 +1,6 @@
<script setup> <script setup>
import { ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import FetchData from 'components/FetchData.vue';
import VnInputDate from 'src/components/common/VnInputDate.vue'; import VnInputDate from 'src/components/common/VnInputDate.vue';
import VnSelect from 'components/common/VnSelect.vue'; import VnSelect from 'components/common/VnSelect.vue';
import ItemsFilterPanel from 'src/components/ItemsFilterPanel.vue'; import ItemsFilterPanel from 'src/components/ItemsFilterPanel.vue';
@ -16,17 +14,9 @@ const props = defineProps({
}, },
}); });
const itemTypeWorkersOptions = ref([]);
</script> </script>
<template> <template>
<FetchData
url="TicketRequests/getItemTypeWorker"
limit="30"
auto-load
:filter="{ fields: ['id', 'nickname'], order: 'nickname ASC', limit: 30 }"
@on-fetch="(data) => (itemTypeWorkersOptions = data)"
/>
<ItemsFilterPanel :data-key="props.dataKey" :custom-tags="['tags']"> <ItemsFilterPanel :data-key="props.dataKey" :custom-tags="['tags']">
<template #body="{ params, searchFn }"> <template #body="{ params, searchFn }">
<QItem class="q-my-md"> <QItem class="q-my-md">
@ -34,14 +24,15 @@ const itemTypeWorkersOptions = ref([]);
<VnSelect <VnSelect
:label="t('params.buyerFk')" :label="t('params.buyerFk')"
v-model="params.buyerFk" v-model="params.buyerFk"
:options="itemTypeWorkersOptions" url="TicketRequests/getItemTypeWorker"
option-value="id" :fields="['id', 'nickname']"
option-label="nickname" option-label="nickname"
dense dense
outlined outlined
rounded rounded
use-input use-input
@update:model-value="searchFn()" @update:model-value="searchFn()"
sort-by="nickname"
/> />
</QItemSection> </QItemSection>
</QItem> </QItem>
@ -50,11 +41,10 @@ const itemTypeWorkersOptions = ref([]);
<VnSelect <VnSelect
url="Warehouses" url="Warehouses"
auto-load auto-load
:filter="{ fields: ['id', 'name'], order: 'name ASC', limit: 30 }" :fields="['id', 'name']"
sort-by="name"
:label="t('params.warehouseFk')" :label="t('params.warehouseFk')"
v-model="params.warehouseFk" v-model="params.warehouseFk"
option-label="name"
option-value="id"
dense dense
outlined outlined
rounded rounded

View File

@ -48,7 +48,6 @@ const onFetch = (data) => {
}, },
], ],
}" }"
limit="30"
@on-fetch="onFetch" @on-fetch="onFetch"
/> />
<div :class="[isDialog ? 'column' : 'form-gap', 'full-width flex']"> <div :class="[isDialog ? 'column' : 'form-gap', 'full-width flex']">

View File

@ -1,36 +1,24 @@
<script setup> <script setup>
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute, useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import VnRow from 'components/ui/VnRow.vue'; import VnRow from 'components/ui/VnRow.vue';
import FormModel from 'components/FormModel.vue'; import FormModel from 'components/FormModel.vue';
import VnInputDate from 'components/common/VnInputDate.vue'; import VnInputDate from 'components/common/VnInputDate.vue';
import VnInput from 'components/common/VnInput.vue'; import VnInput from 'components/common/VnInput.vue';
import VnInputTime from 'components/common/VnInputTime.vue'; import VnInputTime from 'components/common/VnInputTime.vue';
import VnSelect from 'components/common/VnSelect.vue'; import VnSelect from 'components/common/VnSelect.vue';
import FetchData from 'components/FetchData.vue';
import { ref } from 'vue';
const { t } = useI18n(); const { t } = useI18n();
const router = useRouter(); const router = useRouter();
const route = useRoute();
const supplierList = ref([]);
const filter = { include: [{ relation: 'supplier' }] }; const filter = { include: [{ relation: 'supplier' }] };
const onSave = (data, response) => { const onSave = (data, response) => {
router.push({ name: 'RoadmapSummary', params: { id: response?.id } }); router.push({ name: 'RoadmapSummary', params: { id: response?.id } });
}; };
</script> </script>
<template> <template>
<FetchData
url="Suppliers"
auto-load
:filter="{ fields: ['id', 'nickname'] }"
sort-by="nickname"
limit="30"
@on-fetch="(data) => (supplierList = data)"
/>
<FormModel <FormModel
:url="`Roadmaps/${route.params?.id}`" :url="`Roadmaps/${$route.params?.id}`"
observe-form-changes observe-form-changes
:filter="filter" :filter="filter"
model="roadmap" model="roadmap"
@ -59,8 +47,8 @@ const onSave = (data, response) => {
<VnSelect <VnSelect
:label="t('Carrier')" :label="t('Carrier')"
v-model="data.supplierFk" v-model="data.supplierFk"
:options="supplierList" url="Suppliers"
option-value="id" :fields="['id', 'nickname']"
option-label="nickname" option-label="nickname"
emit-value emit-value
map-options map-options

View File

@ -37,14 +37,6 @@ const exprBuilder = (param, value) => {
</script> </script>
<template> <template>
<FetchData
url="Suppliers"
:filter="{ fields: ['id', 'nickname'] }"
sort-by="nickname"
limit="30"
@on-fetch="(data) => (supplierList = data)"
auto-load
/>
<VnFilterPanel <VnFilterPanel
:data-key="props.dataKey" :data-key="props.dataKey"
:search-button="true" :search-button="true"
@ -88,13 +80,13 @@ const exprBuilder = (param, value) => {
/> />
</QItemSection> </QItemSection>
</QItem> </QItem>
<QItem v-if="supplierList" class="q-my-sm"> <QItem class="q-my-sm">
<QItemSection> <QItemSection>
<VnSelect <VnSelect
:label="t('Carrier')" :label="t('Carrier')"
:fields="['id', 'nickname']"
v-model="params.supplierFk" v-model="params.supplierFk"
:options="supplierList" url="Suppliers"
option-value="id"
option-label="nickname" option-label="nickname"
dense dense
outlined outlined