auditoría.ts 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import { createApp, reactive } from 'https://unpkg.com/petite-vue?module'
  2. type Registro = {
  3. carrera: string;
  4. carrera_id: number;
  5. comentario: null;
  6. dia: string;
  7. duracion: string;
  8. duracion_id: number;
  9. estado_supervisor_id: number;
  10. facultad: string;
  11. facultad_id: number;
  12. horario_dia: number;
  13. horario_fin: string;
  14. horario_grupo: string;
  15. horario_hora: string;
  16. horario_id: number;
  17. materia: string;
  18. materia_id: number;
  19. nombre: string;
  20. periodo: string;
  21. periodo_id: number;
  22. profesor_clave: string;
  23. profesor_correo: string;
  24. profesor_grado: null;
  25. profesor_id: number;
  26. profesor_nombre: string;
  27. registro_fecha: null;
  28. registro_fecha_ideal: Date;
  29. registro_fecha_supervisor: Date;
  30. registro_id: number;
  31. registro_justificada: null;
  32. registro_retardo: null;
  33. salon: string;
  34. salon_id: number;
  35. supervisor_id: number;
  36. }
  37. type Estado = {
  38. color: string;
  39. icon: string;
  40. estado_supervisor_id: number;
  41. }
  42. type Facultad = {
  43. clave_dependencia: string;
  44. facultad_id: number;
  45. facultad_nombre: string;
  46. }
  47. type Bloque_Horario = {
  48. hora_fin: string;
  49. hora_inicio: string;
  50. id: number;
  51. selected: boolean;
  52. }
  53. type Filter = {
  54. type: string;
  55. value: string;
  56. icon: string;
  57. field: string;
  58. label: string;
  59. }
  60. const store = reactive({
  61. loading: false,
  62. current: {
  63. comentario: '',
  64. clase_vista: null,
  65. empty: '',
  66. },
  67. facultades: {
  68. data: [] as Facultad[],
  69. async fetch() {
  70. this.data = [] as Facultad[]
  71. const res = await fetch('action/action_facultad.php')
  72. this.data = await res.json()
  73. },
  74. },
  75. filters: {
  76. facultad_id: null,
  77. fecha: null,
  78. fecha_inicio: null,
  79. fecha_fin: null,
  80. profesor: null,
  81. bloque_horario: null,
  82. estados: [],
  83. switchFecha: false,
  84. switchFechas() {
  85. $(function () {
  86. store.filters.fecha_inicio = store.filters.fecha_fin = store.filters.fecha = null
  87. $("#fecha, #fecha_inicio, #fecha_fin").datepicker({
  88. minDate: -3,
  89. maxDate: new Date(),
  90. dateFormat: "yy-mm-dd",
  91. showAnim: "slide",
  92. });
  93. const fecha = $("#fecha"), inicio = $("#fecha_inicio"), fin = $("#fecha_fin")
  94. inicio.on("change", function () {
  95. store.filters.fecha_inicio = inicio.val()
  96. fin.datepicker("option", "minDate", inicio.val());
  97. });
  98. fin.on("change", function () {
  99. store.filters.fecha_fin = fin.val()
  100. inicio.datepicker("option", "maxDate", fin.val());
  101. });
  102. fecha.on("change", function () {
  103. store.filters.fecha = fecha.val()
  104. });
  105. });
  106. }
  107. },
  108. estados: {
  109. data: [] as Estado[],
  110. async fetch() {
  111. this.data = [] as Estado[]
  112. const res = await fetch('action/action_estado_supervisor.php')
  113. this.data = await res.json()
  114. },
  115. getEstado(id: number): Estado {
  116. return this.data.find((estado: Estado) => estado.estado_supervisor_id === id)
  117. },
  118. printEstados() {
  119. if (store.filters.estados.length > 0)
  120. document.querySelector('#estados')!.innerHTML = store.filters.estados.map((estado: number) =>
  121. `<span class="mx-2 badge badge-${store.estados.getEstado(estado).estado_color}">
  122. <i class="${store.estados.getEstado(estado).estado_icon}"></i> ${store.estados.getEstado(estado).nombre}
  123. </span>`
  124. ).join('')
  125. else
  126. document.querySelector('#estados')!.innerHTML = `Todos los registros`
  127. }
  128. },
  129. bloques_horario: {
  130. data: [] as Bloque_Horario[],
  131. async fetch() {
  132. this.data = [] as Bloque_Horario[]
  133. const res = await fetch('action/action_grupo_horario.php')
  134. this.data = await res.json()
  135. if (this.data.every((bloque: Bloque_Horario) => !bloque.selected))
  136. this.data[0].selected = true
  137. },
  138. },
  139. toggle(arr: any, element: any) {
  140. const newArray = arr.includes(element) ? arr.filter((item: any) => item !== element) : [...arr, element]
  141. // if all are selected, then unselect all
  142. if (newArray.length === this.estados.data.length) return []
  143. return newArray
  144. },
  145. })
  146. declare var $: any
  147. type Profesor = {
  148. profesor_id: number;
  149. profesor_nombre: string;
  150. profesor_correo: string;
  151. profesor_clave: string;
  152. profesor_grado: string;
  153. }
  154. createApp({
  155. store,
  156. get clase_vista() {
  157. return store.current.clase_vista
  158. },
  159. registros: {
  160. data: [] as Registro[],
  161. async fetch() {
  162. this.loading = true
  163. this.data = [] as Registro[]
  164. const res = await fetch('action/action_auditoria.php')
  165. this.data = await res.json()
  166. this.loading = false
  167. },
  168. invertir() {
  169. this.data = this.data.reverse()
  170. },
  171. mostrarComentario(registro_id: number) {
  172. const registro = this.data.find((registro: Registro) => registro.registro_id === registro_id)
  173. store.current.comentario = registro.comentario
  174. $('#ver-comentario').modal('show')
  175. },
  176. get relevant() {
  177. /*
  178. facultad_id: null,
  179. fecha: null,
  180. fecha_inicio: null,
  181. fecha_fin: null,
  182. profesor: null,
  183. asistencia: null,
  184. estado_id: null,
  185. if one of the filters is null, then it is not relevant
  186. */
  187. const filters = Object.keys(store.filters).filter((filtro) => store.filters[filtro] || store.filters[filtro]?.length > 0)
  188. return this.data.filter((registro: Registro) => {
  189. return filters.every((filtro) => {
  190. switch (filtro) {
  191. case 'fecha':
  192. return registro.registro_fecha_ideal === store.filters[filtro];
  193. case 'fecha_inicio':
  194. return registro.registro_fecha_ideal >= store.filters[filtro];
  195. case 'fecha_fin':
  196. return registro.registro_fecha_ideal <= store.filters[filtro];
  197. case 'profesor':
  198. const textoFiltro = store.filters[filtro].toLowerCase();
  199. if (/^\([^)]+\)\s[\s\S]+$/.test(textoFiltro)) {
  200. const clave = registro.profesor_clave.toLowerCase();
  201. const filtroClave = textoFiltro.match(/\((.*?)\)/)?.[1];
  202. console.log(clave, filtroClave);
  203. return clave.includes(filtroClave);
  204. } else {
  205. const nombre = registro.profesor_nombre.toLowerCase();
  206. return nombre.includes(textoFiltro);
  207. }
  208. case 'facultad_id':
  209. return registro.facultad_id === store.filters[filtro];
  210. case 'estados':
  211. if (store.filters[filtro].length === 0) return true;
  212. return store.filters[filtro].includes(registro.estado_supervisor_id);
  213. case 'bloque_horario':
  214. const bloque = store.bloques_horario.data.find((bloque: Bloque_Horario) => bloque.id === store.filters[filtro]) as Bloque_Horario;
  215. return registro.horario_hora <= bloque.hora_fin && registro.horario_fin >= bloque.hora_inicio;
  216. default:
  217. return true;
  218. }
  219. })
  220. })
  221. },
  222. async descargar() {
  223. if (this.relevant.length === 0) return;
  224. const res = await fetch('export/supervisor_excel.php', {
  225. method: 'POST',
  226. headers: {
  227. 'Content-Type': 'application/json'
  228. },
  229. body: JSON.stringify(this.relevant)
  230. });
  231. const blob = await res.blob();
  232. (window as any).saveAs(blob, `auditoria_${new Date().toISOString().slice(0, 10)}.xlsx`);
  233. }
  234. },
  235. get profesores() {
  236. return this.registros.data.map((registro: Registro) => (
  237. {
  238. profesor_id: registro.profesor_id,
  239. profesor_nombre: registro.profesor_nombre,
  240. profesor_correo: registro.profesor_correo,
  241. profesor_clave: registro.profesor_clave,
  242. profesor_grado: registro.profesor_grado,
  243. }
  244. )).sort((a: Profesor, b: Profesor) =>
  245. a.profesor_nombre.localeCompare(b.profesor_nombre)
  246. )
  247. },
  248. async mounted() {
  249. await this.registros.fetch()
  250. await store.facultades.fetch()
  251. await store.estados.fetch()
  252. await store.bloques_horario.fetch()
  253. store.filters.bloque_horario = store.bloques_horario.data.find((bloque: Bloque_Horario) => bloque.selected)?.id
  254. store.filters.switchFechas()
  255. }
  256. }).mount('#app')