From de912b266cc0342c0525c8c231266b420fe53960 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Wed, 27 Mar 2024 08:26:28 -0300 Subject: [PATCH] Finish calendar integration --- ...onth.vue => WorkerTimeControlCalendar.vue} | 90 ++++++++++++++----- src/pages/Worker/Card/WorkerTimeControl.vue | 40 +++------ 2 files changed, 78 insertions(+), 52 deletions(-) rename src/components/{common/VnCalendarMonth.vue => WorkerTimeControlCalendar.vue} (60%) diff --git a/src/components/common/VnCalendarMonth.vue b/src/components/WorkerTimeControlCalendar.vue similarity index 60% rename from src/components/common/VnCalendarMonth.vue rename to src/components/WorkerTimeControlCalendar.vue index 24eb65660..01b5af8ae 100644 --- a/src/components/common/VnCalendarMonth.vue +++ b/src/components/WorkerTimeControlCalendar.vue @@ -1,10 +1,9 @@ diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index 7bedc13d0..4300f4803 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -8,7 +8,7 @@ import WorkerTimeHourChip from 'components/WorkerTimeHourChip.vue'; import WorkerTimeForm from 'components/WorkerTimeForm.vue'; import WorkerTimeReasonForm from 'components/WorkerTimeReasonForm.vue'; import WorkerDateLabel from './WorkerDateLabel.vue'; -import VnCalendarMonth from 'components/common/VnCalendarMonth.vue'; +import WorkerTimeControlCalendar from 'components/WorkerTimeControlCalendar.vue'; import useNotify from 'src/composables/useNotify.js'; import axios from 'axios'; @@ -21,6 +21,7 @@ import { useVnConfirm } from 'composables/useVnConfirm'; import { useArrayData } from 'composables/useArrayData'; import { toTimeFormat, secondsToHoursMinutes } from 'filters/date.js'; import toDateString from 'filters/toDateString.js'; +import { date } from 'quasar'; const route = useRoute(); const { t, locale } = useI18n(); @@ -32,6 +33,7 @@ const stateStore = useStateStore(); const weekdayStore = useWeekdayStore(); const weekDays = ref([]); const { openConfirmationModal } = useVnConfirm(); +const { getWeekOfYear } = date; const workerTimeFormDialogRef = ref(null); const workerTimeReasonFormDialogRef = ref(null); @@ -106,7 +108,7 @@ const setDate = async (date) => { startOfWeek.value = newStartOfWeek; endOfWeek.value = newEndOfWeek; - selectedWeekNumber.value = getWeekNumber(newStartOfWeek); // Asignar el número de la semana + selectedWeekNumber.value = getWeekOfYear(newStartOfWeek); // Asignar el número de la semana del año getWeekDates(newStartOfWeek, newEndOfWeek); @@ -133,43 +135,24 @@ const getEndOfWeek = (startOfWeek) => { // Función para obtener las fechas de la semana seleccionada const getWeekDates = (startOfWeek, endOfWeek) => { - selectedCalendarDates.value = []; // Limpiar las fechas seleccionadas previamente usadas por QCalendar + selectedCalendarDates.value = []; weekDays.value = []; // Limpiar la información de las fechas seleccionadas previamente let currentDate = new Date(startOfWeek); while (currentDate <= endOfWeek) { // Iterar sobre los días de la semana - selectedCalendarDates.value.push(formatDate(currentDate)); // Agregar fecha formateada para el array de fechas bindeado al componente QCalendar + selectedCalendarDates.value.push(toDateString(currentDate)); // Agregar fecha formateada para el array de fechas bindeado al componente QCalendar weekDays.value.push({ dated: new Date(currentDate.getTime()) }); // Agregar el día de la semana al array información de días de la semana currentDate = new Date(currentDate.setDate(currentDate.getDate() + 1)); // Avanzar al siguiente día } }; -// Función para Convertir la fecha al formato que acepta el componente QCalendar: '2001-01-01' -const formatDate = (date) => { - return date.toISOString().slice(0, 10); -}; - const workerHoursFilter = computed(() => ({ where: { and: [{ timed: { gte: startOfWeek.value } }, { timed: { lte: endOfWeek.value } }], }, })); -const getWeekNumber = (date) => { - if (!date) return; - const startOfYear = new Date(date.getFullYear(), 0, 1); - const dayOfWeek = startOfYear.getDay(); - const offset = dayOfWeek === 0 ? 6 : dayOfWeek - 1; - const firstWeekMilliseconds = startOfYear.getTime() - offset * 24 * 60 * 60 * 1000; - const dateMilliseconds = date.getTime(); - const weekNumber = - Math.floor( - (dateMilliseconds - firstWeekMilliseconds) / (7 * 24 * 60 * 60 * 1000) - ) + 1; - return weekNumber; -}; - const getWorkedHours = async (from, to) => { weekTotalHours.value = null; let _weekTotalHours = 0; @@ -273,7 +256,6 @@ const fetchWorkerTimeControlMails = async (filter) => { params: { filter: JSON.stringify(filter) }, }); - console.log('data:: ', data); return data; } catch (err) { console.error('Error fetching worker time control mails'); @@ -286,7 +268,7 @@ const fetchWeekData = async () => { where: { workerFk: route.params.id, year: selectedDate.value ? selectedDate.value?.getFullYear() : null, - week: getWeekNumber(selectedDate.value), + week: selectedWeekNumber.value, }, }; @@ -312,7 +294,7 @@ const canBeResend = async () => { const filter = { where: { year: selectedDate.value.getFullYear(), - week: getWeekNumber(selectedDate.value), + week: selectedWeekNumber.value, }, limit: 1, }; @@ -441,7 +423,8 @@ onBeforeMount(() => { }); onMounted(async () => { - setDate(Date.vnNew()); + await setDate(Date.vnNew()); + await getMailStates(selectedDate.value); stateStore.rightDrawer = true; }); @@ -523,12 +506,13 @@ onMounted(async () => { -