Actualización
This commit is contained in:
412
ts/avisos.ts
412
ts/avisos.ts
@@ -1,207 +1,207 @@
|
||||
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'
|
||||
|
||||
type Profesor = {
|
||||
profesor_clave: string;
|
||||
profesor_correo: null | string;
|
||||
profesor_grado: null | string;
|
||||
profesor_id: number;
|
||||
profesor_nombre: string;
|
||||
}
|
||||
|
||||
type Carrera = {
|
||||
carrera_activa: boolean;
|
||||
carrera_comun: boolean;
|
||||
carrera_id: number;
|
||||
carrera_nombre: string;
|
||||
clave_carrera: string;
|
||||
facultad_id: number | null;
|
||||
nivel_id: number;
|
||||
}
|
||||
|
||||
type Periodo = {
|
||||
created_at: Date;
|
||||
estado_id: number;
|
||||
fecha_final: Date;
|
||||
id_periodo_sgu: number;
|
||||
nivel_id: number;
|
||||
periodo_clave: string;
|
||||
periodo_fecha_fin: Date;
|
||||
periodo_fecha_inicio: Date;
|
||||
periodo_id: number;
|
||||
periodo_nombre: string;
|
||||
}
|
||||
|
||||
type Aviso = {
|
||||
aviso_estado: boolean;
|
||||
aviso_titulo: string;
|
||||
aviso_fecha_final: Date;
|
||||
aviso_fecha_inicial: Date;
|
||||
aviso_id: number;
|
||||
aviso_texto: string;
|
||||
carreras: Carrera[];
|
||||
facultad_id: null;
|
||||
profesores: Profesor[];
|
||||
}
|
||||
|
||||
const new_aviso = reactive({
|
||||
titulo: '',
|
||||
descripcion: '',
|
||||
fechaInicio: '',
|
||||
fechaFin: '',
|
||||
profesores: [] as Array<Profesor>,
|
||||
carreras: [] as Array<Carrera>,
|
||||
reset() {
|
||||
this.titulo = ''
|
||||
this.descripcion = ''
|
||||
this.fechaInicio = ''
|
||||
this.fechaFin = ''
|
||||
this.profesores = []
|
||||
this.carreras = []
|
||||
},
|
||||
get isValid() {
|
||||
return this.titulo !== '' && this.descripcion !== '' && this.fechaInicio !== '' && this.fechaFin !== '' && (this.profesores.length > 0 || this.carreras.length > 0) && this.facultad_id !== null
|
||||
},
|
||||
})
|
||||
// define datepicker method
|
||||
|
||||
const app = createApp({
|
||||
new_aviso,
|
||||
profesores: [] as Array<Profesor>,
|
||||
carreras: [] as Array<Carrera>,
|
||||
avisos: [] as Array<Aviso>,
|
||||
|
||||
profesor: null as String | null,
|
||||
formatProfesor(profesor: Profesor) {
|
||||
return `(${profesor.profesor_clave}) ${profesor.profesor_nombre}`
|
||||
},
|
||||
addProfesor() {
|
||||
const profesorObj = this.profesores.find((profesor: Profesor) => this.profesor === this.formatProfesor(profesor))
|
||||
if (profesorObj) {
|
||||
this.new_aviso.profesores.push(profesorObj)
|
||||
this.profesor = null
|
||||
}
|
||||
},
|
||||
|
||||
aviso_shown: null as Aviso | null,
|
||||
// int?
|
||||
aviso_suspendido: null as number | null,
|
||||
suspenderAviso() {
|
||||
if (this.aviso_suspendido) {
|
||||
const aviso = this.avisos.find((aviso: Aviso) => aviso.aviso_id === this.aviso_suspendido)
|
||||
if (aviso) {
|
||||
this.deleteAviso(aviso)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get relevant_profesores() {
|
||||
// not in array new_aviso.profesores
|
||||
const relevant = this.profesores.filter((profesor: Profesor) => !this.new_aviso.profesores.map((profesor: Profesor) => profesor.profesor_id).includes(profesor.profesor_id))
|
||||
// console.log('profesores:', this.profesores.map((profesor: Profesor) => profesor.profesor_nombre), 'relevant:', relevant.map((profesor: Profesor) => profesor.profesor_nombre), 'new_aviso:', this.new_aviso.profesores.map((profesor: Profesor) => profesor.profesor_nombre))
|
||||
return relevant
|
||||
},
|
||||
|
||||
get relevant_carreras() {
|
||||
// not in array new_aviso.carreras
|
||||
return this.carreras.filter((carrera: Carrera) => !this.new_aviso.carreras.includes(carrera))
|
||||
},
|
||||
|
||||
createAviso() {
|
||||
const data = {
|
||||
aviso_titulo: this.new_aviso.titulo,
|
||||
aviso_texto: this.new_aviso.descripcion,
|
||||
aviso_fecha_inicial: this.new_aviso.fechaInicio,
|
||||
aviso_fecha_final: this.new_aviso.fechaFin,
|
||||
profesores: this.new_aviso.profesores.map((profesor: Profesor) => profesor.profesor_id),
|
||||
carreras: this.new_aviso.carreras.map((carrera: Carrera) => carrera.carrera_id),
|
||||
}
|
||||
fetch('/action/avisos.php', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
}).then(res => res.json()).then(res => {
|
||||
if (res.success) {
|
||||
// hydrate with carreras and profesores
|
||||
this.avisos.push({
|
||||
...data,
|
||||
carreras: this.carreras.filter((carrera: Carrera) => data.carreras.includes(carrera.carrera_id)),
|
||||
profesores: this.profesores.filter((profesor: Profesor) => data.profesores.includes(profesor.profesor_id)),
|
||||
aviso_estado: true,
|
||||
aviso_id: res.aviso_id,
|
||||
})
|
||||
this.new_aviso.reset()
|
||||
}
|
||||
else {
|
||||
alert(res.error)
|
||||
console.log(res.errors)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
deleteAviso(aviso: Aviso) {
|
||||
fetch(`/action/avisos.php`, {
|
||||
method: 'DELETE',
|
||||
body: JSON.stringify({ aviso_id: aviso.aviso_id })
|
||||
}).then(res => res.json()).then(res => {
|
||||
if (res.success) {
|
||||
this.avisos = this.avisos.filter((aviso: Aviso) => aviso.aviso_id !== this.aviso_suspendido)
|
||||
this.aviso_suspendido = null
|
||||
}
|
||||
else {
|
||||
alert(res.error)
|
||||
console.log(res.errors)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
updateAviso() {
|
||||
fetch(`/action/avisos.php`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
aviso_id: this.aviso_shown.aviso_id,
|
||||
aviso_fecha_final: this.aviso_shown.aviso_fecha_final,
|
||||
})
|
||||
}).then(res => res.json()).then(res => {
|
||||
if (res.success) {
|
||||
}
|
||||
else {
|
||||
alert(res.error)
|
||||
console.log(res.errors)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
async initializeDatepickers($el: HTMLElement) {
|
||||
const periodo = await fetch('action/periodo_datos.php');
|
||||
const periodo_data = await periodo.json() as Periodo;
|
||||
|
||||
$('.date-picker').datepicker({
|
||||
dateFormat: 'yy-mm-dd',
|
||||
maxDate: periodo_data.periodo_fecha_fin,
|
||||
minDate: 0,
|
||||
});
|
||||
|
||||
$($el).on('change', () => {
|
||||
this.aviso_shown.aviso_fecha_final = $($el).val() as string;
|
||||
});
|
||||
},
|
||||
|
||||
async mounted() {
|
||||
this.avisos = await fetch("/action/avisos.php").then(res => res.json()) as Array<Aviso>
|
||||
this.profesores = await fetch('/action/action_profesor.php').then(res => res.json()) as Array<Profesor>
|
||||
this.carreras = await fetch('/action/action_carreras.php').then(res => res.json()) as Array<Carrera>
|
||||
|
||||
await this.initializeDatepickers()
|
||||
|
||||
const fechaInicio = $('#fechaInicio.date-picker')
|
||||
const fechaFin = $('#fechaFin.date-picker')
|
||||
fechaInicio.on("change", function () {
|
||||
new_aviso.fechaInicio = fechaInicio.val() as string
|
||||
fechaFin.datepicker("option", "minDate", fechaInicio.val());
|
||||
});
|
||||
|
||||
fechaFin.on("change", function () {
|
||||
new_aviso.fechaFin = fechaFin.val() as string
|
||||
fechaInicio.datepicker("option", "maxDate", fechaFin.val());
|
||||
});
|
||||
}
|
||||
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'
|
||||
|
||||
type Profesor = {
|
||||
profesor_clave: string;
|
||||
profesor_correo: null | string;
|
||||
profesor_grado: null | string;
|
||||
profesor_id: number;
|
||||
profesor_nombre: string;
|
||||
}
|
||||
|
||||
type Carrera = {
|
||||
carrera_activa: boolean;
|
||||
carrera_comun: boolean;
|
||||
carrera_id: number;
|
||||
carrera_nombre: string;
|
||||
clave_carrera: string;
|
||||
facultad_id: number | null;
|
||||
nivel_id: number;
|
||||
}
|
||||
|
||||
type Periodo = {
|
||||
created_at: Date;
|
||||
estado_id: number;
|
||||
fecha_final: Date;
|
||||
id_periodo_sgu: number;
|
||||
nivel_id: number;
|
||||
periodo_clave: string;
|
||||
periodo_fecha_fin: Date;
|
||||
periodo_fecha_inicio: Date;
|
||||
periodo_id: number;
|
||||
periodo_nombre: string;
|
||||
}
|
||||
|
||||
type Aviso = {
|
||||
aviso_estado: boolean;
|
||||
aviso_titulo: string;
|
||||
aviso_fecha_final: Date;
|
||||
aviso_fecha_inicial: Date;
|
||||
aviso_id: number;
|
||||
aviso_texto: string;
|
||||
carreras: Carrera[];
|
||||
facultad_id: null;
|
||||
profesores: Profesor[];
|
||||
}
|
||||
|
||||
const new_aviso = reactive({
|
||||
titulo: '',
|
||||
descripcion: '',
|
||||
fechaInicio: '',
|
||||
fechaFin: '',
|
||||
profesores: [] as Array<Profesor>,
|
||||
carreras: [] as Array<Carrera>,
|
||||
reset() {
|
||||
this.titulo = ''
|
||||
this.descripcion = ''
|
||||
this.fechaInicio = ''
|
||||
this.fechaFin = ''
|
||||
this.profesores = []
|
||||
this.carreras = []
|
||||
},
|
||||
get isValid() {
|
||||
return this.titulo !== '' && this.descripcion !== '' && this.fechaInicio !== '' && this.fechaFin !== '' && (this.profesores.length > 0 || this.carreras.length > 0) && this.facultad_id !== null
|
||||
},
|
||||
})
|
||||
// define datepicker method
|
||||
|
||||
const app = createApp({
|
||||
new_aviso,
|
||||
profesores: [] as Array<Profesor>,
|
||||
carreras: [] as Array<Carrera>,
|
||||
avisos: [] as Array<Aviso>,
|
||||
|
||||
profesor: null as String | null,
|
||||
formatProfesor(profesor: Profesor) {
|
||||
return `(${profesor.profesor_clave}) ${profesor.profesor_nombre}`
|
||||
},
|
||||
addProfesor() {
|
||||
const profesorObj = this.profesores.find((profesor: Profesor) => this.profesor === this.formatProfesor(profesor))
|
||||
if (profesorObj) {
|
||||
this.new_aviso.profesores.push(profesorObj)
|
||||
this.profesor = null
|
||||
}
|
||||
},
|
||||
|
||||
aviso_shown: null as Aviso | null,
|
||||
// int?
|
||||
aviso_suspendido: null as number | null,
|
||||
suspenderAviso() {
|
||||
if (this.aviso_suspendido) {
|
||||
const aviso = this.avisos.find((aviso: Aviso) => aviso.aviso_id === this.aviso_suspendido)
|
||||
if (aviso) {
|
||||
this.deleteAviso(aviso)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get relevant_profesores() {
|
||||
// not in array new_aviso.profesores
|
||||
const relevant = this.profesores.filter((profesor: Profesor) => !this.new_aviso.profesores.map((profesor: Profesor) => profesor.profesor_id).includes(profesor.profesor_id))
|
||||
// console.log('profesores:', this.profesores.map((profesor: Profesor) => profesor.profesor_nombre), 'relevant:', relevant.map((profesor: Profesor) => profesor.profesor_nombre), 'new_aviso:', this.new_aviso.profesores.map((profesor: Profesor) => profesor.profesor_nombre))
|
||||
return relevant
|
||||
},
|
||||
|
||||
get relevant_carreras() {
|
||||
// not in array new_aviso.carreras
|
||||
return this.carreras.filter((carrera: Carrera) => !this.new_aviso.carreras.includes(carrera))
|
||||
},
|
||||
|
||||
createAviso() {
|
||||
const data = {
|
||||
aviso_titulo: this.new_aviso.titulo,
|
||||
aviso_texto: this.new_aviso.descripcion,
|
||||
aviso_fecha_inicial: this.new_aviso.fechaInicio,
|
||||
aviso_fecha_final: this.new_aviso.fechaFin,
|
||||
profesores: this.new_aviso.profesores.map((profesor: Profesor) => profesor.profesor_id),
|
||||
carreras: this.new_aviso.carreras.map((carrera: Carrera) => carrera.carrera_id),
|
||||
}
|
||||
fetch('/action/avisos.php', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
}).then(res => res.json()).then(res => {
|
||||
if (res.success) {
|
||||
// hydrate with carreras and profesores
|
||||
this.avisos.push({
|
||||
...data,
|
||||
carreras: this.carreras.filter((carrera: Carrera) => data.carreras.includes(carrera.carrera_id)),
|
||||
profesores: this.profesores.filter((profesor: Profesor) => data.profesores.includes(profesor.profesor_id)),
|
||||
aviso_estado: true,
|
||||
aviso_id: res.aviso_id,
|
||||
})
|
||||
this.new_aviso.reset()
|
||||
}
|
||||
else {
|
||||
alert(res.error)
|
||||
console.log(res.errors)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
deleteAviso(aviso: Aviso) {
|
||||
fetch(`/action/avisos.php`, {
|
||||
method: 'DELETE',
|
||||
body: JSON.stringify({ aviso_id: aviso.aviso_id })
|
||||
}).then(res => res.json()).then(res => {
|
||||
if (res.success) {
|
||||
this.avisos = this.avisos.filter((aviso: Aviso) => aviso.aviso_id !== this.aviso_suspendido)
|
||||
this.aviso_suspendido = null
|
||||
}
|
||||
else {
|
||||
alert(res.error)
|
||||
console.log(res.errors)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
updateAviso() {
|
||||
fetch(`/action/avisos.php`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
aviso_id: this.aviso_shown.aviso_id,
|
||||
aviso_fecha_final: this.aviso_shown.aviso_fecha_final,
|
||||
})
|
||||
}).then(res => res.json()).then(res => {
|
||||
if (res.success) {
|
||||
}
|
||||
else {
|
||||
alert(res.error)
|
||||
console.log(res.errors)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
async initializeDatepickers($el: HTMLElement) {
|
||||
const periodo = await fetch('action/periodo_datos.php');
|
||||
const periodo_data = await periodo.json() as Periodo;
|
||||
|
||||
$('.date-picker').datepicker({
|
||||
dateFormat: 'yy-mm-dd',
|
||||
maxDate: periodo_data.periodo_fecha_fin,
|
||||
minDate: 0,
|
||||
});
|
||||
|
||||
$($el).on('change', () => {
|
||||
this.aviso_shown.aviso_fecha_final = $($el).val() as string;
|
||||
});
|
||||
},
|
||||
|
||||
async mounted() {
|
||||
this.avisos = await fetch("/action/avisos.php").then(res => res.json()) as Array<Aviso>
|
||||
this.profesores = await fetch('/action/action_profesor.php').then(res => res.json()) as Array<Profesor>
|
||||
this.carreras = await fetch('/action/action_carreras.php').then(res => res.json()) as Array<Carrera>
|
||||
|
||||
await this.initializeDatepickers()
|
||||
|
||||
const fechaInicio = $('#fechaInicio.date-picker')
|
||||
const fechaFin = $('#fechaFin.date-picker')
|
||||
fechaInicio.on("change", function () {
|
||||
new_aviso.fechaInicio = fechaInicio.val() as string
|
||||
fechaFin.datepicker("option", "minDate", fechaInicio.val());
|
||||
});
|
||||
|
||||
fechaFin.on("change", function () {
|
||||
new_aviso.fechaFin = fechaFin.val() as string
|
||||
fechaInicio.datepicker("option", "maxDate", fechaFin.val());
|
||||
});
|
||||
}
|
||||
}).mount('#app')
|
||||
124
ts/carreras.ts
124
ts/carreras.ts
@@ -1,63 +1,63 @@
|
||||
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;
|
||||
}
|
||||
|
||||
type 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
|
||||
|
||||
await fetch('action/carrera.php', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
carrera_id: carrera.carrera_id,
|
||||
nivel_id: nivel.nivel_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()
|
||||
})
|
||||
|
||||
|
||||
},
|
||||
async mounted() {
|
||||
this.carreras = await fetch('action/carrera.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
|
||||
}))
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
type 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
|
||||
|
||||
await fetch('action/carrera.php', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
carrera_id: carrera.carrera_id,
|
||||
nivel_id: nivel.nivel_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()
|
||||
})
|
||||
|
||||
|
||||
},
|
||||
async mounted() {
|
||||
this.carreras = await fetch('action/carrera.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')
|
||||
@@ -1 +1 @@
|
||||
declare module 'https://*'
|
||||
declare module 'https://*'
|
||||
|
||||
86
ts/faltas.ts
86
ts/faltas.ts
@@ -1,43 +1,43 @@
|
||||
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module';
|
||||
// define that $ has type any
|
||||
declare const $: any;
|
||||
|
||||
const filter = reactive({
|
||||
facultad: -1,
|
||||
profesor: '',
|
||||
porcentaje: 0
|
||||
});
|
||||
const app = createApp({
|
||||
filter,
|
||||
facultades: [],
|
||||
profesores: [],
|
||||
|
||||
faltas: [],
|
||||
openModal() {
|
||||
const modal = document.getElementById('cargando');
|
||||
$(modal).modal('show');
|
||||
},
|
||||
closeModal() {
|
||||
const modal = document.getElementById('cargando');
|
||||
$(modal).modal('hide');
|
||||
},
|
||||
|
||||
async refresh() {
|
||||
<<<<<<< HEAD
|
||||
alert(`Facultad: ${filter.facultad} - Profesor: ${filter.profesor} - Porcentaje: ${filter.porcentaje}%`
|
||||
if(filter.facultad == -1 || filter.porcetaje < 10) {
|
||||
=======
|
||||
if(filter.facultad == -1 || filter.porcentaje < 10) {
|
||||
>>>>>>> 7688f1aac1824c234bc5f19b154e9ad1f4808d4f
|
||||
return;
|
||||
}
|
||||
|
||||
this.openModal();
|
||||
this.faltas = await fetch(`action/profesor_faltas.php?facultad=${this.filter.facultad}&profesor=${this.filter.profesor}&porcentaje=${this.filter.porcentaje}`).then(res => res.json());
|
||||
this.closeModal();
|
||||
},
|
||||
async mounted() {
|
||||
this.facultades = await fetch('action/action_facultad.php').then(res => res.json());
|
||||
this.profesores = await fetch('action/action_profesor.php').then(res => res.json());
|
||||
}
|
||||
}).mount('#app');
|
||||
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module';
|
||||
// define that $ has type any
|
||||
declare const $: any;
|
||||
|
||||
const filter = reactive({
|
||||
facultad: -1,
|
||||
profesor: '',
|
||||
porcentaje: 0
|
||||
});
|
||||
const app = createApp({
|
||||
filter,
|
||||
facultades: [],
|
||||
profesores: [],
|
||||
|
||||
faltas: [],
|
||||
openModal() {
|
||||
const modal = document.getElementById('cargando');
|
||||
$(modal).modal('show');
|
||||
},
|
||||
closeModal() {
|
||||
const modal = document.getElementById('cargando');
|
||||
$(modal).modal('hide');
|
||||
},
|
||||
|
||||
async refresh() {
|
||||
<<<<<<< HEAD
|
||||
alert(`Facultad: ${filter.facultad} - Profesor: ${filter.profesor} - Porcentaje: ${filter.porcentaje}%`
|
||||
if(filter.facultad == -1 || filter.porcetaje < 10) {
|
||||
=======
|
||||
if(filter.facultad == -1 || filter.porcentaje < 10) {
|
||||
>>>>>>> 7688f1aac1824c234bc5f19b154e9ad1f4808d4f
|
||||
return;
|
||||
}
|
||||
|
||||
this.openModal();
|
||||
this.faltas = await fetch(`action/profesor_faltas.php?facultad=${this.filter.facultad}&profesor=${this.filter.profesor}&porcentaje=${this.filter.porcentaje}`).then(res => res.json());
|
||||
this.closeModal();
|
||||
},
|
||||
async mounted() {
|
||||
this.facultades = await fetch('action/action_facultad.php').then(res => res.json());
|
||||
this.profesores = await fetch('action/action_profesor.php').then(res => res.json());
|
||||
}
|
||||
}).mount('#app');
|
||||
|
||||
288
ts/periodos.ts
288
ts/periodos.ts
@@ -1,145 +1,145 @@
|
||||
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
interface Nivel {
|
||||
nivel_id: number;
|
||||
nivel_nombre: string;
|
||||
}
|
||||
|
||||
const app = createApp({
|
||||
periodos: [] as Array<Periodo>,
|
||||
niveles: [] as Array<Nivel>,
|
||||
messages: [] as Array<{ title: string, text: string, type: string, timestamp: string }>,
|
||||
|
||||
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({
|
||||
action: action,
|
||||
periodo_id: periodo_id,
|
||||
...data
|
||||
})
|
||||
})
|
||||
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.periodos = await fetch('action/periodos.php').then(res => res.json())
|
||||
this.niveles = await fetch('action/nivel.php').then(res => res.json())
|
||||
}
|
||||
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
interface Nivel {
|
||||
nivel_id: number;
|
||||
nivel_nombre: string;
|
||||
}
|
||||
|
||||
const app = createApp({
|
||||
periodos: [] as Array<Periodo>,
|
||||
niveles: [] as Array<Nivel>,
|
||||
messages: [] as Array<{ title: string, text: string, type: string, timestamp: string }>,
|
||||
|
||||
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({
|
||||
action: action,
|
||||
periodo_id: periodo_id,
|
||||
...data
|
||||
})
|
||||
})
|
||||
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.periodos = await fetch('action/periodos.php').then(res => res.json())
|
||||
this.niveles = await fetch('action/nivel.php').then(res => res.json())
|
||||
}
|
||||
}).mount('#app')
|
||||
210
ts/puestos.ts
210
ts/puestos.ts
@@ -1,106 +1,106 @@
|
||||
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'
|
||||
type Puesto = {
|
||||
puesto_id: number,
|
||||
nombre: string,
|
||||
facultad_id: number,
|
||||
}
|
||||
|
||||
type Carrera = {
|
||||
carrera_id: number;
|
||||
carrera_nombre: string;
|
||||
clave_carrera: string;
|
||||
}
|
||||
|
||||
type Materia = {
|
||||
carrera_id: number;
|
||||
clave_materia: string;
|
||||
materia_id: number;
|
||||
materia_nombre: string;
|
||||
}
|
||||
|
||||
type Usuario = {
|
||||
usuario_clave: string;
|
||||
usuario_id: number;
|
||||
usuario_nombre: string;
|
||||
}
|
||||
|
||||
const app = createApp({
|
||||
message: null,
|
||||
puestos: [] as Puesto[],
|
||||
carreras: [] as Carrera[],
|
||||
materias: [] as Materia[],
|
||||
usuarios: [] as Usuario[],
|
||||
|
||||
async nuevoPuesto(nuevoPuesto: string) {
|
||||
try {
|
||||
const res = await fetch('action/puesto.php', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
puesto_nombre: nuevoPuesto
|
||||
})
|
||||
})
|
||||
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}`)
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
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',
|
||||
body: JSON.stringify({
|
||||
puesto_id,
|
||||
materias: materias.map(m => m.materia_id),
|
||||
usuario_id
|
||||
})
|
||||
})
|
||||
const data = await res.json()
|
||||
this.message = data.msg;
|
||||
|
||||
// after 3 seconds, remove the message
|
||||
setTimeout(() => {
|
||||
this.message = null
|
||||
}, 3000)
|
||||
} catch (error) {
|
||||
alert(`Error: ${error}`)
|
||||
}
|
||||
},
|
||||
|
||||
async mounted() {
|
||||
this.puestos = await fetch('action/puesto.php').then(res => res.json())
|
||||
this.carreras = await fetch('action/action_carreras.php').then(res => res.json())
|
||||
this.materias = await fetch('action/action_materias.php').then(res => res.json())
|
||||
this.usuarios = await fetch('action/usuarios.php').then(res => res.json())
|
||||
}
|
||||
import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'
|
||||
type Puesto = {
|
||||
puesto_id: number,
|
||||
nombre: string,
|
||||
facultad_id: number,
|
||||
}
|
||||
|
||||
type Carrera = {
|
||||
carrera_id: number;
|
||||
carrera_nombre: string;
|
||||
clave_carrera: string;
|
||||
}
|
||||
|
||||
type Materia = {
|
||||
carrera_id: number;
|
||||
clave_materia: string;
|
||||
materia_id: number;
|
||||
materia_nombre: string;
|
||||
}
|
||||
|
||||
type Usuario = {
|
||||
usuario_clave: string;
|
||||
usuario_id: number;
|
||||
usuario_nombre: string;
|
||||
}
|
||||
|
||||
const app = createApp({
|
||||
message: null,
|
||||
puestos: [] as Puesto[],
|
||||
carreras: [] as Carrera[],
|
||||
materias: [] as Materia[],
|
||||
usuarios: [] as Usuario[],
|
||||
|
||||
async nuevoPuesto(nuevoPuesto: string) {
|
||||
try {
|
||||
const res = await fetch('action/puesto.php', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
puesto_nombre: nuevoPuesto
|
||||
})
|
||||
})
|
||||
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}`)
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
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',
|
||||
body: JSON.stringify({
|
||||
puesto_id,
|
||||
materias: materias.map(m => m.materia_id),
|
||||
usuario_id
|
||||
})
|
||||
})
|
||||
const data = await res.json()
|
||||
this.message = data.msg;
|
||||
|
||||
// after 3 seconds, remove the message
|
||||
setTimeout(() => {
|
||||
this.message = null
|
||||
}, 3000)
|
||||
} catch (error) {
|
||||
alert(`Error: ${error}`)
|
||||
}
|
||||
},
|
||||
|
||||
async mounted() {
|
||||
this.puestos = await fetch('action/puesto.php').then(res => res.json())
|
||||
this.carreras = await fetch('action/action_carreras.php').then(res => res.json())
|
||||
this.materias = await fetch('action/action_materias.php').then(res => res.json())
|
||||
this.usuarios = await fetch('action/usuarios.php').then(res => res.json())
|
||||
}
|
||||
}).mount('#app')
|
||||
Reference in New Issue
Block a user