0
0
Fork 0

refactor: order functions

This commit is contained in:
Alex Moreno 2024-09-11 11:10:38 +02:00
parent e83715ecbf
commit 68729d2e77
1 changed files with 51 additions and 62 deletions

View File

@ -50,59 +50,6 @@ function reloadData() {
paginate.value.fetch(); paginate.value.fetch();
} }
const handleSendToTablet = async (row) => {
try {
if (isProduction(false)) {
const { deviceProductionFk } = row;
await axios.post(`Docuwares/upload`, {
fileCabinet: FILECABINET_ID,
ids: [deviceProductionFk],
});
}
notify(t('PDF sended to signed'), 'positive');
row.isDocuware = true;
} catch (err) {
console.error('Error sending to sign');
}
};
function checkFileDocuware({ deviceProductionFk }, signed) {
return axios.post(`Docuwares/${deviceProductionFk}/checkFile`, {
fileCabinet: FILECABINET_ID,
signed,
});
}
const handleRefreshDocuware = async (row) => {
try {
if (isProduction()) {
await checkFileDocuware(row, true);
}
notify(t('PDA Signed'), 'positive');
row.isSigned = true;
} catch (err) {
console.error('Error refreshing docuware call');
}
};
const handleDownloadDocuware = async (row) => {
try {
if (isProduction(false)) {
const { deviceProductionFk } = row;
await axios.post(`Docuwares/download`, {
fileCabinet: FILECABINET_ID,
ids: [deviceProductionFk],
});
}
notify(t('PDF downloaded'), 'positive');
} catch (err) {
console.error('Error downloading docuware');
}
};
function handlePromiseDocuware(promise, deviceProductions) {
const id = +promise.config.url.match(/\d+/)[0];
const deviceProduction = deviceProductions.find(
({ deviceProductionFk }) => deviceProductionFk === id
);
return deviceProduction;
}
async function fetchDocuware(deviceProductions) { async function fetchDocuware(deviceProductions) {
const promisesIsDocuware = await Promise.allSettled( const promisesIsDocuware = await Promise.allSettled(
deviceProductions.map((device) => checkFileDocuware(device, false)) deviceProductions.map((device) => checkFileDocuware(device, false))
@ -128,6 +75,50 @@ async function fetchDocuware(deviceProductions) {
loadingDocuware.value = false; loadingDocuware.value = false;
} }
function checkFileDocuware({ deviceProductionFk }, signed) {
return axios.post(`Docuwares/${deviceProductionFk}/checkFile`, {
fileCabinet: FILECABINET_ID,
signed,
});
}
async function sendToTablet(row) {
if (isProduction(false)) {
const { deviceProductionFk } = row;
await axios.post(`Docuwares/upload`, {
fileCabinet: FILECABINET_ID,
ids: [deviceProductionFk],
});
}
notify(t('PDF sended to signed'), 'positive');
row.isDocuware = true;
}
const refreshDocuware = async (row) => {
if (isProduction()) {
await checkFileDocuware(row, true);
}
notify(t('PDA Signed'), 'positive');
row.isSigned = true;
};
const downloadDocuware = async (row) => {
if (isProduction(false)) {
const { deviceProductionFk } = row;
await axios.post(`Docuwares/download`, {
fileCabinet: FILECABINET_ID,
ids: [deviceProductionFk],
});
}
notify(t('PDF downloaded'), 'positive');
};
function handlePromiseDocuware(promise, deviceProductions) {
const id = +promise.config.url.match(/\d+/)[0];
const deviceProduction = deviceProductions.find(
({ deviceProductionFk }) => deviceProductionFk === id
);
return deviceProduction;
}
</script> </script>
<template> <template>
@ -197,8 +188,7 @@ async function fetchDocuware(deviceProductions) {
<QBtn <QBtn
:loading="loadingDocuware" :loading="loadingDocuware"
v-if="!row.isDocuware" icon="send"
icon="vn:client"
flat flat
class="btn-delete" class="btn-delete"
color="primary" color="primary"
@ -207,7 +197,7 @@ async function fetchDocuware(deviceProductions) {
t('Sign PDA'), t('Sign PDA'),
t('Are you sure you want to send it?'), t('Are you sure you want to send it?'),
() => handleSendToTablet(row) () => sendToTablet(row)
) )
" "
> >
@ -218,24 +208,23 @@ async function fetchDocuware(deviceProductions) {
<QBtn <QBtn
:loading="loadingDocuware" :loading="loadingDocuware"
v-if="row.isDocuware && !row.isSigned"
icon="refresh" icon="refresh"
flat flat
class="btn-delete" class="btn-delete"
color="primary" color="primary"
@click="handleRefreshDocuware(row)" @click="refreshDocuware(row)"
> >
<QTooltip> <QTooltip>
{{ t('worker.pda.refresh') }} {{ t('worker.pda.refresh') }}
</QTooltip> </QBtn </QTooltip>
><QBtn </QBtn>
<QBtn
:loading="loadingDocuware" :loading="loadingDocuware"
v-if="row.isSigned"
icon="cloud_download" icon="cloud_download"
flat flat
class="btn-delete" class="btn-delete"
color="primary" color="primary"
@click="handleDownloadDocuware(row)" @click="downloadDocuware(row)"
> >
<QTooltip> <QTooltip>
{{ t('worker.pda.download') }} {{ t('worker.pda.download') }}