Merge branch '7884-AddLabelerField' of https://gitea.verdnatura.es/verdnatura/salix-front into 7884-AddLabelerField
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jon Elias 2024-09-18 08:23:18 +02:00
commit 3a95cf123e
9 changed files with 90 additions and 93 deletions

View File

@ -5,8 +5,10 @@ import useNotify from 'src/composables/useNotify.js';
const session = useSession(); const session = useSession();
const { notify } = useNotify(); const { notify } = useNotify();
const baseUrl = '/api/';
axios.defaults.baseURL = '/api/'; axios.defaults.baseURL = baseUrl;
const axiosNoError = axios.create({ baseURL: baseUrl });
const onRequest = (config) => { const onRequest = (config) => {
const token = session.getToken(); const token = session.getToken();
@ -79,5 +81,7 @@ const onResponseError = (error) => {
axios.interceptors.request.use(onRequest, onRequestError); axios.interceptors.request.use(onRequest, onRequestError);
axios.interceptors.response.use(onResponse, onResponseError); axios.interceptors.response.use(onResponse, onResponseError);
axiosNoError.interceptors.request.use(onRequest);
axiosNoError.interceptors.response.use(onResponse);
export { onRequest, onResponseError }; export { onRequest, onResponseError, axiosNoError };

View File

@ -67,9 +67,13 @@ const mixinRules = [
requiredFieldRule, requiredFieldRule,
...($attrs.rules ?? []), ...($attrs.rules ?? []),
(val) => { (val) => {
const { min } = vnInputRef.value.$attrs; const { min, max } = vnInputRef.value.$attrs;
if (!min) return null; if (!min) return null;
if (min >= 0) if (Math.floor(val) < min) return t('inputMin', { value: min }); if (min >= 0) if (Math.floor(val) < min) return t('inputMin', { value: min });
if (!max) return null;
if (max > 0) {
if (Math.floor(val) > max) return t('inputMax', { value: max });
}
}, },
]; ];
</script> </script>
@ -116,8 +120,10 @@ const mixinRules = [
<i18n> <i18n>
en: en:
inputMin: Must be more than {value} inputMin: Must be more than {value}
inputMax: Must be less than {value}
es: es:
inputMin: Debe ser mayor a {value} inputMin: Debe ser mayor a {value}
inputMax: Debe ser menor a {value}
</i18n> </i18n>
<style lang="scss"> <style lang="scss">
.q-field__append { .q-field__append {

View File

@ -2,6 +2,7 @@
import { onMounted, watch, computed, ref } from 'vue'; import { onMounted, watch, computed, ref } from 'vue';
import { date } from 'quasar'; import { date } from 'quasar';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useAttrs } from 'vue';
const model = defineModel({ type: [String, Date] }); const model = defineModel({ type: [String, Date] });
const $props = defineProps({ const $props = defineProps({
@ -14,29 +15,19 @@ const $props = defineProps({
default: true, default: true,
}, },
}); });
import { useValidator } from 'src/composables/useValidator';
const { validations } = useValidator();
const { t } = useI18n(); const { t } = useI18n();
const requiredFieldRule = (val) => !!val || t('globals.fieldRequired'); const requiredFieldRule = (val) => validations().required($attrs.required, val);
const dateFormat = 'DD/MM/YYYY'; const dateFormat = 'DD/MM/YYYY';
const isPopupOpen = ref(); const isPopupOpen = ref();
const hover = ref(); const hover = ref();
const mask = ref(); const mask = ref();
const $attrs = useAttrs();
onMounted(() => { const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
// fix quasar bug
mask.value = '##/##/####';
});
const styleAttrs = computed(() => {
return $props.isOutlined
? {
dense: true,
outlined: true,
rounded: true,
}
: {};
});
const formattedDate = computed({ const formattedDate = computed({
get() { get() {
@ -48,15 +39,12 @@ const formattedDate = computed({
let newDate; let newDate;
if (value) { if (value) {
// parse input // parse input
if (value.includes('/')) { if (value.includes('/') && value.length >= 10) {
if (value.length == 6) value = value + new Date().getFullYear(); if (value.at(2) == '/') value = value.split('/').reverse().join('/');
if (value.length >= 10) { value = date.formatDate(
if (value.at(2) == '/') value = value.split('/').reverse().join('/'); new Date(value).toISOString(),
value = date.formatDate( 'YYYY-MM-DDTHH:mm:ss.SSSZ'
new Date(value).toISOString(), );
'YYYY-MM-DDTHH:mm:ss.SSSZ'
);
}
} }
const [year, month, day] = value.split('-').map((e) => parseInt(e)); const [year, month, day] = value.split('-').map((e) => parseInt(e));
newDate = new Date(year, month - 1, day); newDate = new Date(year, month - 1, day);
@ -79,12 +67,25 @@ const formattedDate = computed({
const popupDate = computed(() => const popupDate = computed(() =>
model.value ? date.formatDate(new Date(model.value), 'YYYY/MM/DD') : model.value model.value ? date.formatDate(new Date(model.value), 'YYYY/MM/DD') : model.value
); );
onMounted(() => {
// fix quasar bug
mask.value = '##/##/####';
});
watch( watch(
() => model.value, () => model.value,
(val) => (formattedDate.value = val), (val) => (formattedDate.value = val),
{ immediate: true } { immediate: true }
); );
const styleAttrs = computed(() => {
return $props.isOutlined
? {
dense: true,
outlined: true,
rounded: true,
}
: {};
});
</script> </script>
<template> <template>
@ -96,9 +97,10 @@ watch(
placeholder="dd/mm/aaaa" placeholder="dd/mm/aaaa"
v-bind="{ ...$attrs, ...styleAttrs }" v-bind="{ ...$attrs, ...styleAttrs }"
:class="{ required: $attrs.required }" :class="{ required: $attrs.required }"
:rules="$attrs.required ? [requiredFieldRule] : null" :rules="mixinRules"
:clearable="false" :clearable="false"
@click="isPopupOpen = true" @click="isPopupOpen = true"
hide-bottom-space
> >
<template #append> <template #append>
<QIcon <QIcon

View File

@ -1,8 +1,10 @@
<script setup> <script setup>
import { computed, ref } from 'vue'; import { computed, ref, useAttrs } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { date } from 'quasar'; import { date } from 'quasar';
import { useValidator } from 'src/composables/useValidator';
const { validations } = useValidator();
const $attrs = useAttrs();
const model = defineModel({ type: String }); const model = defineModel({ type: String });
const props = defineProps({ const props = defineProps({
timeOnly: { timeOnly: {
@ -16,8 +18,8 @@ const props = defineProps({
}); });
const initialDate = ref(model.value ?? Date.vnNew()); const initialDate = ref(model.value ?? Date.vnNew());
const { t } = useI18n(); const { t } = useI18n();
const requiredFieldRule = (val) => !!val || t('globals.fieldRequired'); const requiredFieldRule = (val) => validations().required($attrs.required, val);
const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
const dateFormat = 'HH:mm'; const dateFormat = 'HH:mm';
const isPopupOpen = ref(); const isPopupOpen = ref();
const hover = ref(); const hover = ref();
@ -74,9 +76,10 @@ function dateToTime(newDate) {
v-bind="{ ...$attrs, ...styleAttrs }" v-bind="{ ...$attrs, ...styleAttrs }"
:class="{ required: $attrs.required }" :class="{ required: $attrs.required }"
style="min-width: 100px" style="min-width: 100px"
:rules="$attrs.required ? [requiredFieldRule] : null" :rules="mixinRules"
@click="isPopupOpen = false" @click="isPopupOpen = false"
type="time" type="time"
hide-bottom-space
> >
<template #append> <template #append>
<QIcon <QIcon

View File

@ -20,6 +20,8 @@ onMounted(() => (stateStore.leftDrawer = $props.leftDrawer));
</QScrollArea> </QScrollArea>
</QDrawer> </QDrawer>
<QPageContainer> <QPageContainer>
<RouterView></RouterView> <QPage>
<RouterView />
</QPage>
</QPageContainer> </QPageContainer>
</template> </template>

View File

@ -1,7 +1,8 @@
<script setup> <script setup>
import { ref, toRefs, computed, watch, onMounted } from 'vue'; import { ref, toRefs, computed, watch, onMounted, useAttrs } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import FetchData from 'src/components/FetchData.vue'; import FetchData from 'src/components/FetchData.vue';
import { useValidator } from 'src/composables/useValidator';
const emit = defineEmits(['update:modelValue', 'update:options', 'remove']); const emit = defineEmits(['update:modelValue', 'update:options', 'remove']);
const $props = defineProps({ const $props = defineProps({
@ -82,10 +83,11 @@ const $props = defineProps({
default: false, default: false,
}, },
}); });
const { validations } = useValidator();
const requiredFieldRule = (val) => validations().required($attrs.required, val);
const $attrs = useAttrs();
const { t } = useI18n(); const { t } = useI18n();
const requiredFieldRule = (val) => val ?? t('globals.fieldRequired'); const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
const { optionLabel, optionValue, optionFilter, optionFilterValue, options, modelValue } = const { optionLabel, optionValue, optionFilter, optionFilterValue, options, modelValue } =
toRefs($props); toRefs($props);
const myOptions = ref([]); const myOptions = ref([]);
@ -248,8 +250,9 @@ const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);
ref="vnSelectRef" ref="vnSelectRef"
lazy-rules lazy-rules
:class="{ required: $attrs.required }" :class="{ required: $attrs.required }"
:rules="$attrs.required ? [requiredFieldRule] : null" :rules="mixinRules"
virtual-scroll-slice-size="options.length" virtual-scroll-slice-size="options.length"
hide-bottom-space
> >
<template v-if="isClearable" #append> <template v-if="isClearable" #append>
<QIcon <QIcon

View File

@ -2,6 +2,7 @@
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { onMounted, ref, computed, onBeforeMount, nextTick, reactive } from 'vue'; import { onMounted, ref, computed, onBeforeMount, nextTick, reactive } from 'vue';
import { axiosNoError } from 'src/boot/axios';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';
import WorkerTimeHourChip from 'pages/Worker/Card/WorkerTimeHourChip.vue'; import WorkerTimeHourChip from 'pages/Worker/Card/WorkerTimeHourChip.vue';
@ -12,7 +13,6 @@ import WorkerTimeControlCalendar from 'pages/Worker/Card/WorkerTimeControlCalend
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
import axios from 'axios'; import axios from 'axios';
import { useRole } from 'src/composables/useRole';
import { useAcl } from 'src/composables/useAcl'; import { useAcl } from 'src/composables/useAcl';
import { useWeekdayStore } from 'src/stores/useWeekdayStore'; import { useWeekdayStore } from 'src/stores/useWeekdayStore';
import { useStateStore } from 'stores/useStateStore'; import { useStateStore } from 'stores/useStateStore';
@ -63,13 +63,16 @@ const selectedCalendarDates = ref([]);
const selectedDateFormatted = ref(toDateString(defaultDate.value)); const selectedDateFormatted = ref(toDateString(defaultDate.value));
const arrayData = useArrayData('workerData'); const arrayData = useArrayData('workerData');
const acl = useAcl();
const worker = computed(() => arrayData.store?.data); const worker = computed(() => arrayData.store?.data);
const canSend = computed(() =>
const isHr = computed(() => useRole().hasAny(['hr'])); acl.hasAny([{ model: 'WorkerTimeControl', props: 'sendMail', accessType: 'WRITE' }])
);
const canSend = computed(() => useAcl().hasAny('WorkerTimeControl', 'sendMail', 'WRITE')); const canUpdate = computed(() =>
acl.hasAny([
{ model: 'WorkerTimeControl', props: 'updateMailState', accessType: 'WRITE' },
])
);
const isHimself = computed(() => user.value.id === Number(route.params.id)); const isHimself = computed(() => user.value.id === Number(route.params.id));
const columns = computed(() => { const columns = computed(() => {
@ -257,58 +260,32 @@ const fetchHours = async () => {
} }
}; };
const fetchWorkerTimeControlMails = async (filter) => {
try {
const { data } = await axios.get('WorkerTimeControlMails', {
params: { filter: JSON.stringify(filter) },
});
return data;
} catch (err) {
console.error('Error fetching worker time control mails');
}
};
const fetchWeekData = async () => { const fetchWeekData = async () => {
const where = {
year: selectedDate.value.getFullYear(),
week: selectedWeekNumber.value,
};
try { try {
const filter = { const mail = (
where: { await axiosNoError.get(`Workers/${route.params.id}/mail`, {
workerFk: route.params.id, params: { filter: { where } },
year: selectedDate.value ? selectedDate.value?.getFullYear() : null, })
week: selectedWeekNumber.value, ).data[0];
},
};
const data = await fetchWorkerTimeControlMails(filter); if (!mail) state.value = null;
if (!data.length) { else {
state.value = null;
} else {
const [mail] = data;
state.value = mail.state; state.value = mail.state;
reason.value = mail.reason; reason.value = mail.reason;
} }
await canBeResend(); canResend.value = !!(
await axiosNoError.get('WorkerTimeControlMails/count', { params: { where } })
).data.count;
} catch (err) { } catch (err) {
console.error('Error fetching week data'); console.error('Error fetching week data');
} }
}; };
const canBeResend = async () => {
canResend.value = false;
const filter = {
where: {
year: selectedDate.value.getFullYear(),
week: selectedWeekNumber.value,
},
limit: 1,
};
const data = await fetchWorkerTimeControlMails(filter);
if (data.length) canResend.value = true;
};
const setHours = (data) => { const setHours = (data) => {
for (const weekDay of weekDays.value) { for (const weekDay of weekDays.value) {
if (data) { if (data) {
@ -449,7 +426,7 @@ onMounted(async () => {
<div> <div>
<QBtnGroup push class="q-gutter-x-sm" flat> <QBtnGroup push class="q-gutter-x-sm" flat>
<QBtn <QBtn
v-if="isHimself && state" v-if="canUpdate && state"
:label="t('Satisfied')" :label="t('Satisfied')"
color="primary" color="primary"
type="submit" type="submit"
@ -457,7 +434,7 @@ onMounted(async () => {
@click="isSatisfied()" @click="isSatisfied()"
/> />
<QBtn <QBtn
v-if="isHimself && state" v-if="canUpdate && state"
:label="t('Not satisfied')" :label="t('Not satisfied')"
color="primary" color="primary"
type="submit" type="submit"
@ -468,7 +445,7 @@ onMounted(async () => {
</QBtnGroup> </QBtnGroup>
<QBtnGroup push class="q-gutter-x-sm q-ml-none" flat> <QBtnGroup push class="q-gutter-x-sm q-ml-none" flat>
<QBtn <QBtn
v-if="reason && state && (isHimself || isHr)" v-if="reason && state && canUpdate"
:label="t('Reason')" :label="t('Reason')"
color="primary" color="primary"
type="submit" type="submit"

View File

@ -23,7 +23,7 @@ describe('EntryDms', () => {
expect(value).to.have.length(newFileTd++); expect(value).to.have.length(newFileTd++);
const newRowSelector = `tbody > :nth-child(${newFileTd})`; const newRowSelector = `tbody > :nth-child(${newFileTd})`;
cy.waitForElement(newRowSelector); cy.waitForElement(newRowSelector);
cy.validateRow(newRowSelector, [u, u, u, u, 'ENTRADA ID 1']); cy.validateRow(newRowSelector, [u, u, u, u, u, 'ENTRADA ID 1']);
//Edit new dms //Edit new dms
const newDescription = 'entry id 1 modified'; const newDescription = 'entry id 1 modified';
@ -38,7 +38,7 @@ describe('EntryDms', () => {
cy.saveCard(); cy.saveCard();
cy.reload(); cy.reload();
cy.validateRow(newRowSelector, [u, u, u, u, newDescription]); cy.validateRow(newRowSelector, [u, u, u, u, u, newDescription]);
}); });
}); });
}); });

View File

@ -5,7 +5,7 @@ describe('Ticket descriptor', () => {
const warehouseValue = ':nth-child(1) > :nth-child(6) > .value > span'; const warehouseValue = ':nth-child(1) > :nth-child(6) > .value > span';
const summaryHeader = '.summaryHeader > div'; const summaryHeader = '.summaryHeader > div';
const weight = 25; const weight = 25;
const weightValue = ':nth-child(10) > .value > span'; const weightValue = '.summaryBody.row :nth-child(1) > :nth-child(9) > .value > span';
beforeEach(() => { beforeEach(() => {
cy.login('developer'); cy.login('developer');
cy.viewport(1920, 1080); cy.viewport(1920, 1080);