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); try {
redirectToCreateView(stringifiedZoneData); const { data } = await axios.post(`Zones/${zoneId}/clone`, {
}; shipped: $props.zone.value.shipped,
});
const cloneZoneWithEntries = () => { clonedZoneId = data;
try { } catch (e) {
axios.post(`Zones/${$props.travel.id}/cloneWithEntries`); opts.message = t('It was not able to clone the zone');
notify('globals.dataSaved', 'positive'); opts.type = 'negative';
} catch (err) { } finally {
console.err('Error cloning travel with entries'); notify(opts);
}
}; if (clonedZoneId) push({ name: 'ZoneSummary', params: { id: clonedZoneId } });
}
const isBuyer = computed(() => { },
return role.hasAny(['buyer']); remove: async () => {
}); try {
await axios.post(`Zones/${zoneId}/setDeleted`);
const openDeleteEntryDialog = (id) => {
quasar notify({ message: t('Zone deleted'), type: 'positive' });
.dialog({ notify({
component: VnConfirm, message: t('You can undo this action within the first hour'),
componentProps: { icon: 'info',
title: t('The travel will be deleted'), });
message: t('Do you want to delete this travel?'),
}, push({ name: 'ZoneList' });
}) } catch (e) {
.onOk(async () => { notify({ message: e.message, type: 'negative' });
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');
}
}; };
function openConfirmDialog(callback) {
dialog({
component: VnConfirm,
componentProps: {
promise: actions[callback],
},
});
}
</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>