feat: integración de SIU Guaraní, auto-completado y rediseño en grilla de recorrido

This commit is contained in:
Carlos Tello
2026-03-29 03:06:36 -03:00
parent ca33ed19ce
commit 490bf2355b
8 changed files with 1210 additions and 583 deletions
+66
View File
@@ -0,0 +1,66 @@
import { Injectable } from '@angular/core';
import { CapacitorHttp, HttpResponse } from '@capacitor/core';
@Injectable({ providedIn: 'root' })
export class SiuService {
private readonly BASE_URL = 'https://siuuniciu.eastus2.cloudapp.azure.com/caba';
async getAcademicHistory(dni: string, pass: string, carreraId: string = '30'): Promise<any[]> {
try {
// 1. LOGIN POST
const loginData = `usuario=${dni}&password=${pass}&login=Ingresar`;
await CapacitorHttp.post({
url: `${this.BASE_URL}/acceso?auth=form`,
data: loginData,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
// 2. CAMBIO DE CARRERA (Simulando el GET que capturamos)
// Esto es lo que destrabó el cuello de botella
await CapacitorHttp.get({
url: `${this.BASE_URL}/acceso/cambiar_carrera?id=${carreraId}&op=inicio_alumno`,
});
// 3. OBTENER PLAN DE ESTUDIO
const resPlan: HttpResponse = await CapacitorHttp.get({
url: `${this.BASE_URL}/plan_estudio`,
});
// 4. PARSEO DEL JSON EMBEBIDO
// Buscamos el bloque on_arrival que contiene "info_plan"
const rawHtml = resPlan.data;
const regex = /on_arrival\((\{.*?"id":"info_plan".*?\})\);/s;
const match = rawHtml.match(regex);
if (match && match[1]) {
const jsonData = JSON.parse(match[1]);
const contentHtml = jsonData.content;
return this.parseHtmlSubjects(contentHtml);
}
throw new Error('No se encontró el bloque de materias');
} catch (error) {
console.error('Error SIU:', error);
throw error;
}
}
private parseHtmlSubjects(html: string): any[] {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const rows = Array.from(doc.querySelectorAll('tr'));
return rows.map(row => {
const cols = row.querySelectorAll('td');
if (cols.length >= 6) {
const nombreRaw = cols[0].textContent?.trim() || '';
return {
nombre: nombreRaw.split(' (')[0],
nota: cols[4].textContent?.trim(),
origen: cols[5].textContent?.trim()
};
}
return null;
}).filter(item => item && item.nombre);
}
}