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

@@ -69,6 +69,12 @@ type Periodo = {
periodo_nombre: string;
}
declare var $: any
$('div.modal#cargando').modal({
backdrop: 'static',
keyboard: false,
show: false,
})
const store = reactive({
loading: false,
@@ -80,6 +86,7 @@ const store = reactive({
maxPages: 10,
perPage: 10,
modal_state: "Cargando datos...",
justificada: null,
},
facultades: {
data: [] as Facultad[],
@@ -104,8 +111,12 @@ const store = reactive({
async switchFechas() {
const periodo = await fetch('action/periodo_datos.php');
const periodo_data = await periodo.json() as Periodo;
// 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({
@@ -116,6 +127,7 @@ const store = reactive({
});
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());
@@ -124,10 +136,21 @@ 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: {
@@ -173,39 +196,46 @@ const store = reactive({
}
return newArray
},
})
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
}
declare var $: any
type Profesor = {
profesor_id: number;
profesor_nombre: string;
profesor_correo: string;
profesor_clave: string;
profesor_grado: string;
}
$('div.modal#cargando').modal({
backdrop: 'static',
keyboard: false,
show: false,
})
createApp({
store,
get clase_vista() {
return store.current.clase_vista
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: [] as Registro[],
async fetch() {
async fetch(fecha?: Date, fecha_inicio?: Date, fecha_fin?: Date) {
// if (!store.filters.facultad_id || !store.filters.periodo_id) return
this.loading = true
this.data = [] as Registro[]
const params = {
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 as any).toString()
const res = await fetch(`action/action_auditoria.php?${paramsUrl}`, {
method: 'GET',
@@ -221,7 +251,6 @@ createApp({
store.current.comentario = registro.comentario
$('#ver-comentario').modal('show')
},
get relevant() {
/*
facultad_id: null,
@@ -242,10 +271,6 @@ createApp({
perPage: 10,
*/
return this.data.filter((registro: 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':
@@ -272,9 +297,11 @@ createApp({
return store.filters[filtro].includes(registro.estado_supervisor_id);
case 'bloque_horario':
const bloque = store.bloques_horario.data.find((bloque: Bloque_Horario) => bloque.id === store.filters[filtro]) as Bloque_Horario;
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
}
}
})
})
@@ -313,8 +340,31 @@ createApp({
return Math.ceil(this.relevant.length / store.current.perPage)
}
},
})
type Profesor = {
profesor_id: number;
profesor_nombre: string;
profesor_correo: string;
profesor_clave: string;
profesor_grado: string;
}
createApp({
store,
get clase_vista() {
return store.current.clase_vista
},
set_justificar(horario_id: Number, profesor_id: Number, registro_fecha_ideal: Date) {
store.current.justificada = store.registros.relevant.find((registro: 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: Registro) => ({
profesor_id: registro.profesor_id,
profesor_nombre: registro.profesor_nombre,
@@ -336,7 +386,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()