0
0
Fork 0

perf: ZoneDescriptor

This commit is contained in:
Javier Segarra 2024-04-30 12:06:24 +02:00
parent 9563a1a6ed
commit a512f094d6
2 changed files with 72 additions and 87 deletions

View File

@ -57,7 +57,7 @@ function extractHour(dateTime) {
:subtitle="data.subtitle" :subtitle="data.subtitle"
:filter="filter" :filter="filter"
@on-fetch="setData" @on-fetch="setData"
data-key="travelData" data-key="zoneData"
> >
<template #header-extra-action> <template #header-extra-action>
<QBtn <QBtn
@ -75,14 +75,14 @@ function extractHour(dateTime) {
</QTooltip> </QTooltip>
</QBtn> </QBtn>
</template> </template>
<template #menu="{ entity }"> <!-- <template #menu="{ entity }">
<ZoneDescriptorMenuItems :zone="entity" /> <ZoneDescriptorMenuItems :zone="entity" />
</template> </template> -->
<template #body="{ entity }"> <template #body="{ entity }">
{{ console.log('entity', entity) }} {{ console.log('entity', entity) }}
<VnLv :label="t('Agency')" :value="entity.agencyMode.name" /> <VnLv :label="t('Agency')" :value="entity.agencyMode.name" />
<VnLv :label="t('Closing hour')" :value="extractHour(entity.hour)" /> <VnLv :label="t('Closing hour')" :value="extractHour(entity.hour)" />
<VnLv :label="t('traveling days')" :value="entity.travelingDays" /> <VnLv :label="t('zoneing days')" :value="entity.zoneingDays" />
<VnLv :label="t('Price')" :value="entity.price" /> <VnLv :label="t('Price')" :value="entity.price" />
<VnLv :label="t('Bonus')" :value="entity.bonus" /> <VnLv :label="t('Bonus')" :value="entity.bonus" />
</template> </template>
@ -92,12 +92,12 @@ function extractHour(dateTime) {
<i18n> <i18n>
es: es:
Summary: Detalles Summary: Detalles
The travel will be deleted: El envío será eliminado The zone will be deleted: El envío será eliminado
Do you want to delete this travel?: ¿Quieres eliminar este envío? Do you want to delete this zone?: ¿Quieres eliminar este envío?
All travels with current agency: Todos los envíos con la agencia actual All zones with current agency: Todos los envíos con la agencia actual
Agency: Agencia Agency: Agencia
Closing hour: Hora de cierre Closing hour: Hora de cierre
traveling days: Días de viaje zoneing days: Días de viaje
Price: Precio Price: Precio
Bonus: Bonificación Bonus: Bonificación
</i18n> </i18n>

View File

@ -1,108 +1,93 @@
<script setup> <script setup>
import { computed } from 'vue';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
const { dialog, notify } = useQuasar();
import VnConfirm from 'components/ui/VnConfirm.vue'; import VnConfirm from 'components/ui/VnConfirm.vue';
import axios from 'axios'; import axios from 'axios';
import useNotify from 'src/composables/useNotify.js';
import { useRole } from 'src/composables/useRole';
const $props = defineProps({ const $props = defineProps({
travel: { zone: {
type: Object, type: Object,
default: () => {}, default: () => {},
}, },
}); });
const { t } = useI18n(); const { t } = useI18n();
const router = useRouter(); const { push, currentRoute } = useRouter();
const quasar = useQuasar(); const zoneId = currentRoute.value.params.id;
const { notify } = useNotify();
const role = useRole();
const redirectToCreateView = (queryParams) => { const actions = {
router.push({ name: 'ZoneCreate', query: { travelData: queryParams } }); clone: async () => {
}; const opts = { message: t('Zone cloned'), type: 'positive' };
let clonedZoneId;
const cloneZone = () => {
const stringifiedZoneData = JSON.stringify($props.travel);
redirectToCreateView(stringifiedZoneData);
};
const cloneZoneWithEntries = () => {
try { try {
axios.post(`Zones/${$props.travel.id}/cloneWithEntries`); const { data } = await axios.post(`Zones/${zoneId}/clone`, {
notify('globals.dataSaved', 'positive'); shipped: $props.zone.value.shipped,
} catch (err) { });
console.err('Error cloning travel with entries'); clonedZoneId = data;
} } catch (e) {
}; opts.message = t('It was not able to clone the zone');
opts.type = 'negative';
} finally {
notify(opts);
const isBuyer = computed(() => { if (clonedZoneId) push({ name: 'ZoneSummary', params: { id: clonedZoneId } });
return role.hasAny(['buyer']); }
},
remove: async () => {
try {
await axios.post(`Zones/${zoneId}/setDeleted`);
notify({ message: t('Zone deleted'), type: 'positive' });
notify({
message: t('You can undo this action within the first hour'),
icon: 'info',
}); });
const openDeleteEntryDialog = (id) => { push({ name: 'ZoneList' });
quasar } catch (e) {
.dialog({ notify({ message: e.message, type: 'negative' });
}
},
};
function openConfirmDialog(callback) {
dialog({
component: VnConfirm, component: VnConfirm,
componentProps: { componentProps: {
title: t('The travel will be deleted'), promise: actions[callback],
message: t('Do you want to delete this travel?'),
}, },
})
.onOk(async () => {
await deleteZone(id);
}); });
};
const deleteZone = async (id) => {
try {
await axios.delete(`Zones/${id}`);
router.push({ name: 'ZoneList' });
notify('globals.dataDeleted', 'positive');
} catch (err) {
console.error('Error deleting travel');
} }
};
</script> </script>
<template> <template>
<QItem v-ripple clickable @click="cloneZone(travel)"> <QItem @click="openConfirmDialog('clone')" v-ripple clickable>
<QItemSection>{{ t('travel.summary.cloneShipping') }}</QItemSection> <QItemSection avatar>
</QItem> <QIcon name="content_copy" />
<QItem v-ripple clickable @click="cloneZoneWithEntries()">
<QItemSection>
{{ t('travel.summary.CloneZoneAndEntries') }}
</QItemSection> </QItemSection>
<QItemSection>{{ t('To clone zone') }}</QItemSection>
</QItem> </QItem>
<QItem <QItem @click="openConfirmDialog('remove')" v-ripple clickable>
v-if="isBuyer && travel.totalEntries === 0" <QItemSection avatar>
v-ripple <QIcon name="delete" />
clickable
@click="openDeleteEntryDialog(travel.id)"
>
<QItemSection>
{{ t('travel.summary.deleteZone') }}
</QItemSection>
</QItem>
<QItem v-ripple clickable>
<QItemSection>
<RouterLink
:to="{ name: 'EntryCreate', query: { travelFk: travel.id } }"
class="color-vn-text"
>
{{ t('travel.summary.AddEntry') }}
</RouterLink>
</QItemSection> </QItemSection>
<QItemSection>{{ t('deleteOrder') }}</QItemSection>
</QItem> </QItem>
</template> </template>
<i18n> <i18n>
en:
deleteOrder: Delete order
confirmDeletion: Confirm deletion
confirmDeletionMessage: Are you sure you want to delete this order?
es: es:
The travel will be deleted: El envío será eliminado To clone zone: Clonar zone
Do you want to delete this travel?: ¿Quieres eliminar este envío? deleteOrder: Eliminar pedido
confirmDeletion: Confirmar eliminación
confirmDeletionMessage: Seguro que quieres eliminar este pedido?
</i18n> </i18n>