7525-devToTest #419

Merged
alexm merged 177 commits from 7525-devToTest into test 2024-06-04 08:06:27 +00:00
6 changed files with 207 additions and 145 deletions
Showing only changes of commit e2b72f132c - Show all commits

View File

@ -1,6 +1,6 @@
{ {
"name": "salix-front", "name": "salix-front",
"version": "24.22.0", "version": "24.24.0",
"description": "Salix frontend", "description": "Salix frontend",
"productName": "Salix", "productName": "Salix",
"author": "Verdnatura", "author": "Verdnatura",

View File

@ -35,7 +35,7 @@ const $props = defineProps({
downloadModel: { downloadModel: {
type: String, type: String,
required: false, required: false,
default: null, default: undefined,
}, },
defaultDmsCode: { defaultDmsCode: {
type: String, type: String,

View File

@ -170,23 +170,6 @@ watch([year, businessFk], () => refreshData());
ref="WorkerFreelanceRef" ref="WorkerFreelanceRef"
auto-load auto-load
/> />
<template v-if="stateStore.isHeaderMounted()">
<Teleport to="#actions-append">
<div class="row q-gutter-x-sm">
<QBtn
flat
@click="stateStore.toggleRightDrawer()"
round
dense
icon="menu"
>
<QTooltip bottom anchor="bottom right">
{{ t('globals.collapseMenu') }}
</QTooltip>
</QBtn>
</div>
</Teleport>
</template>
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above> <QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above>
<QScrollArea class="fit text-grey-8"> <QScrollArea class="fit text-grey-8">
<WorkerCalendarFilter <WorkerCalendarFilter

View File

@ -1,140 +1,212 @@
<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 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 fetchCurrentDeviceRef = ref(null); const paginate = ref();
const deviceProductionsFilter = { const dialog = ref();
fields: ['id', 'serialNumber', 'modelFk'], const route = useRoute();
where: { stateFk: 'idle' }, const { openConfirmationModal } = useVnConfirm();
order: 'id', const routeId = computed(() => route.params.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 = (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
}`;
};
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();
}; };
onMounted(async () => await fetchCurrentDeviceRef.value.fetch()); function reloadData() {
initialData.value.deviceProductionFk = null;
initialData.value.simSerialNumber = null;
paginate.value.fetch();
}
</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"
url="DeviceProductionUsers" data-key="WorkerPda"
:filter="{ url="DeviceProductionUsers"
where: { userFk: route.params.id }, :filter="{ where: { userFk: routeId } }"
include: { relation: 'deviceProduction' }, order="id"
}"
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 #form="{ data }"> <template #body="{ rows }">
<QField <QCard
v-if="currentPDA && currentPDA.description" flat
:label="t('worker.pda.currentPDA')" bordered
:model-value="currentPDA.description" :key="row.id"
:editable="false" v-for="row of rows"
class="full-width" class="card q-pt-xs q-mb-sm"
> >
<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="sm" <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;
</template> </span>
</QField> <span>{{ t('SIM serial number') }}: </span>
<span>
<VnSelect {{
v-else row?.deviceProduction?.serialNumber
:label="t('worker.pda.newPDA')" }}&nbsp;
v-model="data.pda" </span>
:options="deviceProductionsOptions" </div>
option-label="serialNumber" </template>
option-value="id" </QField>
hide-selected <QField
:disable="!isAllowedToEdit" :label="t('Current SIM')"
> :model-value="row?.simSerialNumber"
<template #option="scope"> disable
<QItem v-bind="scope.itemProps"> >
<QItemSection> <template #control>
<QItemLabel>ID: {{ scope.opt?.id }}</QItemLabel> <div tabindex="0">{{ row?.simSerialNumber }}</div>
<QItemLabel caption> </template>
{{ scope.opt?.modelFk }}, </QField>
{{ scope.opt?.serialNumber }} </VnRow>
</QItemLabel> </QItemSection>
</QItemSection> <QItemSection side>
</QItem> <QIcon
</template> name="delete"
</VnSelect> size="sm"
class="cursor-pointer"
color="primary"
@click="
openConfirmationModal(
t(`Remove PDA`),
t('Do you want to remove this PDA?'),
() => deallocatePDA(row.deviceProductionFk)
)
"
>
<QTooltip>
{{ t('worker.pda.removePDA') }}
</QTooltip>
</QIcon>
</QItemSection>
</QItem>
</QCard>
</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

@ -489,23 +489,6 @@ onMounted(async () => {
</QBtnGroup> </QBtnGroup>
</div> </div>
</Teleport> </Teleport>
<template v-if="stateStore.isHeaderMounted()">
<Teleport to="#actions-append">
<div class="row q-gutter-x-sm">
<QBtn
flat
@click="stateStore.toggleRightDrawer()"
round
dense
icon="menu"
>
<QTooltip bottom anchor="bottom right">
{{ t('globals.collapseMenu') }}
</QTooltip>
</QBtn>
</div>
</Teleport>
</template>
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="260" class="q-pa-md"> <QDrawer v-model="stateStore.rightDrawer" side="right" :width="260" class="q-pa-md">
<div class="q-pa-md q-mb-md" style="border: 2px solid #222"> <div class="q-pa-md q-mb-md" style="border: 2px solid #222">
<QCardSection horizontal> <QCardSection horizontal>

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');
});
});