0
0
Fork 0

Merge branch 'dev' into 5926_pda_worker_docuware

This commit is contained in:
Javier Segarra 2024-05-21 11:15:39 +02:00
commit 2c2f2b3b0d
2 changed files with 207 additions and 164 deletions

View File

@ -1,70 +1,63 @@
<script setup> <script setup>
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { onMounted, ref, computed } from 'vue'; import { ref, computed } from 'vue';
import FetchData from 'components/FetchData.vue';
import FormModel from 'components/FormModel.vue'; import axios from 'axios';
import VnSelect from 'src/components/common/VnSelect.vue'; import useNotify from 'src/composables/useNotify.js';
import useNotify from 'src/composables/useNotify.js'; import FetchData from 'components/FetchData.vue';
import axios from 'axios'; import FormModelPopup from 'src/components/FormModelPopup.vue';
import { useRole } from 'src/composables/useRole'; import { useVnConfirm } from 'composables/useVnConfirm';
import { useVnConfirm } from 'src/composables/useVnConfirm';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import VnRow from 'components/ui/VnRow.vue';
import VnSelect from 'src/components/common/VnSelect.vue';
import VnInput from 'src/components/common/VnInput.vue';
const route = useRoute();
const { t } = useI18n(); const { t } = useI18n();
const { notify } = useNotify(); const { notify } = useNotify();
const { hasAny } = useRole();
const paginate = ref();
const downloadDocuware = ref(true); const downloadDocuware = ref(true);
const sendToTablet = ref(true); const sendToTablet = ref(true);
const fetchCurrentDeviceRef = ref(null); const dialog = ref();
const docuwarePDARef = ref(null); const docuwarePDARef = ref(null);
const deviceProductionsFilter = { const route = useRoute();
fields: ['id', 'serialNumber', 'modelFk'], const { openConfirmationModal } = useVnConfirm();
where: { stateFk: 'idle' }, const routeId = computed(() => route.params.id);
order: 'id',
};
const deviceProductionsOptions = ref([]);
const newPDA = ref({});
const currentPDA = ref(null);
const isAllowedToEdit = computed(() => hasAny(['hr', 'productionAssi'])); const initialData = computed(() => {
return {
userFk: routeId.value,
deviceProductionFk: null,
simSerialNumber: null,
};
});
const setCurrentPDA = async (data) => { const deallocatePDA = async (deviceProductionFk) => {
currentPDA.value = data;
currentPDA.value.description = `ID: ${currentPDA.value.deviceProductionFk} ${t(
'worker.pda.model'
)}: ${currentPDA.value.deviceProduction.modelFk} ${t('worker.pda.serialNumber')}: ${
currentPDA.value.deviceProduction.serialNumber
}`;
await axios.get(
`Workers/${route.params.id}/${currentPDA.value.deviceProductionFk}/isPDASigned`
);
data.pda = null;
currentPDA.value = null;
};
const deallocatePDA = async (data) => {
try { try {
await axios.post(`Workers/${route.params.id}/deallocatePDA`, { await axios.post(`Workers/${route.params.id}/deallocatePDA`, {
pda: currentPDA.value.deviceProductionFk, pda: deviceProductionFk,
}); });
data.pda = null;
currentPDA.value = null;
await fetchCurrentDeviceRef.value.fetch();
notify(t('PDA deallocated'), 'positive'); notify(t('PDA deallocated'), 'positive');
} catch (err) { } catch (err) {
console.error('Error deallocating PDA'); console.error('Error deallocating PDA');
} }
paginate.value.fetch();
}; };
const { openConfirmationModal } = useVnConfirm();
function reloadData() {
initialData.value.deviceProductionFk = null;
initialData.value.simSerialNumber = null;
paginate.value.fetch();
}
const handleSendToTablet = async () => { const handleSendToTablet = async () => {
try { try {
await axios.post(`Docuwares/upload`, { await axios.post(`Docuwares/upload`, {
fileCabinet: 'hr', fileCabinet: 'hr',
worker: route.params.id, worker: route.params.id,
pda: currentPDA.value.deviceProductionFk, // pda: currentPDA.value.deviceProductionFk,
}); });
notify(t('PDA Signed'), 'positive'); notify(t('PDA Signed'), 'positive');
} catch (err) { } catch (err) {
@ -75,136 +68,162 @@ const handleDownloadDocuware = async () => {};
</script> </script>
<template> <template>
<FetchData <QPage class="column items-center q-pa-md centerCard">
url="DeviceProductions" <FetchData
:filter="deviceProductionsFilter" url="workers/getAvailablePda"
auto-load @on-fetch="(data) => (deviceProductions = data)"
@on-fetch="(data) => (deviceProductionsOptions = data)" auto-load
/> />
<FetchData <VnPaginate
ref="fetchCurrentDeviceRef" ref="paginate"
@on-fetch=" data-key="WorkerPda"
(data) => { url="DeviceProductionUsers"
downloadDocuware = true; :filter="{ where: { userFk: routeId } }"
sendToTablet = true; order="id"
}
"
/>
<FetchData
ref="docuwarePDARef"
url="DeviceProductionUsers"
:filter="{
where: { userFk: route.params.id },
include: { relation: 'deviceProduction' },
}"
auto-load
@on-fetch="(data) => setCurrentPDA(data[0])"
/>
<QPage class="column items-center q-pa-md">
<FormModel
url="DeviceProductionUsers"
:url-create="`Workers/${route.params.id}/allocatePDA`"
model="DeviceProductionUser"
:form-initial-data="newPDA"
auto-load auto-load
:default-buttons="{ save: { label: 'globals.assign', color: 'primary' } }"
@on-data-saved="(_, data) => setCurrentPDA(data)"
> >
<!-- <template #moreActions> <template #body="{ rows }">
<QBtn <QCard
:label="t('Download')" flat
class="q-mt-sm" bordered
@click.stop="downloadDocueare()" :key="row.id"
type="submit" v-for="row of rows"
color="primary" class="card q-pt-xs q-mb-sm"
/>
</template> -->
<template #form="{ data }">
<QField
v-if="currentPDA && currentPDA.description"
:label="t('worker.pda.currentPDA')"
:model-value="currentPDA.description"
:editable="false"
class="full-width"
> >
<template #control> <QItem>
<div tabindex="0"> <QItemSection side-left>
{{ currentPDA.description }} <VnRow>
</div> <QField
</template> :label="t('worker.pda.currentPDA')"
<template v-if="isAllowedToEdit" #append> :model-value="row?.deviceProductionFk"
<QIcon disable
name="delete" >
size="md" <template #control>
class="cursor-pointer" <div tabindex="0" style="padding: none">
color="primary" <span>Id: </span>
@click="deallocatePDA(data)" <span>
> {{ row?.deviceProductionFk }}&nbsp;
<QTooltip> </span>
{{ t('worker.pda.removePDA') }} <span>{{ t('Model') }}: </span>
</QTooltip> <span>
</QIcon> {{ row?.deviceProduction?.modelFk }}&nbsp;
<QIcon </span>
v-if="downloadDocuware" <span>{{ t('SIM serial number') }}: </span>
name="cloud_download" <span>
size="md" {{
class="cursor-pointer" row?.deviceProduction?.serialNumber
color="primary" }}&nbsp;
@click="handleDownloadDocuware(data)" </span>
> </div>
<QTooltip> </template>
{{ t('worker.pda.removePDA') }} </QField>
</QTooltip> <QField
</QIcon> :label="t('Current SIM')"
<QIcon :model-value="row?.simSerialNumber"
v-if="sendToTablet" disable
name="vn:client" >
size="md" <template #control>
class="cursor-pointer" <div tabindex="0">{{ row?.simSerialNumber }}</div>
color="primary" </template>
@click=" </QField>
openConfirmationModal( </VnRow>
t('Are you sure you want to send it?'), </QItemSection>
t('Sign PDA'), <QItemSection side>
handleSendToTablet <QIcon
) name="delete"
" size="sm"
> class="cursor-pointer"
<QTooltip> color="primary"
{{ t('worker.pda.removePDA') }} @click="
</QTooltip> openConfirmationModal(
</QIcon> t(`Remove PDA`),
</template> t('Do you want to remove this PDA?'),
</QField> () => deallocatePDA(row.deviceProductionFk)
)
<VnSelect "
v-else >
:label="t('worker.pda.newPDA')" <QTooltip>
v-model="data.pda" {{ t('worker.pda.removePDA') }}
:options="deviceProductionsOptions" </QTooltip>
option-label="serialNumber" </QIcon>
option-value="id" </QItemSection>
hide-selected </QItem>
:disable="!isAllowedToEdit" </QCard>
>
<template #option="scope">
<QItem v-bind="scope.itemProps">
<QItemSection>
<QItemLabel>ID: {{ scope.opt?.id }}</QItemLabel>
<QItemLabel caption>
{{ scope.opt?.modelFk }},
{{ scope.opt?.serialNumber }}
</QItemLabel>
</QItemSection>
</QItem>
</template>
</VnSelect>
</template> </template>
</FormModel> </VnPaginate>
<QPageSticky :offset="[18, 18]">
<QBtn @click.stop="dialog.show()" color="primary" fab icon="add">
<QDialog ref="dialog">
<FormModelPopup
:title="t('Add new device')"
url-create="DeviceProductionUsers"
model="DeviceProductionUser"
:form-initial-data="initialData"
@on-data-saved="reloadData()"
>
<template #form-inputs="{ data }">
<VnRow class="row q-gutter-md q-mb-md">
<VnSelect
:label="t('worker.pda.newPDA')"
v-model="data.deviceProductionFk"
:options="deviceProductions"
option-label="id"
option-value="id"
id="deviceProductionFk"
hide-selected
>
<template #option="scope">
<QItem v-bind="scope.itemProps">
<QItemSection>
<QItemLabel
>ID: {{ scope.opt?.id }}</QItemLabel
>
<QItemLabel caption>
{{ scope.opt?.modelFk }},
{{ scope.opt?.serialNumber }}
</QItemLabel>
</QItemSection>
</QItem>
</template>
</VnSelect>
<VnInput
v-model="data.simSerialNumber"
:label="t('SIM serial number')"
id="simSerialNumber"
use-input
/>
</VnRow>
</template>
</FormModelPopup>
</QDialog>
</QBtn>
<QTooltip>
{{ t('globals.new') }}
</QTooltip>
</QPageSticky>
</QPage> </QPage>
</template> </template>
<style lang="scss" scoped>
.centerCard {
padding: 5%;
width: 100%;
max-width: 70%;
margin: 0 auto;
}
.label {
color: red;
}
.q-field {
height: 65px;
}
</style>
<i18n> <i18n>
es: es:
Remove PDA: Eliminar PDA
Do you want to remove this PDA?: ¿Desea eliminar este PDA?
PDA deallocated: PDA desasignada PDA deallocated: PDA desasignada
SIM serial number: Número de serie de la SIM
Model: Modelo
This PDA is already assigned to another user: Este PDA ya está asignado a otro usuario
Add new device: Añadir nuevo dispositivo
</i18n> </i18n>

View File

@ -0,0 +1,24 @@
describe('WorkerPda', () => {
const deviceProductionField =
'.vn-row > .q-field > .q-field__inner > .q-field__control > .q-field__control-container';
beforeEach(() => {
cy.viewport(1920, 1080);
cy.login('developer');
cy.visit(`/#/worker/1110/pda`);
});
it('assign pda', () => {
cy.get('.q-page-sticky > div > .q-btn > .q-btn__content > .q-icon').click();
cy.get(deviceProductionField).type('{downArrow}{enter}');
cy.get('.vn-row > #simSerialNumber').type('123{enter}');
cy.get('.q-notification__message').should('have.text', 'Data created');
});
it('delete pda', () => {
cy.get('.q-card > .q-item > .q-item__section--side > .q-icon').click();
cy.get(
'.q-card__actions > .q-btn--unelevated > .q-btn__content > .block'
).click();
cy.get('.q-notification__message').should('have.text', 'PDA deallocated');
});
});