All
This commit is contained in:
@@ -38,6 +38,21 @@ type Horario = {
|
||||
bloques: number;
|
||||
}
|
||||
|
||||
type Facultad = {
|
||||
clave_dependencia: string;
|
||||
facultad_id: number;
|
||||
facultad_nombre: string;
|
||||
carreras: Carrera[];
|
||||
}
|
||||
|
||||
type Carrera = {
|
||||
carrera_id: number;
|
||||
carrera_nombre: string;
|
||||
clave_carrera: string;
|
||||
facultad_id: number;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const profesores = reactive({
|
||||
data: [] as Profesor[],
|
||||
@@ -55,6 +70,26 @@ const profesores = reactive({
|
||||
},
|
||||
})
|
||||
|
||||
const facultades = reactive({
|
||||
data: [] as Facultad[],
|
||||
fetch: async function () {
|
||||
const facultades = await fetch('action/action_facultad.php').then(response => response.json()) as Facultad[]
|
||||
const carreras = await fetch(`action/carrera.php`).then(response => response.json()) as Carrera[]
|
||||
this.data = await Promise.all(facultades.map(async facultad => ({
|
||||
...facultad,
|
||||
carreras: await Promise.all(carreras.filter((carrera: Carrera) => carrera.facultad_id === facultad.facultad_id).map(async (carrera: Carrera) => {
|
||||
const grupos = await fetch(`action/action_grupo.php?carrera_id=${carrera.carrera_id}`).then(response => response.json())
|
||||
return {
|
||||
...carrera,
|
||||
grupos,
|
||||
}
|
||||
})),
|
||||
})))
|
||||
|
||||
this.data = this.data.filter((facultad: Facultad) => facultad.carreras.length > 0)
|
||||
}
|
||||
})
|
||||
|
||||
type Structure = {
|
||||
sábado: boolean;
|
||||
hora_mínima: number;
|
||||
@@ -64,8 +99,12 @@ type Structure = {
|
||||
|
||||
const horarios = reactive({
|
||||
data: [] as Horario[],
|
||||
fetch: async function () {
|
||||
if (profesores.current) {
|
||||
fetch: async function (grupo: number | null = null, carrera_id: number | null = null) {
|
||||
if (grupo && carrera_id) {
|
||||
const response = await fetch(`action/action_horario.php?grupo=${grupo}&carrera_id=${carrera_id}`)
|
||||
this.data = await response.json()
|
||||
}
|
||||
else if (profesores.current) {
|
||||
const response = await fetch(`action/action_horario.php?profesor_id=${profesores.current.profesor_id}`)
|
||||
this.data = await response.json()
|
||||
}
|
||||
@@ -134,7 +173,9 @@ const horarios = reactive({
|
||||
const app = createApp({
|
||||
profesores,
|
||||
horarios,
|
||||
facultades,
|
||||
mounted: async function () {
|
||||
await profesores.fetch()
|
||||
await facultades.fetch()
|
||||
}
|
||||
}).mount('#app')
|
||||
@@ -41,13 +41,41 @@ const app = createApp({
|
||||
})
|
||||
const data = await res.json()
|
||||
this.puestos.push(data)
|
||||
// order by puesto.nombre
|
||||
this.puestos.sort((a: Puesto, b: Puesto) => a.nombre.localeCompare(b.nombre))
|
||||
} catch (error) {
|
||||
alert(`Error: ${error}`)
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
async actualizarPuesto(puesto_id: number, materias: Materia[], usuario_id: number) {
|
||||
to_delete: null as Puesto | null,
|
||||
async eliminarPuesto(puesto_id: number) {
|
||||
try {
|
||||
const res = await fetch('action/puesto.php', {
|
||||
method: 'DELETE',
|
||||
body: JSON.stringify({
|
||||
puesto_id
|
||||
})
|
||||
})
|
||||
const data = await res.json()
|
||||
this.message = data.msg;
|
||||
|
||||
// after 3 seconds, remove the message
|
||||
setTimeout(() => {
|
||||
this.message = null
|
||||
}, 3000)
|
||||
|
||||
this.puestos = this.puestos.filter((p: Puesto) => p.puesto_id !== puesto_id)
|
||||
// order by puesto.nombre
|
||||
this.puestos.sort((a: Puesto, b: Puesto) => a.nombre.localeCompare(b.nombre))
|
||||
} catch (error) {
|
||||
alert(`Error: ${error}`)
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
async actualizarPuesto(puesto_id: number, materias: Materia[], usuario_id: number | null) {
|
||||
try {
|
||||
const res = await fetch('action/puesto.php', {
|
||||
method: 'PUT',
|
||||
|
||||
Reference in New Issue
Block a user