Añadir justificaciones

This commit is contained in:
2023-08-16 19:19:00 +00:00
parent 094cf8b611
commit 9ce1dee313
5 changed files with 422 additions and 137 deletions

View File

@@ -1,4 +1,9 @@
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module';
$('div.modal#cargando').modal({
backdrop: 'static',
keyboard: false,
show: false,
});
const store = reactive({
loading: false,
current: {
@@ -9,6 +14,7 @@ const store = reactive({
maxPages: 10,
perPage: 10,
modal_state: "Cargando datos...",
justificada: null,
},
facultades: {
data: [],
@@ -32,7 +38,11 @@ const store = reactive({
async switchFechas() {
const periodo = await fetch('action/periodo_datos.php');
const periodo_data = await periodo.json();
// console.log(`Fecha inicio: ${periodo_data.periodo_fecha_inicio} Fecha fin: ${periodo_data.fecha_final}`);
if (!store.filters.switchFecha) {
$('div.modal#cargando').modal('show');
await store.registros.fetch();
$('div.modal#cargando').modal('hide');
}
$(function () {
store.filters.fecha_inicio = store.filters.fecha_fin = store.filters.fecha = null;
$("#fecha, #fecha_inicio, #fecha_fin").datepicker({
@@ -42,6 +52,7 @@ const store = reactive({
showAnim: "slide",
});
const fecha = $("#fecha"), inicio = $("#fecha_inicio"), fin = $("#fecha_fin");
fecha.datepicker("setDate", new Date(`${periodo_data.fecha_final}:00:00:00`));
inicio.on("change", function () {
store.filters.fecha_inicio = inicio.val();
fin.datepicker("option", "minDate", inicio.val());
@@ -50,10 +61,19 @@ const store = reactive({
store.filters.fecha_fin = fin.val();
inicio.datepicker("option", "maxDate", fin.val());
});
fecha.on("change", function () {
fecha.on("change", async function () {
store.filters.fecha = fecha.val();
$('div.modal#cargando').modal('show');
await store.registros.fetch(store.filters.fecha);
$('div.modal#cargando').modal('hide');
});
});
},
async fetchByDate() {
$('div.modal#cargando').modal('show');
await store.registros.fetch(undefined, store.filters.fecha_inicio, store.filters.fecha_fin);
store.current.page = 1;
$('div.modal#cargando').modal('hide');
}
},
estados: {
@@ -96,20 +116,36 @@ const store = reactive({
}
return newArray;
},
});
$('div.modal#cargando').modal({
backdrop: 'static',
keyboard: false,
show: false,
});
createApp({
store,
get clase_vista() {
return store.current.clase_vista;
async justificar() {
if (!store.current.justificada)
return;
let data;
try {
const res = await fetch('action/action_justificar.php', {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(store.current.justificada)
});
data = await res.json();
}
catch (error) {
alert('Error al justificar');
store.current.justificada = store.current.clone_justificada;
}
finally {
delete store.current.clone_justificada;
}
store.current.justificada.justificador_nombre = data.justificador_nombre;
store.current.justificada.justificador_clave = data.justificador_clave;
store.current.justificada.justificador_facultad = data.justificador_facultad;
store.current.justificada.justificador_rol = data.justificador_rol;
store.current.justificada.registro_fecha_justificacion = data.registro_fecha_justificacion;
},
registros: {
data: [],
async fetch() {
async fetch(fecha, fecha_inicio, fecha_fin) {
// if (!store.filters.facultad_id || !store.filters.periodo_id) return
this.loading = true;
this.data = [];
@@ -117,6 +153,12 @@ createApp({
facultad_id: 19,
periodo_id: 2,
};
if (fecha)
params['fecha'] = fecha;
if (fecha_inicio)
params['fecha_inicio'] = fecha_inicio;
if (fecha_fin)
params['fecha_fin'] = fecha_fin;
const paramsUrl = new URLSearchParams(params).toString();
const res = await fetch(`action/action_auditoria.php?${paramsUrl}`, {
method: 'GET',
@@ -152,10 +194,6 @@ createApp({
perPage: 10,
*/
return this.data.filter((registro) => {
if (store.filters.sin_registro && !registro.registro_fecha_supervisor)
return true;
else if (store.filters.sin_registro)
return false;
return filters.every((filtro) => {
switch (filtro) {
case 'fecha':
@@ -184,9 +222,13 @@ createApp({
return store.filters[filtro].includes(registro.estado_supervisor_id);
case 'bloque_horario':
const bloque = store.bloques_horario.data.find((bloque) => bloque.id === store.filters[filtro]);
return registro.horario_hora <= bloque.hora_fin && registro.horario_fin >= bloque.hora_inicio;
default:
return true;
return registro.horario_hora < bloque.hora_fin && registro.horario_fin > bloque.hora_inicio;
default: {
if (store.filters.sin_registro && !registro.registro_fecha_supervisor)
return true;
else if (store.filters.sin_registro)
return false;
}
}
});
});
@@ -226,8 +268,22 @@ createApp({
return Math.ceil(this.relevant.length / store.current.perPage);
}
},
});
createApp({
store,
get clase_vista() {
return store.current.clase_vista;
},
set_justificar(horario_id, profesor_id, registro_fecha_ideal) {
store.current.justificada = store.registros.relevant.find((registro) => registro.horario_id === horario_id && registro.profesor_id === profesor_id && registro.registro_fecha_ideal === registro_fecha_ideal);
store.current.clone_justificada = JSON.parse(JSON.stringify(store.current.justificada));
},
cancelar_justificacion() {
Object.assign(store.current.justificada, store.current.clone_justificada);
delete store.current.clone_justificada;
},
get profesores() {
return this.registros.data
return store.registros.data
.map((registro) => ({
profesor_id: registro.profesor_id,
profesor_nombre: registro.profesor_nombre,
@@ -245,7 +301,7 @@ createApp({
},
async mounted() {
$('div.modal#cargando').modal('show');
await this.registros.fetch();
await store.registros.fetch();
await store.facultades.fetch();
await store.estados.fetch();
await store.bloques_horario.fetch();