0
0
Fork 0

Merge pull request '#5919 locker' (!338) from 5919-locker into dev

Reviewed-on: verdnatura/salix-front#338
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Jorge Penadés 2024-05-13 12:08:47 +00:00
commit cde918744d
9 changed files with 108 additions and 2 deletions

View File

@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- (Worker) => Se crea la sección Taquilla
### Fixed
- (General) => Se vuelven a mostrar los parámetros en la url al aplicar un filtro

View File

@ -156,9 +156,12 @@ const startFormWatcher = () => {
async function fetch() {
try {
const { data } = await axios.get($props.url, {
let { data } = await axios.get($props.url, {
params: { filter: JSON.stringify($props.filter) },
});
if (Array.isArray(data)) data = data[0] ?? {};
state.set($props.model, data);
originalData.value = data && JSON.parse(JSON.stringify(data));

View File

@ -1,5 +1,5 @@
<script setup>
import { onBeforeMount, computed } from 'vue';
import { onBeforeMount, computed, watchEffect } from 'vue';
import { useRoute, onBeforeRouteUpdate } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { useArrayData } from 'src/composables/useArrayData';
@ -47,6 +47,11 @@ if (props.baseUrl) {
}
});
}
watchEffect(() => {
if (Array.isArray(arrayData.store.data))
arrayData.store.data = arrayData.store.data[0];
});
</script>
<template>
<Teleport

View File

@ -826,6 +826,7 @@ worker:
log: Log
calendar: Calendar
timeControl: Time control
locker: Locker
list:
name: Name
email: Email

View File

@ -824,6 +824,7 @@ worker:
log: Historial
calendar: Calendario
timeControl: Control de horario
locker: Taquilla
list:
name: Nombre
email: Email

View File

@ -0,0 +1,64 @@
<script setup>
import { ref, computed } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import axios from 'axios';
import { useRole } from 'src/composables/useRole';
import FormModel from 'components/FormModel.vue';
import VnSelect from 'src/components/common/VnSelect.vue';
import { useArrayData } from 'src/composables/useArrayData';
import FetchData from 'components/FetchData.vue';
const { hasAny } = useRole();
const { t } = useI18n();
const fetchData = ref();
const originaLockerId = ref();
const lockers = ref([]);
const { store } = useArrayData('Worker');
const entityId = computed(() => useRoute().params.id);
const filter = computed(() => ({
where: {
gender: store.data?.sex,
or: [{ workerFk: null }, { workerFk: entityId.value }],
},
}));
const save = async (data) => {
const lockerId = data.id ?? originaLockerId.value;
const workerFk = lockerId == originaLockerId.value ? null : entityId.value;
await axios.patch(`Lockers/${lockerId}`, { workerFk });
};
const init = async (data) => {
await fetchData.value.fetch();
originaLockerId.value = data.id;
};
</script>
<template>
<FetchData
ref="fetchData"
url="Lockers/codes"
:filter="filter"
@on-fetch="(data) => (lockers = data)"
/>
<FormModel
:url="`Workers/${entityId}/locker`"
model="worker"
auto-load
:save-fn="save"
@on-fetch="init"
>
<template #form="{ data }">
<VnSelect
:label="t('Locker')"
v-model="data.id"
:options="lockers"
option-label="code"
option-value="id"
hide-selected
:readonly="!hasAny(['productionBoss', 'hr'])"
/>
</template>
</FormModel>
</template>

View File

@ -1,2 +1,3 @@
Search worker: Buscar trabajador
You can search by worker id or name: Puedes buscar por id o nombre del trabajador
Locker: Taquilla

View File

@ -22,6 +22,7 @@ export default {
'WorkerCalendar',
'WorkerDms',
'WorkerTimeControl',
'WorkerLocker',
],
departmentCard: ['BasicData'],
},
@ -167,6 +168,15 @@ export default {
component: () =>
import('src/pages/Worker/Card/WorkerTimeControl.vue'),
},
{
name: 'WorkerLocker',
path: 'locker',
meta: {
title: 'locker',
icon: 'lock',
},
component: () => import('src/pages/Worker/Card/WorkerLocker.vue'),
},
],
},
],

View File

@ -0,0 +1,19 @@
describe('WorkerList', () => {
const workerId = 1110;
const lockerCode = '200A';
const input = '.q-card input';
const firstOpt = '[role="listbox"] .q-item:nth-child(1)';
beforeEach(() => {
cy.viewport(1280, 720);
cy.login('productionBoss');
cy.visit(`/#/worker/${workerId}/locker`);
});
it('should allocates a locker', () => {
cy.get(input).click();
cy.get(input).type(lockerCode);
cy.get(firstOpt).click();
cy.saveCard();
cy.get(input).invoke('val').should('eq', lockerCode);
});
});