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')
|
||||
|
||||
170
ts/periodos.ts
170
ts/periodos.ts
@@ -1,63 +1,145 @@
|
||||
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'
|
||||
|
||||
type Carrera = {
|
||||
carrera_id: number;
|
||||
carrera_nombre: string;
|
||||
clave_carrera: string;
|
||||
facultad_id: number;
|
||||
facultad_nombre: string;
|
||||
nivel_id: number;
|
||||
nivel_nombre: string;
|
||||
interface Periodo {
|
||||
created_at: Date;
|
||||
estado_id: number;
|
||||
id_periodo_sgu: number;
|
||||
nivel: string;
|
||||
nivel_id: number | '';
|
||||
periodo_clave: string;
|
||||
periodo_fecha_fin: Date;
|
||||
periodo_fecha_inicio: Date;
|
||||
periodo_id: number;
|
||||
periodo_nombre: string;
|
||||
}
|
||||
|
||||
type Nivel = {
|
||||
interface Nivel {
|
||||
nivel_id: number;
|
||||
nivel_nombre: string;
|
||||
}
|
||||
|
||||
const app = createApp({
|
||||
carreras: [] as Carrera[],
|
||||
niveles: [] as Nivel[],
|
||||
message: {} as Record<string, string>,
|
||||
async setNivel(carrera: Carrera, nivel: Nivel) {
|
||||
if (carrera.nivel_id === nivel.nivel_id) {
|
||||
return
|
||||
}
|
||||
carrera.nivel_id = nivel.nivel_id
|
||||
carrera.nivel_nombre = nivel.nivel_nombre
|
||||
periodos: [] as Array<Periodo>,
|
||||
niveles: [] as Array<Nivel>,
|
||||
messages: [] as Array<{ title: string, text: string, type: string, timestamp: string }>,
|
||||
|
||||
await fetch('action/carrera.php', {
|
||||
addMessage(title: string, text: string, type: string) {
|
||||
this.messages.push({ title, text, type, timestamp: new Date() });
|
||||
},
|
||||
|
||||
async sendRequest(action: string, periodo_id: number, data: any) {
|
||||
const response = await fetch('action/periodos.php', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
carrera_id: carrera.carrera_id,
|
||||
nivel_id: nivel.nivel_id
|
||||
action: action,
|
||||
periodo_id: periodo_id,
|
||||
...data
|
||||
})
|
||||
})
|
||||
.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()
|
||||
})
|
||||
|
||||
|
||||
return await response.json()
|
||||
},
|
||||
|
||||
async changeNivel(periodo: Periodo, nivel_id: number) {
|
||||
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.nivel_id === nivel_id)?.nivel_nombre}`, 'success')
|
||||
periodo.nivel_id = nivel_id
|
||||
periodo.nivel = this.niveles.find((nivel: 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: Periodo, fecha_inicio: Date) {
|
||||
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: Periodo, fecha_fin: Date) {
|
||||
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: 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: Periodo) {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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: Periodo) {
|
||||
const response = await fetch('action/periodos.php', {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
periodo_id: periodo.periodo_id,
|
||||
})
|
||||
})
|
||||
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: Periodo) => 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
|
||||
}, {} as Record<number, Carrera[]>)
|
||||
this.carreras = Object.entries(carreras).map(([facultad_nombre, carreras]) => ({
|
||||
facultad_nombre: facultad_nombre,
|
||||
carreras
|
||||
}))
|
||||
}
|
||||
}).mount('#app')
|
||||
Reference in New Issue
Block a user