0
0
Fork 0
This commit is contained in:
William Buezas 2024-03-15 08:20:48 -03:00
parent 6baaebf6bd
commit c7b60346e9
1 changed files with 93 additions and 76 deletions

View File

@ -9,19 +9,26 @@ import axios from 'axios';
import { useRole } from 'src/composables/useRole'; import { useRole } from 'src/composables/useRole';
import { useWeekdayStore } from 'src/stores/useWeekdayStore'; import { useWeekdayStore } from 'src/stores/useWeekdayStore';
import { useStateStore } from 'stores/useStateStore'; import { useStateStore } from 'stores/useStateStore';
import { useState } from 'src/composables/useState';
const route = useRoute(); const route = useRoute();
const { t } = useI18n(); const { t } = useI18n();
const { notify } = useNotify(); // const { notify } = useNotify();
const { hasAny } = useRole(); const { hasAny } = useRole();
const state = useState();
const user = state.getUser();
const stateStore = useStateStore(); const stateStore = useStateStore();
const weekdayStore = useWeekdayStore(); const weekdayStore = useWeekdayStore();
const entryDirections = [ // const entryDirections = [
{ code: 'in', description: t('Entrada') }, // { code: 'in', description: t('Entrada') },
{ code: 'middle', description: t('Intermedio') }, // { code: 'middle', description: t('Intermedio') },
{ code: 'out', description: t('Salida') }, // { code: 'out', description: t('Salida') },
]; // ];
const isHr = computed(() => hasAny(['hr']));
const isHimSelf = computed(() => user.value.id === route.params.id);
const columns = computed(() => { const columns = computed(() => {
return weekdayStore.localeWeekdays?.map((day) => { return weekdayStore.localeWeekdays?.map((day) => {
@ -34,54 +41,74 @@ const columns = computed(() => {
}); });
}); });
const fetchWorkerTimeControlRef = ref(null);
const calendarRef = ref(null); const calendarRef = ref(null);
const selectedDate = ref(null); // const selectedDate = ref(null);
const selectedDateRange = ref(null); const selectedDates = ref([]);
const endOfWeek = ref(null);
const startOfWeek = ref(null);
const handleDateSelection = (date) => { const defaultDate = computed(() => {
if (!date) return; const date = Date.vnNew();
console.log('date', date); const year = date.getFullYear();
const month = date.getMonth() + 1; // Nota: getMonth devuelve el mes indexado desde 0
return `${year}/${month.toString().padStart(2, '0')}`;
});
const _date = new Date(date.year, date.month - 1, date.day); const handleDateSelection = async (dates, _, selectedDateDetails) => {
console.log('_date', _date); if (!dates.length || !selectedDateDetails) return;
const dateRange = { from: '', to: '' }; const selectedDate = new Date(
selectedDateDetails.year,
selectedDateDetails.month - 1,
selectedDateDetails.day
);
// Obtener la fecha de 3 días atrás // Obtener el día de la semana de la fecha seleccionada (0 = Domingo, 1 = Lunes, ..., 6 = Sábado)
const threeDaysAgo = new Date(_date); const dayOfWeek = selectedDate.getDay();
threeDaysAgo.setDate(_date.getDate() - 3);
dateRange.from = {
year: threeDaysAgo.getFullYear(),
month: threeDaysAgo.getMonth() + 1, // Los meses van de 0 a 11, por eso sumamos 1
day: threeDaysAgo.getDate(),
};
// Obtener la fecha de 3 días adelante // Obtener el primer día de la semana (Lunes)
const threeDaysAhead = new Date(_date); const newStartOfWeek = new Date(selectedDate);
threeDaysAhead.setDate(_date.getDate() + 3); newStartOfWeek.setDate(
dateRange.to = { selectedDate.getDate() - dayOfWeek + (dayOfWeek === 0 ? -6 : 1)
year: threeDaysAhead.getFullYear(), );
month: threeDaysAhead.getMonth() + 1, // Los meses van de 0 a 11, por eso sumamos 1 startOfWeek.value = newStartOfWeek;
day: threeDaysAhead.getDate(),
};
calendarRef.value.setEditingRange(dateRange.from, dateRange.to); // Obtener el último día de la semana (Domingo)
console.log('date range:', dateRange); const newEndOfWeek = new Date(newStartOfWeek);
newEndOfWeek.setDate(newStartOfWeek.getDate() + 6);
endOfWeek.value = newEndOfWeek;
// Crear un array con las fechas de la semana seleccionada
const selectedDatesArray = [];
for (
let date = new Date(newStartOfWeek);
date <= newEndOfWeek;
date.setDate(date.getDate() + 1)
) {
selectedDatesArray.push(new Date(date).toISOString().slice(0, 10));
}
console.log('start of week:: ', startOfWeek.value);
console.log('new end of week:: ', endOfWeek.value);
// Asignar el array de fechas de la semana seleccionada al valor reactivo
selectedDates.value = selectedDatesArray;
setTimeout(async () => {
await fetchWorkerTimeControlRef.value.fetch();
}, 1);
}; };
// const isAllowedToEdit = computed(() => hasAny(['hr', 'productionAssi'])); const workerTimeControlsFilter = computed(() => ({
// const columns = computed(() => [ where: {
// { and: [{ timed: { gte: startOfWeek.value } }, { timed: { lte: endOfWeek.value } }],
// label: 'asd', },
// name: 'picture', }));
// align: 'left',
// }, const setWorkerTimeControls = (data) => {
// { console.log('worker time controls:: ', data);
// label: t('entry.latestBuys.tags'), };
// name: 'tags',
// align: 'left',
// },
// ]);
console.log('columns:: ', columns.value); console.log('columns:: ', columns.value);
@ -96,34 +123,28 @@ onMounted(async () => {
</script> </script>
<template> <template>
<!-- <FetchData <FetchData
ref="fetchCurrentDeviceRef" ref="fetchWorkerTimeControlRef"
url="DeviceProductionUsers" url="WorkerTimeControls/filter"
:filter="{ :filter="workerTimeControlsFilter"
where: { userFk: route.params.id }, :params="{
include: { relation: 'deviceProduction' }, workerFk: route.params.id,
}" }"
auto-load @on-fetch="(data) => setWorkerTimeControls(data)"
@on-fetch="(data) => setCurrentPDA(data[0])" />
/> -->
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="300" show-if-above> <QDrawer v-model="stateStore.rightDrawer" side="right" :width="300" show-if-above>
<!-- <QScrollArea class="fit text-grey-8"> --> <QDate
<div class="fit"> ref="calendarRef"
<QDate :model-value="selectedDates"
ref="calendarRef" @update:model-value="handleDateSelection"
v-model="selectedDate" mask="YYYY-MM-DD"
@range-start="handleDateSelection" color="primary"
mask="YYYY-MM-DD" minimal
color="primary" multiple
minimal bordered
:years-in-month-view="false" :default-year-month="defaultDate"
first-day-of-week="1" />
range <pre>date range: {{ selectedDates }}</pre>
class
/>
</div>
<!-- </QScrollArea> -->
</QDrawer> </QDrawer>
<QPage class="column items-center q-pa-md"> <QPage class="column items-center q-pa-md">
<QCard class="full-width"> <QCard class="full-width">
@ -132,11 +153,7 @@ onMounted(async () => {
</QPage> </QPage>
</template> </template>
<style scoped lang="scss"> <style scoped lang="scss"></style>
.test {
max-width: 100px !important;
}
</style>
<i18n> <i18n>
es: es: