forked from verdnatura/salix-front
refactor: order functions
This commit is contained in:
parent
e83715ecbf
commit
68729d2e77
|
@ -50,59 +50,6 @@ function reloadData() {
|
|||
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) {
|
||||
const promisesIsDocuware = await Promise.allSettled(
|
||||
deviceProductions.map((device) => checkFileDocuware(device, false))
|
||||
|
@ -128,6 +75,50 @@ async function fetchDocuware(deviceProductions) {
|
|||
|
||||
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>
|
||||
|
||||
<template>
|
||||
|
@ -197,8 +188,7 @@ async function fetchDocuware(deviceProductions) {
|
|||
|
||||
<QBtn
|
||||
:loading="loadingDocuware"
|
||||
v-if="!row.isDocuware"
|
||||
icon="vn:client"
|
||||
icon="send"
|
||||
flat
|
||||
class="btn-delete"
|
||||
color="primary"
|
||||
|
@ -207,7 +197,7 @@ async function fetchDocuware(deviceProductions) {
|
|||
t('Sign PDA'),
|
||||
t('Are you sure you want to send it?'),
|
||||
|
||||
() => handleSendToTablet(row)
|
||||
() => sendToTablet(row)
|
||||
)
|
||||
"
|
||||
>
|
||||
|
@ -218,24 +208,23 @@ async function fetchDocuware(deviceProductions) {
|
|||
|
||||
<QBtn
|
||||
:loading="loadingDocuware"
|
||||
v-if="row.isDocuware && !row.isSigned"
|
||||
icon="refresh"
|
||||
flat
|
||||
class="btn-delete"
|
||||
color="primary"
|
||||
@click="handleRefreshDocuware(row)"
|
||||
@click="refreshDocuware(row)"
|
||||
>
|
||||
<QTooltip>
|
||||
{{ t('worker.pda.refresh') }}
|
||||
</QTooltip> </QBtn
|
||||
><QBtn
|
||||
</QTooltip>
|
||||
</QBtn>
|
||||
<QBtn
|
||||
:loading="loadingDocuware"
|
||||
v-if="row.isSigned"
|
||||
icon="cloud_download"
|
||||
flat
|
||||
class="btn-delete"
|
||||
color="primary"
|
||||
@click="handleDownloadDocuware(row)"
|
||||
@click="downloadDocuware(row)"
|
||||
>
|
||||
<QTooltip>
|
||||
{{ t('worker.pda.download') }}
|
||||
|
|
Loading…
Reference in New Issue