feat: refs #5186 use arrayData in summary
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-03-22 14:57:36 +01:00
parent f86c331afa
commit d2efbb204f
11 changed files with 61 additions and 56 deletions

View File

@ -41,7 +41,12 @@ const state = useState();
const slots = useSlots(); const slots = useSlots();
const { t } = useI18n(); const { t } = useI18n();
const { viewSummary } = useSummaryDialog(); const { viewSummary } = useSummaryDialog();
const { store } = useArrayData($props.dataKey); const arrayData = useArrayData($props.dataKey || $props.module, {
url: $props.url,
filter: $props.filter,
skip: 0,
});
const { store } = arrayData;
const entity = computed(() => store.data); const entity = computed(() => store.data);
const isLoading = ref(false); const isLoading = ref(false);
@ -49,24 +54,15 @@ defineExpose({
getData, getData,
}); });
onBeforeMount(async () => { onBeforeMount(async () => {
if ($props.url) { await getData();
await getData(); watch(
watch( () => $props.url,
() => $props.url, async () => await getData()
async (newUrl, lastUrl) => { );
if (newUrl == lastUrl) return;
await getData();
}
);
}
}); });
async function getData() { async function getData() {
const arrayData = useArrayData($props.dataKey, { store.url = $props.url;
url: $props.url,
filter: $props.filter,
skip: 0,
});
isLoading.value = true; isLoading.value = true;
try { try {
const { data } = await arrayData.fetch({ append: false, updateRouter: false }); const { data } = await arrayData.fetch({ append: false, updateRouter: false });

View File

@ -1,11 +1,10 @@
<script setup> <script setup>
import { onMounted, ref, watch } from 'vue'; import { ref, computed, watch, onBeforeMount } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import axios from 'axios';
import SkeletonSummary from 'components/ui/SkeletonSummary.vue'; import SkeletonSummary from 'components/ui/SkeletonSummary.vue';
import VnLv from 'src/components/ui/VnLv.vue'; import VnLv from 'src/components/ui/VnLv.vue';
import { useArrayData } from 'src/composables/useArrayData';
const entity = ref();
const props = defineProps({ const props = defineProps({
url: { url: {
type: String, type: String,
@ -19,43 +18,48 @@ const props = defineProps({
type: Number, type: Number,
default: null, default: null,
}, },
dataKey: {
type: String,
default: '',
},
}); });
const emit = defineEmits(['onFetch']); const emit = defineEmits(['onFetch']);
const route = useRoute(); const route = useRoute();
const isSummary = ref(); const isSummary = ref();
const arrayData = useArrayData(props.dataKey || route.meta.moduleName, {
url: props.url,
filter: props.filter,
skip: 0,
});
const { store } = arrayData;
const entity = computed(() => store.data);
const isLoading = ref(false);
defineExpose({ defineExpose({
entity, entity,
fetch, fetch,
}); });
onMounted(() => { onBeforeMount(async () => {
isSummary.value = String(route.path).endsWith('/summary'); isSummary.value = String(route.path).endsWith('/summary');
fetch(); await fetch();
watch(props, async () => await fetch());
}); });
async function fetch() { async function fetch() {
const params = {}; store.url = props.url;
isLoading.value = true;
if (props.filter) params.filter = JSON.stringify(props.filter); const { data } = await arrayData.fetch({ append: false, updateRouter: false });
const { data } = await axios.get(props.url, { params });
entity.value = data;
emit('onFetch', data); emit('onFetch', data);
isLoading.value = false;
} }
watch(props, async () => {
entity.value = null;
fetch();
});
</script> </script>
<template> <template>
<div class="summary container"> <div class="summary container">
<QCard class="cardSummary"> <QCard class="cardSummary">
<SkeletonSummary v-if="!entity" /> <SkeletonSummary v-if="!entity || isLoading" />
<template v-if="entity"> <template v-if="entity && !isLoading">
<div class="summaryHeader bg-primary q-pa-sm text-weight-bolder"> <div class="summaryHeader bg-primary q-pa-sm text-weight-bolder">
<slot name="header-left"> <slot name="header-left">
<router-link <router-link

View File

@ -90,6 +90,7 @@ export default {
summary: 'Summary', summary: 'Summary',
basicData: 'Basic data', basicData: 'Basic data',
log: 'Logs', log: 'Logs',
parkingList: 'Parkings list',
}, },
}, },
errors: { errors: {
@ -672,7 +673,6 @@ export default {
summary: 'Summary', summary: 'Summary',
basicData: 'Basic Data', basicData: 'Basic Data',
log: 'Logs', log: 'Logs',
parkingList: 'Parking list',
}, },
list: { list: {
parking: 'Parking', parking: 'Parking',
@ -700,7 +700,6 @@ export default {
column: 'Column', column: 'Column',
pageTitles: { pageTitles: {
parking: 'Parking', parking: 'Parking',
parkingList: 'Parkings list',
}, },
searchBar: { searchBar: {
info: 'You can search by parking code', info: 'You can search by parking code',
@ -976,7 +975,7 @@ export default {
roadmap: 'Roadmap', roadmap: 'Roadmap',
summary: 'Summary', summary: 'Summary',
basicData: 'Basic Data', basicData: 'Basic Data',
stops: 'Stops' stops: 'Stops',
}, },
}, },
roadmap: { roadmap: {
@ -984,7 +983,7 @@ export default {
roadmap: 'Roadmap', roadmap: 'Roadmap',
summary: 'Summary', summary: 'Summary',
basicData: 'Basic Data', basicData: 'Basic Data',
stops: 'Stops' stops: 'Stops',
}, },
}, },
route: { route: {

View File

@ -90,6 +90,7 @@ export default {
summary: 'Resumen', summary: 'Resumen',
basicData: 'Datos básicos', basicData: 'Datos básicos',
log: 'Historial', log: 'Historial',
parkingList: 'Listado de parkings',
}, },
}, },
errors: { errors: {
@ -730,7 +731,6 @@ export default {
summary: 'Resumen', summary: 'Resumen',
basicData: 'Datos básicos', basicData: 'Datos básicos',
log: 'Historial', log: 'Historial',
parkingList: 'Listado de parkings',
}, },
list: { list: {
parking: 'Parking', parking: 'Parking',
@ -757,7 +757,6 @@ export default {
column: 'Columna', column: 'Columna',
pageTitles: { pageTitles: {
parking: 'Parking', parking: 'Parking',
parkingList: 'Listado de parkings',
}, },
searchBar: { searchBar: {
info: 'Puedes buscar por código de parking', info: 'Puedes buscar por código de parking',
@ -975,7 +974,7 @@ export default {
roadmap: 'Troncales', roadmap: 'Troncales',
summary: 'Resumen', summary: 'Resumen',
basicData: 'Datos básicos', basicData: 'Datos básicos',
stops: 'Paradas' stops: 'Paradas',
}, },
}, },
roadmap: { roadmap: {
@ -983,7 +982,7 @@ export default {
roadmap: 'Troncales', roadmap: 'Troncales',
summary: 'Resumen', summary: 'Resumen',
basicData: 'Datos básicos', basicData: 'Datos básicos',
stops: 'Paradas' stops: 'Paradas',
}, },
}, },
route: { route: {

View File

@ -199,7 +199,7 @@ function getLink(param) {
<template> <template>
<CardSummary <CardSummary
ref="summary" data-key="InvoiceInSummary"
:url="`InvoiceIns/${entityId}/summary`" :url="`InvoiceIns/${entityId}/summary`"
@on-fetch="(data) => setData(data)" @on-fetch="(data) => setData(data)"
> >

View File

@ -13,7 +13,7 @@ const route = useRoute();
const stateStore = useStateStore(); const stateStore = useStateStore();
const filter = { const filter = {
fields: ['id', 'sectorFk', 'code', 'pickingOrder'], fields: ['id', 'sectorFk', 'code', 'pickingOrder', 'row', 'column'],
include: [{ relation: 'sector', scope: { fields: ['id', 'description'] } }], include: [{ relation: 'sector', scope: { fields: ['id', 'description'] } }],
}; };
@ -22,7 +22,6 @@ const arrayData = useArrayData('Parking', {
filter, filter,
}); });
const { store } = arrayData; const { store } = arrayData;
onMounted(async () => await arrayData.fetch({ append: false })); onMounted(async () => await arrayData.fetch({ append: false }));
watch( watch(
() => route.params.id, () => route.params.id,

View File

@ -1,11 +1,12 @@
<script setup> <script setup>
import { computed } from 'vue'; import { computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router';
import { useArrayData } from 'src/composables/useArrayData'; import { useArrayData } from 'src/composables/useArrayData';
import CardDescriptor from 'components/ui/CardDescriptor.vue'; import CardDescriptor from 'components/ui/CardDescriptor.vue';
import VnLv from 'components/ui/VnLv.vue'; import VnLv from 'components/ui/VnLv.vue';
defineProps({ const props = defineProps({
id: { id: {
type: Number, type: Number,
required: false, required: false,
@ -14,16 +15,23 @@ defineProps({
}); });
const { t } = useI18n(); const { t } = useI18n();
const { params } = useRoute();
const entityId = computed(() => props.id || params.id);
const { store } = useArrayData('Parking'); const { store } = useArrayData('Parking');
const card = computed(() => store.data); const card = computed(() => store.data);
const filter = {
fields: ['id', 'sectorFk', 'code', 'pickingOrder', 'row', 'column'],
include: [{ relation: 'sector', scope: { fields: ['id', 'description'] } }],
};
</script> </script>
<template> <template>
<CardDescriptor <CardDescriptor
module="Parking" module="Parking"
data-key="Parking" data-key="Parking"
:url="`Parkings/${entityId}`"
:title="card?.code" :title="card?.code"
:subtitle="card?.id" :subtitle="card?.id"
:filter="filter"
> >
<template #body="{ entity: parking }"> <template #body="{ entity: parking }">
<VnLv :label="t('globals.code')" :value="parking.code" /> <VnLv :label="t('globals.code')" :value="parking.code" />

View File

@ -11,20 +11,19 @@ const $props = defineProps({
default: 0, default: 0,
}, },
}); });
const route = useRoute(); const { params } = useRoute();
const { t } = useI18n(); const { t } = useI18n();
const entityId = computed(() => $props.id || params.id);
const entityId = computed(() => $props.id || route.params.id);
const filter = { const filter = {
fields: ['sectorFk', 'code', 'pickingOrder', 'row', 'column'], fields: ['id', 'sectorFk', 'code', 'pickingOrder', 'row', 'column'],
include: [{ relation: 'sector', scope: { fields: ['id', 'description'] } }], include: [{ relation: 'sector', scope: { fields: ['id', 'description'] } }],
}; };
</script> </script>
<template> <template>
<div class="q-pa-md"> <div class="q-pa-md">
<CardSummary ref="summary" :url="`Parkings/${entityId}`" :filter="filter"> <CardSummary :url="`Parkings/${entityId}`" :filter="filter">
<template #header="{ entity: parking }">{{ parking.code }}</template> <template #header="{ entity: parking }">{{ parking.code }}</template>
<template #body="{ entity: parking }"> <template #body="{ entity: parking }">
<QCard class="vn-one"> <QCard class="vn-one">

View File

@ -12,7 +12,7 @@ import ParkingFilter from './ParkingFilter.vue';
import ParkingSummary from './Card/ParkingSummary.vue'; import ParkingSummary from './Card/ParkingSummary.vue';
const stateStore = useStateStore(); const stateStore = useStateStore();
const router = useRouter(); const { push } = useRouter();
const { t } = useI18n(); const { t } = useI18n();
const { viewSummary } = useSummaryDialog(); const { viewSummary } = useSummaryDialog();
@ -83,7 +83,7 @@ function exprBuilder(param, value) {
:key="row.id" :key="row.id"
:id="row.id" :id="row.id"
:title="row.code" :title="row.code"
@click="router.push({ path: `/parking/${row.id}` })" @click="push({ path: `/parking/${row.id}` })"
> >
<template #list-items> <template #list-items>
<VnLv label="Sector" :value="row.sector?.description" /> <VnLv label="Sector" :value="row.sector?.description" />

View File

@ -6,6 +6,7 @@ export default {
meta: { meta: {
title: 'parking', title: 'parking',
icon: 'garage_home', icon: 'garage_home',
moduleName: 'Parking',
}, },
component: RouterView, component: RouterView,
redirect: { name: 'ParkingCard' }, redirect: { name: 'ParkingCard' },

View File

@ -13,7 +13,7 @@ describe('ParkingList', () => {
cy.closeSideMenu(); cy.closeSideMenu();
}); });
it('should redirect on clicking a invoice', () => { it('should redirect on clicking a parking', () => {
cy.get(firstChipId) cy.get(firstChipId)
.invoke('text') .invoke('text')
.then((content) => { .then((content) => {