feat: refs #6919 improve vn-card logic

This commit is contained in:
Jorge Penadés 2024-11-14 17:30:54 +01:00
parent 7626c777ed
commit 565ec15589
22 changed files with 28 additions and 33 deletions

View File

@ -10,11 +10,11 @@ import LeftMenu from 'components/LeftMenu.vue';
import RightMenu from 'components/common/RightMenu.vue';
const props = defineProps({
dataKey: { type: String, required: true },
baseUrl: { type: String, default: undefined },
customUrl: { type: String, default: undefined },
url: { type: String, default: undefined },
filter: { type: Object, default: () => {} },
descriptor: { type: Object, required: true },
filterPanel: { type: Object, default: undefined },
idInWhere: { type: Boolean, default: false },
searchDataKey: { type: String, default: undefined },
searchbarProps: { type: Object, default: undefined },
redirectOnError: { type: Boolean, default: false },
@ -23,24 +23,18 @@ const props = defineProps({
const stateStore = useStateStore();
const route = useRoute();
const router = useRouter();
const url = computed(() => {
if (props.baseUrl) {
return `${props.baseUrl}/${route.params.id}`;
}
return props.customUrl;
});
const searchRightDataKey = computed(() => {
if (!props.searchDataKey) return route.name;
return props.searchDataKey;
});
const arrayData = useArrayData(props.dataKey, {
url: url.value,
url: props.url,
filter: props.filter,
});
onBeforeMount(async () => {
try {
if (!props.baseUrl) arrayData.store.filter.where = { id: route.params.id };
if (props.idInWhere) arrayData.store.filter.where = { id: route.params.id };
await arrayData.fetch({ append: false, updateRouter: false });
} catch {
const { matched: matches } = router.currentRoute.value;
@ -49,10 +43,10 @@ onBeforeMount(async () => {
}
});
if (props.baseUrl) {
if (!props.idInWhere) {
onBeforeRouteUpdate(async (to, from) => {
if (to.params.id !== from.params.id) {
arrayData.store.url = `${props.baseUrl}/${to.params.id}`;
arrayData.store.url = `${props.url}/${to.params.id}`;
await arrayData.fetch({ append: false, updateRouter: false });
}
});

View File

@ -8,7 +8,7 @@ const { t } = useI18n();
<template>
<VnCard
data-key="Alias"
base-url="MailAliases"
url="MailAliases"
:descriptor="AliasDescriptor"
search-data-key="AccountAliasList"
:searchbar-props="{

View File

@ -7,7 +7,7 @@ import filter from './ClaimFilter.js';
<template>
<VnCard
data-key="Claim"
base-url="Claims"
url="Claims"
:descriptor="ClaimDescriptor"
:filter-panel="ClaimFilter"
search-data-key="ClaimList"

View File

@ -12,7 +12,7 @@ const routeName = computed(() => route.name);
<template>
<VnCard
data-key="Client"
base-url="Clients"
url="Clients"
:descriptor="CustomerDescriptor"
:filter-panel="routeName != 'CustomerConsumption' && CustomerFilter"
search-data-key="CustomerList"

View File

@ -7,7 +7,7 @@ import DepartmentDescriptor from 'pages/Department/Card/DepartmentDescriptor.vue
class="q-pa-md column items-center"
v-bind="{ ...$attrs }"
data-key="Department"
base-url="Departments"
url="Departments"
:descriptor="DepartmentDescriptor"
/>
</template>

View File

@ -7,7 +7,7 @@ import filter from './EntryFilter.js';
<template>
<VnCard
data-key="Entry"
base-url="Entries"
url="Entries"
:filter="filter"
:descriptor="EntryDescriptor"
:filter-panel="EntryFilter"

View File

@ -45,7 +45,7 @@ onBeforeRouteUpdate(async (to) => await setRectificative(to));
<template>
<VnCard
data-key="InvoiceIn"
base-url="InvoiceIns"
url="InvoiceIns"
:filter="filter"
:descriptor="InvoiceInDescriptor"
:filter-panel="InvoiceInFilter"

View File

@ -6,7 +6,7 @@ import InvoiceOutFilter from '../InvoiceOutFilter.vue';
<template>
<VnCard
data-key="InvoiceOut"
base-url="InvoiceOuts"
url="InvoiceOuts"
:descriptor="InvoiceOutDescriptor"
:filter-panel="InvoiceOutFilter"
search-data-key="InvoiceOutList"

View File

@ -6,7 +6,7 @@ import ItemListFilter from '../ItemListFilter.vue';
<template>
<VnCard
data-key="Item"
base-url="Items"
url="Items"
:descriptor="ItemDescriptor"
:filter-panel="ItemListFilter"
search-data-key="ItemList"

View File

@ -7,7 +7,7 @@ import ItemTypeSearchbar from '../ItemTypeSearchbar.vue';
<template>
<VnCard
data-key="ItemTypeSummary"
base-url="ItemTypes"
url="ItemTypes"
:descriptor="ItemTypeDescriptor"
:filter-panel="ItemTypeFilter"
search-data-key="ItemTypeList"

View File

@ -26,7 +26,7 @@ const customFilterPanel = computed(() => {
<template>
<VnCard
data-key="Order"
base-url="Orders"
url="Orders"
:descriptor="OrderDescriptor"
:filter-panel="customFilterPanel"
:search-data-key="customRouteRedirectName"

View File

@ -6,7 +6,7 @@ import ParkingFilter from 'pages/Parking/ParkingFilter.vue';
<template>
<VnCard
data-key="Parking"
base-url="Parkings"
url="Parkings"
:descriptor="ParkingDescriptor"
:filter-panel="ParkingFilter"
search-data-key="ParkingList"

View File

@ -5,7 +5,7 @@ import VnCard from 'components/common/VnCard.vue';
<template>
<VnCard
data-key="Agency"
base-url="Agencies"
url="Agencies"
:descriptor="AgencyDescriptor"
search-data-key="AgencyList"
:searchbar-props="{

View File

@ -7,7 +7,7 @@ import RouteSearchbar from 'pages/Route/Card/RouteSearchbar.vue';
<template>
<VnCard
data-key="Route"
base-url="Routes"
url="Routes"
:descriptor="RouteDescriptor"
:filter-panel="RouteFilter"
search-data-key="RouteList"

View File

@ -6,7 +6,7 @@ import RoadmapFilter from 'pages/Route/Roadmap/RoadmapFilter.vue';
<template>
<VnCard
data-key="Roadmap"
base-url="Roadmaps"
url="Roadmaps"
:descriptor="RoadmapDescriptor"
:filter-panel="RoadmapFilter"
search-data-key="RoadmapList"

View File

@ -7,7 +7,7 @@ import ShelvingSearchbar from './ShelvingSearchbar.vue';
<template>
<VnCard
data-key="Shelving"
base-url="Shelvings"
url="Shelvings"
:descriptor="ShelvingDescriptor"
:filter-panel="ShelvingFilter"
search-data-key="ShelvingList"

View File

@ -6,7 +6,7 @@ import SupplierListFilter from '../SupplierListFilter.vue';
<template>
<VnCard
data-key="Supplier"
base-url="Suppliers"
url="Suppliers"
:descriptor="SupplierDescriptor"
:filter-panel="SupplierListFilter"
search-data-key="SupplierList"

View File

@ -10,7 +10,7 @@ const { t } = useI18n();
<template>
<VnCard
data-key="Ticket"
base-url="Tickets"
url="Tickets"
:filter-panel="TicketFilter"
:descriptor="TicketDescriptor"
search-data-key="TicketList"

View File

@ -33,7 +33,7 @@ const filter = {
<template>
<VnCard
data-key="Travel"
base-url="Travels"
url="Travels"
search-data-key="TravelList"
:filter="filter"
:descriptor="TravelDescriptor"

View File

@ -2,5 +2,5 @@
import VnCard from 'components/common/VnCard.vue';
</script>
<template>
<VnCard data-key="Wagon" base-url="Wagons" />
<VnCard data-key="Wagon" url="Wagons" />
</template>

View File

@ -6,7 +6,8 @@ import WorkerFilter from '../WorkerFilter.vue';
<template>
<VnCard
data-key="Worker"
custom-url="Workers/summary"
url="Workers/summary"
:id-in-where="true"
:descriptor="WorkerDescriptor"
:filter-panel="WorkerFilter"
search-data-key="WorkerList"

View File

@ -20,7 +20,7 @@ function notIsLocations(ifIsFalse, ifIsTrue) {
<template>
<VnCard
data-key="zone"
base-url="Zones"
url="Zones"
:descriptor="ZoneDescriptor"
:filter-panel="ZoneFilterPanel"
:search-data-key="notIsLocations('ZoneList', 'ZoneLocations')"