Update code with changes from git diff

This commit is contained in:
2023-11-10 18:15:14 +00:00
parent 2e00fbec20
commit 2173869717
33 changed files with 7013 additions and 615 deletions

View File

@@ -6,6 +6,7 @@ $('div.modal#cargando').modal({
});
const store = reactive({
loading: false,
perido: null,
current: {
comentario: '',
clase_vista: null,
@@ -132,8 +133,8 @@ const store = reactive({
store.current.justificada.registro_justificada = true;
let data;
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'
},
@@ -154,6 +155,43 @@ const store = reactive({
store.current.justificada.justificador_rol = data.justificador_rol;
store.current.justificada.registro_fecha_justificacion = data.registro_fecha_justificacion;
},
async justificarBloque(fecha, bloques, justificacion) {
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: [],
async fetch(fecha, fecha_inicio, fecha_fin) {
@@ -203,7 +241,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) => {
return filters.every((filtro) => {
switch (filtro) {
@@ -279,6 +317,7 @@ const store = reactive({
});
createApp({
store,
messages: [],
get clase_vista() {
return store.current.clase_vista;
},
@@ -294,12 +333,21 @@ createApp({
profesores: [],
async mounted() {
$('div.modal#cargando').modal('show');
// 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();
$('div.modal#cargando').modal('hide');
try {
// 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());
this.profesores = await (await fetch('action/action_profesor.php')).json();
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');

View File

@@ -1,44 +1,115 @@
import { createApp } from 'https://unpkg.com/petite-vue?module';
const app = createApp({
carreras: [],
periodos: [],
niveles: [],
message: {},
async setNivel(carrera, nivel) {
if (carrera.nivel_id === nivel.nivel_id) {
messages: [],
addMessage(title, text, type) {
this.messages.push({ title, text, type, timestamp: new Date() });
},
async sendRequest(action, periodo_id, data) {
const response = await fetch('action/periodos.php', {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
action: action,
periodo_id: periodo_id,
...data
})
});
return await response.json();
},
async changeNivel(periodo, nivel_id) {
if (periodo.nivel_id === nivel_id)
return;
const result = await this.sendRequest('changeNivel', periodo.periodo_id, { nivel_id: nivel_id });
if (result.success) {
this.addMessage('Nivel cambiado', `El nivel del periodo ${periodo.periodo_nombre} ha sido cambiado a ${this.niveles.find((nivel) => nivel.nivel_id === nivel_id)?.nivel_nombre}`, 'success');
periodo.nivel_id = nivel_id;
periodo.nivel = this.niveles.find((nivel) => nivel.nivel_id === nivel_id)?.nivel_nombre || '';
}
else {
this.addMessage('Error al cambiar nivel', `No se pudo cambiar el nivel del periodo ${periodo.periodo_nombre}`, 'danger');
}
},
async changeFechaInicio(periodo, fecha_inicio) {
const result = await this.sendRequest('changeFechaInicio', periodo.periodo_id, { periodo_fecha_inicio: fecha_inicio });
if (result.success) {
this.addMessage('Fecha de inicio cambiada', `La fecha de inicio del periodo ${periodo.periodo_nombre} ha sido cambiada a ${fecha_inicio}`, 'success');
periodo.periodo_fecha_inicio = fecha_inicio;
}
else {
this.addMessage('Error al cambiar fecha de inicio', `No se pudo cambiar la fecha de inicio del periodo ${periodo.periodo_nombre}`, 'danger');
}
},
async changeFechaFin(periodo, fecha_fin) {
const result = await this.sendRequest('changeFechaFin', periodo.periodo_id, { periodo_fecha_fin: fecha_fin });
if (result.success) {
this.addMessage('Fecha de fin cambiada', `La fecha de fin del periodo ${periodo.periodo_nombre} ha sido cambiada a ${fecha_fin}`, 'success');
periodo.periodo_fecha_fin = fecha_fin;
}
else {
this.addMessage('Error al cambiar fecha de fin', `No se pudo cambiar la fecha de fin del periodo ${periodo.periodo_nombre}`, 'danger');
}
},
async updatePeriodo(periodo) {
const result = await this.sendRequest('updatePeriodo', periodo.periodo_id, {
periodo_nombre: periodo.periodo_nombre,
id_periodo_sgu: periodo.id_periodo_sgu,
periodo_clave: periodo.periodo_clave,
});
if (result.success) {
this.addMessage('Periodo actualizado', `El periodo ${periodo.periodo_nombre} ha sido actualizado`, 'success');
}
else {
this.addMessage('Error al actualizar periodo', `No se pudo actualizar el periodo ${periodo.periodo_nombre}`, 'danger');
}
},
async createPeriodo(newPeriodo) {
if (newPeriodo.periodo_nombre === null || newPeriodo.nivel_id === null || newPeriodo.periodo_fecha_inicio === null || newPeriodo.periodo_fecha_fin === null) {
this.addMessage('Error al crear periodo', `No se pudo crear el periodo ${newPeriodo.periodo_nombre}`, 'danger');
return;
}
carrera.nivel_id = nivel.nivel_id;
carrera.nivel_nombre = nivel.nivel_nombre;
await fetch('action/carrera.php', {
method: 'PUT',
const result = await fetch('action/periodos.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(newPeriodo)
}).then(res => res.json());
if (result.success) {
this.addMessage('Periodo creado', `El periodo ${newPeriodo.periodo_nombre} ha sido creado`, 'success');
this.periodos;
Object.keys(newPeriodo).forEach(key => newPeriodo[key] = null);
newPeriodo.nivel_id = '';
this.periodos = await fetch('action/periodos.php').then(res => res.json());
}
else {
this.addMessage('Error al crear periodo', `No se pudo crear el periodo ${newPeriodo.periodo_nombre}`, 'danger');
}
},
async deletePeriodo(periodo) {
const response = await fetch('action/periodos.php', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
carrera_id: carrera.carrera_id,
nivel_id: nivel.nivel_id
periodo_id: periodo.periodo_id,
})
})
.then(res => res.json())
.then(res => {
this.message.title = "Actualización";
this.message.text = res.error ?? res.success;
this.message.type = res.error ? 'danger' : 'success';
this.message.timestamp = new Date().toLocaleTimeString();
});
const result = await response.json();
if (result.success) {
this.addMessage('Periodo eliminado', `El periodo ${periodo.periodo_nombre} ha sido eliminado`, 'success');
this.periodos = this.periodos.filter((p) => p.periodo_id !== periodo.periodo_id);
}
else {
this.addMessage('Error al eliminar periodo', `No se pudo eliminar el periodo ${periodo.periodo_nombre}`, 'danger');
}
},
async mounted() {
this.carreras = await fetch('action/carrera.php').then(res => res.json());
this.periodos = await fetch('action/periodos.php').then(res => res.json());
this.niveles = await fetch('action/nivel.php').then(res => res.json());
// group by facultad_id
const carreras = this.carreras.reduce((acc, cur) => {
const { facultad_nombre } = cur;
if (!acc[facultad_nombre]) {
acc[facultad_nombre] = [];
}
acc[facultad_nombre].push(cur);
return acc;
}, {});
this.carreras = Object.entries(carreras).map(([facultad_nombre, carreras]) => ({
facultad_nombre: facultad_nombre,
carreras
}));
}
}).mount('#app');

View File

@@ -29,3 +29,12 @@ const check = () => {
}
['scroll', 'resize'].forEach(e => window.addEventListener(e, check))
document.addEventListener('DOMContentLoaded', function () {
const links = document.querySelectorAll('a');
links.forEach(function (link) {
link.addEventListener('click', function (event) {
// event.preventDefault();
});
});
});