WIP
This commit is contained in:
parent
c7b60346e9
commit
d12fa85d73
|
@ -19,7 +19,7 @@ const state = useState();
|
||||||
const user = state.getUser();
|
const user = state.getUser();
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
const weekdayStore = useWeekdayStore();
|
const weekdayStore = useWeekdayStore();
|
||||||
|
const weekDays = ref([]);
|
||||||
// const entryDirections = [
|
// const entryDirections = [
|
||||||
// { code: 'in', description: t('Entrada') },
|
// { code: 'in', description: t('Entrada') },
|
||||||
// { code: 'middle', description: t('Intermedio') },
|
// { code: 'middle', description: t('Intermedio') },
|
||||||
|
@ -43,61 +43,58 @@ const columns = computed(() => {
|
||||||
|
|
||||||
const fetchWorkerTimeControlRef = ref(null);
|
const fetchWorkerTimeControlRef = ref(null);
|
||||||
const calendarRef = ref(null);
|
const calendarRef = ref(null);
|
||||||
// const selectedDate = ref(null);
|
// Dates formateadas para bindear al componente QDate
|
||||||
const selectedDates = ref([]);
|
const selectedCalendarDates = ref([]);
|
||||||
const endOfWeek = ref(null);
|
|
||||||
const startOfWeek = ref(null);
|
const startOfWeek = ref(null);
|
||||||
|
const endOfWeek = ref(null);
|
||||||
|
|
||||||
const defaultDate = computed(() => {
|
const defaultDate = computed(() => {
|
||||||
const date = Date.vnNew();
|
const date = Date.vnNew();
|
||||||
const year = date.getFullYear();
|
return `${date.getFullYear()}/${(date.getMonth() + 1).toString().padStart(2, '0')}`;
|
||||||
const month = date.getMonth() + 1; // Nota: getMonth devuelve el mes indexado desde 0
|
|
||||||
return `${year}/${month.toString().padStart(2, '0')}`;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleDateSelection = async (dates, _, selectedDateDetails) => {
|
const handleDateSelection = async (dates, _, selectedDateDetails) => {
|
||||||
if (!dates.length || !selectedDateDetails) return;
|
if (!dates.length || !selectedDateDetails) return;
|
||||||
|
|
||||||
const selectedDate = new Date(
|
const { year, month, day } = selectedDateDetails;
|
||||||
selectedDateDetails.year,
|
const selectedDate = new Date(year, month - 1, day);
|
||||||
selectedDateDetails.month - 1,
|
|
||||||
selectedDateDetails.day
|
|
||||||
);
|
|
||||||
|
|
||||||
// Obtener el día de la semana de la fecha seleccionada (0 = Domingo, 1 = Lunes, ..., 6 = Sábado)
|
startOfWeek.value = getStartOfWeek(selectedDate);
|
||||||
|
endOfWeek.value = getEndOfWeek(startOfWeek.value);
|
||||||
|
|
||||||
|
getWeekDates(startOfWeek.value, endOfWeek.value);
|
||||||
|
|
||||||
|
await fetchWorkerTimeControl();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStartOfWeek = (selectedDate) => {
|
||||||
const dayOfWeek = selectedDate.getDay();
|
const dayOfWeek = selectedDate.getDay();
|
||||||
|
const startOfWeek = new Date(selectedDate);
|
||||||
|
startOfWeek.setDate(selectedDate.getDate() - dayOfWeek + (dayOfWeek === 0 ? -6 : 1));
|
||||||
|
return startOfWeek;
|
||||||
|
};
|
||||||
|
|
||||||
// Obtener el primer día de la semana (Lunes)
|
const getEndOfWeek = (startOfWeek) => {
|
||||||
const newStartOfWeek = new Date(selectedDate);
|
const endOfWeek = new Date(startOfWeek);
|
||||||
newStartOfWeek.setDate(
|
endOfWeek.setDate(startOfWeek.getDate() + 6);
|
||||||
selectedDate.getDate() - dayOfWeek + (dayOfWeek === 0 ? -6 : 1)
|
return endOfWeek;
|
||||||
);
|
};
|
||||||
startOfWeek.value = newStartOfWeek;
|
|
||||||
|
|
||||||
// Obtener el último día de la semana (Domingo)
|
const getWeekDates = (startOfWeek, endOfWeek) => {
|
||||||
const newEndOfWeek = new Date(newStartOfWeek);
|
selectedCalendarDates.value = [];
|
||||||
newEndOfWeek.setDate(newStartOfWeek.getDate() + 6);
|
let currentDate = new Date(startOfWeek);
|
||||||
endOfWeek.value = newEndOfWeek;
|
|
||||||
|
|
||||||
// Crear un array con las fechas de la semana seleccionada
|
while (currentDate <= endOfWeek) {
|
||||||
const selectedDatesArray = [];
|
selectedCalendarDates.value.push(formatDate(currentDate));
|
||||||
for (
|
weekDays.value.push({
|
||||||
let date = new Date(newStartOfWeek);
|
dated: new Date(currentDate.getTime()),
|
||||||
date <= newEndOfWeek;
|
});
|
||||||
date.setDate(date.getDate() + 1)
|
currentDate = new Date(currentDate.setDate(currentDate.getDate() + 1));
|
||||||
) {
|
|
||||||
selectedDatesArray.push(new Date(date).toISOString().slice(0, 10));
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
console.log('start of week:: ', startOfWeek.value);
|
const formatDate = (date) => {
|
||||||
console.log('new end of week:: ', endOfWeek.value);
|
return date.toISOString().slice(0, 10);
|
||||||
|
|
||||||
// Asignar el array de fechas de la semana seleccionada al valor reactivo
|
|
||||||
selectedDates.value = selectedDatesArray;
|
|
||||||
|
|
||||||
setTimeout(async () => {
|
|
||||||
await fetchWorkerTimeControlRef.value.fetch();
|
|
||||||
}, 1);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const workerTimeControlsFilter = computed(() => ({
|
const workerTimeControlsFilter = computed(() => ({
|
||||||
|
@ -106,6 +103,14 @@ const workerTimeControlsFilter = computed(() => ({
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const fetchWorkerTimeControl = async () => {
|
||||||
|
try {
|
||||||
|
await fetchWorkerTimeControlRef.value.fetch();
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching worker time control');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const setWorkerTimeControls = (data) => {
|
const setWorkerTimeControls = (data) => {
|
||||||
console.log('worker time controls:: ', data);
|
console.log('worker time controls:: ', data);
|
||||||
};
|
};
|
||||||
|
@ -135,7 +140,7 @@ onMounted(async () => {
|
||||||
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="300" show-if-above>
|
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="300" show-if-above>
|
||||||
<QDate
|
<QDate
|
||||||
ref="calendarRef"
|
ref="calendarRef"
|
||||||
:model-value="selectedDates"
|
:model-value="selectedCalendarDates"
|
||||||
@update:model-value="handleDateSelection"
|
@update:model-value="handleDateSelection"
|
||||||
mask="YYYY-MM-DD"
|
mask="YYYY-MM-DD"
|
||||||
color="primary"
|
color="primary"
|
||||||
|
|
Loading…
Reference in New Issue