Commit Bulk
This commit is contained in:
82
js/horario.js
Normal file
82
js/horario.js
Normal file
@@ -0,0 +1,82 @@
|
||||
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module';
|
||||
const profesores = reactive({
|
||||
data: [],
|
||||
search: null,
|
||||
fetch: async function () {
|
||||
const response = await fetch('action/action_profesor.php');
|
||||
this.data = await response.json();
|
||||
},
|
||||
get clave() {
|
||||
const match = this.search.match(/^\((.+)\)/);
|
||||
return match ? match[1] : '';
|
||||
},
|
||||
get current() {
|
||||
return this.data.find((profesor) => profesor.profesor_clave === profesores.clave);
|
||||
},
|
||||
});
|
||||
const horarios = reactive({
|
||||
data: [],
|
||||
fetch: async function () {
|
||||
if (profesores.current) {
|
||||
const response = await fetch(`action/action_horario.php?profesor_id=${profesores.current.profesor_id}`);
|
||||
this.data = await response.json();
|
||||
}
|
||||
},
|
||||
get structure() {
|
||||
if (this.data.length === 0)
|
||||
return null;
|
||||
const structure = {
|
||||
sábado: this.data.some((horario) => horario.horario_dia === 6),
|
||||
hora_mínima: Math.min(...this.data.map((horario) => parseInt(horario.horario_hora.split(':')[0]))),
|
||||
hora_máxima: Math.max(...this.data.map((horario) => {
|
||||
const [hour, minute] = horario.horario_fin.split(':').map(Number);
|
||||
return hour + Math.ceil(minute / 60);
|
||||
})),
|
||||
horas_totales: 0
|
||||
};
|
||||
structure.horas_totales = structure.hora_máxima - structure.hora_mínima;
|
||||
return structure;
|
||||
},
|
||||
get blocks() {
|
||||
if (this.data.length === 0)
|
||||
return null;
|
||||
return [...Array(this.structure.horas_totales).keys()].flatMap(hora => {
|
||||
const baseHour = hora + this.structure.hora_mínima;
|
||||
return [0, 15, 30, 45].map(block => ({ hour: baseHour, block }));
|
||||
});
|
||||
},
|
||||
getHorarioData(hour, block, día) {
|
||||
const foundHorario = this.data.find((horario) => parseInt(horario.horario_hora.split(':')[0]) === hour &&
|
||||
parseInt(horario.horario_hora.split(':')[1]) === block &&
|
||||
horario.horario_dia === día);
|
||||
return foundHorario;
|
||||
},
|
||||
isOccupied(hora, bloque, day) {
|
||||
if (this.getHorarioData(hora, bloque, day)) {
|
||||
return false;
|
||||
}
|
||||
const currentTimeInMinutes = hora * 60 + bloque;
|
||||
for (const item of this.data) {
|
||||
if (item.horario_dia !== day) {
|
||||
continue; // Skip items that are not on the specified day
|
||||
}
|
||||
// Split the hour and minute from horario_hora
|
||||
const [startHour, startMinute] = item.horario_hora.split(":").map(Number);
|
||||
const startTimeInMinutes = startHour * 60 + startMinute;
|
||||
// Calculate end time using duracion
|
||||
const [durationHours, durationMinutes] = item.duracion.split(":").map(Number);
|
||||
const endTimeInMinutes = startTimeInMinutes + (durationHours * 60) + durationMinutes;
|
||||
if (currentTimeInMinutes >= startTimeInMinutes && currentTimeInMinutes < endTimeInMinutes) {
|
||||
return true; // The block is occupied
|
||||
}
|
||||
}
|
||||
return false; // The block is not occupied by any class
|
||||
}
|
||||
});
|
||||
const app = createApp({
|
||||
profesores,
|
||||
horarios,
|
||||
mounted: async function () {
|
||||
await profesores.fetch();
|
||||
}
|
||||
}).mount('#app');
|
||||
Reference in New Issue
Block a user