feat: refs #6564 enhance ticket advance functionality with confirmation actions and improved UI interactions
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2025-02-03 17:35:36 +01:00
parent fda024d6fe
commit 498e8c385e
1 changed files with 48 additions and 39 deletions

View File

@ -14,6 +14,7 @@ import { useState } from 'src/composables/useState';
import { toDateFormat } from 'src/filters/date.js'; import { toDateFormat } from 'src/filters/date.js';
import axios from 'axios'; import axios from 'axios';
import VnTable from 'src/components/VnTable/VnTable.vue'; import VnTable from 'src/components/VnTable/VnTable.vue';
import { QTable } from 'quasar';
const state = useState(); const state = useState();
const { t } = useI18n(); const { t } = useI18n();
@ -27,6 +28,16 @@ const selectedTickets = ref([]);
const vnTableRef = ref({}); const vnTableRef = ref({});
const originElRef = ref(null); const originElRef = ref(null);
const destinationElRef = ref(null); const destinationElRef = ref(null);
const actions = {
advance: {
title: t('advanceTickets.advanceTickets'),
cb: moveTicketsAdvance,
},
advanceWithoutNegative: {
title: t('advanceTickets.advanceTicketsWithoutNegatives'),
cb: splitTickets,
},
};
let today = Date.vnNew().toISOString(); let today = Date.vnNew().toISOString();
const tomorrow = new Date(today); const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1); tomorrow.setDate(tomorrow.getDate() + 1);
@ -250,7 +261,7 @@ const requestComponentUpdate = async (ticket, isWithoutNegatives) => {
return { query, params }; return { query, params };
}; };
const moveTicketsAdvance = async () => { async function moveTicketsAdvance() {
let ticketsToMove = []; let ticketsToMove = [];
for (const ticket of selectedTickets.value) { for (const ticket of selectedTickets.value) {
if (!ticket.id) { if (!ticket.id) {
@ -275,7 +286,7 @@ const moveTicketsAdvance = async () => {
vnTableRef.value.reload(); vnTableRef.value.reload();
selectedTickets.value = []; selectedTickets.value = [];
if (ticketsToMove.length) notify(t('advanceTickets.moveTicketSuccess'), 'positive'); if (ticketsToMove.length) notify(t('advanceTickets.moveTicketSuccess'), 'positive');
}; }
const progressLength = ref(0); const progressLength = ref(0);
const progressPercentage = computed(() => { const progressPercentage = computed(() => {
@ -293,12 +304,12 @@ const progressAdd = () => {
t('advanceTickets.moveTicketSuccess', { t('advanceTickets.moveTicketSuccess', {
ticketsNumber: progressLength.value - splitErrors.value.length, ticketsNumber: progressLength.value - splitErrors.value.length,
}), }),
'positive' 'positive',
); );
} }
}; };
const splitTickets = async () => { async function splitTickets() {
try { try {
showProgressDialog.value = true; showProgressDialog.value = true;
for (const ticket of selectedTickets.value) { for (const ticket of selectedTickets.value) {
@ -318,7 +329,7 @@ const splitTickets = async () => {
} finally { } finally {
vnTableRef.value.reload(); vnTableRef.value.reload();
} }
}; }
const resetProgressData = () => { const resetProgressData = () => {
if (cancelProgress.value) cancelProgress.value = false; if (cancelProgress.value) cancelProgress.value = false;
@ -334,20 +345,30 @@ const handleCloseProgressDialog = () => {
const handleCancelProgress = () => (cancelProgress.value = true); const handleCancelProgress = () => (cancelProgress.value = true);
const getMessage = (type) => { const confirmAction = (action) => {
const locale = openConfirmationModal(actions[action].title, false, actions[action].cb, null, {
type === 'advance' ? 'advanceTitleSubtitle' : 'advanceWithoutNegativeSubtitle'; component: QTable,
props: {
let message = t(`advanceTickets.${locale}`, { columns: [
selectedTickets: selectedTickets.value.length, {
align: 'center',
label: t('advanceTickets.destination'),
name: 'id',
field: (row) => row.id,
},
{
align: 'center',
label: t('advanceTickets.origin'),
name: 'futureId',
field: (row) => row.futureId,
},
],
rows: selectedTickets.value,
class: 'full-width',
dense: true,
flat: true,
},
}); });
// message += '<ul>';
// for (const ticket of selectedTickets.value) {
// message += `<li>${ticket.futureId} << ${ticket.id}</li>`;
// }
// message += '</ul>';
return message;
}; };
watch( watch(
@ -369,16 +390,16 @@ watch(
originElRef.value.setAttribute('colspan', '9'); originElRef.value.setAttribute('colspan', '9');
destinationElRef.value.textContent = `${t( destinationElRef.value.textContent = `${t(
'advanceTickets.destination' 'advanceTickets.destination',
)} ${toDateFormat(vnTableRef.value.params.dateToAdvance)}`; )} ${toDateFormat(vnTableRef.value.params.dateToAdvance)}`;
originElRef.value.textContent = `${t('advanceTickets.origin')} ${toDateFormat( originElRef.value.textContent = `${t('advanceTickets.origin')} ${toDateFormat(
vnTableRef.value.params.dateFuture vnTableRef.value.params.dateFuture,
)}`; )}`;
newRow.append(destinationElRef.value, originElRef.value); newRow.append(destinationElRef.value, originElRef.value);
head.insertBefore(newRow, firstRow); head.insertBefore(newRow, firstRow);
}, },
{ once: true, inmmediate: true } { once: true, inmmediate: true },
); );
watch( watch(
@ -386,14 +407,14 @@ watch(
() => { () => {
if (originElRef.value && destinationElRef.value) { if (originElRef.value && destinationElRef.value) {
destinationElRef.value.textContent = `${t( destinationElRef.value.textContent = `${t(
'advanceTickets.destination' 'advanceTickets.destination',
)} ${toDateFormat(vnTableRef.value.params.dateToAdvance)}`; )} ${toDateFormat(vnTableRef.value.params.dateToAdvance)}`;
originElRef.value.textContent = `${t('advanceTickets.origin')} ${toDateFormat( originElRef.value.textContent = `${t('advanceTickets.origin')} ${toDateFormat(
vnTableRef.value.params.dateFuture vnTableRef.value.params.dateFuture,
)}`; )}`;
} }
}, },
{ deep: true } { deep: true },
); );
</script> </script>
<template> <template>
@ -423,13 +444,7 @@ watch(
color="primary" color="primary"
class="q-mr-sm" class="q-mr-sm"
:disable="!selectedTickets.length" :disable="!selectedTickets.length"
@click.stop=" @click.stop="confirmAction('advance')"
openConfirmationModal(
t('advanceTickets.advanceTickets'),
getMessage('advance'),
moveTicketsAdvance
)
"
> >
<QTooltip> <QTooltip>
{{ t('advanceTickets.advanceTickets') }} {{ t('advanceTickets.advanceTickets') }}
@ -439,13 +454,7 @@ watch(
icon="alt_route" icon="alt_route"
color="primary" color="primary"
:disable="!selectedTickets.length" :disable="!selectedTickets.length"
@click.stop=" @click.stop="confirmAction('advanceWithoutNegative')"
openConfirmationModal(
t('advanceTickets.advanceWithoutNegativeTitle'),
getMessage('split'),
splitTickets
)
"
> >
<QTooltip> <QTooltip>
{{ t('advanceTickets.advanceTicketsWithoutNegatives') }} {{ t('advanceTickets.advanceTicketsWithoutNegatives') }}
@ -474,7 +483,7 @@ watch(
}" }"
v-model:selected="selectedTickets" v-model:selected="selectedTickets"
:pagination="{ rowsPerPage: 0 }" :pagination="{ rowsPerPage: 0 }"
:no-data-label="t('globals.noResults')" :no-data-label="$t('globals.noResults')"
:right-search="false" :right-search="false"
auto-load auto-load
:disable-option="{ card: true }" :disable-option="{ card: true }"