Update code with changes from git diff
This commit is contained in:
@@ -77,6 +77,7 @@ $('div.modal#cargando').modal({
|
||||
|
||||
const store = reactive({
|
||||
loading: false,
|
||||
perido: null as Periodo | null,
|
||||
current: {
|
||||
comentario: '',
|
||||
clase_vista: null,
|
||||
@@ -216,8 +217,8 @@ const store = reactive({
|
||||
registro_fecha_justificacion: Date;
|
||||
};
|
||||
try {
|
||||
const res = await fetch('action/action_justificar.php', {
|
||||
method: 'PUT',
|
||||
const res = await fetch('action/justificar.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -237,6 +238,41 @@ const store = reactive({
|
||||
store.current.justificada.justificador_rol = data.justificador_rol
|
||||
store.current.justificada.registro_fecha_justificacion = data.registro_fecha_justificacion
|
||||
},
|
||||
async justificarBloque(fecha: Date, bloques: Array<number>, justificacion: string) {
|
||||
if (bloques.length === 0) {
|
||||
alert('No se ha seleccionado ningún bloque');
|
||||
return;
|
||||
}
|
||||
if (!justificacion) {
|
||||
alert('No se ha ingresado ninguna observación');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await fetch('action/action_justificar.php', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
fecha,
|
||||
bloques,
|
||||
justificacion,
|
||||
})
|
||||
})
|
||||
const resData = await res.json();
|
||||
if (resData.status === 'success') {
|
||||
alert('Se ha justificado el bloque');
|
||||
store.current.modal_state = 'Cargando datos...';
|
||||
$('div.modal#cargando').modal('show');
|
||||
await store.registros.fetch();
|
||||
$('div.modal#cargando').modal('hide');
|
||||
} else {
|
||||
alert('No se ha podido justificar el bloque');
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error al justificar');
|
||||
}
|
||||
},
|
||||
registros: {
|
||||
data: [] as Registro[],
|
||||
async fetch(fecha?: Date, fecha_inicio?: Date, fecha_fin?: Date) {
|
||||
@@ -284,7 +320,7 @@ const store = reactive({
|
||||
if one of the filters is null, then it is not relevant
|
||||
|
||||
*/
|
||||
const filters = Object.keys(store.filters).filter((filtro) => store.filters[filtro] || store.filters[filtro]?.length > 0)
|
||||
const filters = Object.keys(store.filters).filter((filtro) => store.filters[filtro] !== null || store.filters[filtro]?.length > 0)
|
||||
return this.data.filter((registro: Registro) => {
|
||||
return filters.every((filtro) => {
|
||||
switch (filtro) {
|
||||
@@ -306,6 +342,7 @@ const store = reactive({
|
||||
return nombre.includes(textoFiltro);
|
||||
}
|
||||
case 'facultad_id':
|
||||
|
||||
return registro.facultad_id === store.filters[filtro];
|
||||
case 'estados':
|
||||
if (store.filters[filtro].length === 0) return true;
|
||||
@@ -364,6 +401,7 @@ type Profesor = {
|
||||
}
|
||||
createApp({
|
||||
store,
|
||||
messages: [] as Array<{ title: string, text: string, type: string, timestamp: string }>,
|
||||
get clase_vista() {
|
||||
return store.current.clase_vista
|
||||
},
|
||||
@@ -380,14 +418,22 @@ createApp({
|
||||
profesores: [] as Profesor[],
|
||||
async mounted() {
|
||||
$('div.modal#cargando').modal('show');
|
||||
try {
|
||||
|
||||
// await store.registros.fetch()
|
||||
await store.facultades.fetch()
|
||||
await store.estados.fetch()
|
||||
await store.bloques_horario.fetch()
|
||||
await store.filters.switchFechas()
|
||||
this.profesores = await (await fetch('action/action_profesor.php')).json() as Profesor[];
|
||||
|
||||
$('div.modal#cargando').modal('hide');
|
||||
// await store.registros.fetch()
|
||||
await store.facultades.fetch()
|
||||
await store.estados.fetch()
|
||||
await store.bloques_horario.fetch()
|
||||
await store.filters.switchFechas();
|
||||
store.periodo = await fetch('action/periodo_datos.php').then(res => res.json()) as Periodo;
|
||||
this.profesores = await (await fetch('action/action_profesor.php')).json() as Profesor[];
|
||||
|
||||
this.messages.push({ title: 'Datos cargados', text: 'Los datos se han cargado correctamente', type: 'success', timestamp: new Date() })
|
||||
} catch (error) {
|
||||
this.messages.push({ title: 'Error al cargar datos', text: 'No se pudieron cargar los datos', type: 'danger', timestamp: new Date() })
|
||||
}
|
||||
finally {
|
||||
$('div.modal#cargando').modal('hide');
|
||||
}
|
||||
}
|
||||
}).mount('#app')
|
||||
|
||||
Reference in New Issue
Block a user