From e862fcb0c136b32b46b225632337a8cccaac210b Mon Sep 17 00:00:00 2001 From: Fernando Date: Fri, 12 Oct 2018 10:50:46 -0500 Subject: [PATCH] Funcionalidad Basica --- .gitignore | 2 + data.json | 278 +++++++++++++++++++++++++ index.html | 149 ++++++++++++++ process.js | 513 ++++++++++++++++++++++++++++++++++++++++++++++ process.min.js | 1 + raw3anioData.json | 147 +++++++++++++ rawJsonCreator.js | 66 ++++++ style.css | 161 +++++++++++++++ 8 files changed, 1317 insertions(+) create mode 100644 .gitignore create mode 100644 data.json create mode 100644 index.html create mode 100644 process.js create mode 100644 process.min.js create mode 100644 raw3anioData.json create mode 100644 rawJsonCreator.js create mode 100644 style.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf7e091 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/idea +/node_modules \ No newline at end of file diff --git a/data.json b/data.json new file mode 100644 index 0000000..bc24a13 --- /dev/null +++ b/data.json @@ -0,0 +1,278 @@ +{ + "1er_anio": { + "Calculo 1->C1V": { + "Teoria": { + "Grupo A": { + "Docente": "Doris Tupacyupanqui", "Horas": ["Ma1130", "Ma1220", "Ma1310", "Mi0850", "Mi0940", "Vi0700", "Vi0750"] + } + , + "Grupo B": { + "Docente": "Pablo Quicaño", "Horas": ["Lu1640", "Ma1740", "Ma1830", "Ma1920", "Ju1740", "Ju1920", "Ju1830"] + } + } + } + , + "Estructuras Discretas 2->ED2": { + "Teoria": { + "Grupo A": { + "Docente": "Olha Sharhorodska", "Horas": ["Mi1220", "Mi1310", "Ju1220", "Ju1310"] + } + , + "Grupo B": { + "Docente": "Olha Sharhorodska", "Horas": ["Mi1400", "Mi1450", "Vi1550", "Vi1640"] + } + } + } + , + "Programacion Web 1->PW1": { + "Teoria": { + "Grupo A": { + "Docente": "Richart Escobedo", "Horas": ["Ma0940", "Ma1040"] + } + , + "Grupo B": { + "Docente": "Carlo Corrales", "Horas": ["Lu1220", "Lu1310"] + } + } + , + "Laboratorio": { + "Grupo A": { + "Docente": "Richart Escobedo", "Horas": ["Ma1130", "Ma1220", "Mi0850", "Mi0940"] + } + , + "Grupo B": { + "Docente": "Carlo Corrales", "Horas": ["Lu1400", "Lu1450", "Mi1550", "Mi1640"] + } + , + "Grupo C": { + "Docente": "Richart Escobedo", "Horas": ["Ma1550", "Ma1640", "Lu1740", "Lu1830"] + } + , + "Grupo D": { + "Docente": "Carlo Corrales", "Horas": ["Lu1740", "Lu1830", "Mi1740", "Mi1830"] + } + , + "Grupo E": { + "Docente": "Carlo Corrales", "Horas": ["Lu1550", "Lu1640", "Ma1740", "Ma1830"] + } + } + } + , + "Fundamentos de Programacion 2->FP2": { + "Teoria": { + "Grupo A": { + "Docente": "Marco Aedo", "Horas": ["Lu0850", "Lu0940", "Vi1220", "Vi1310"] + } + , + "Grupo B": { + "Docente": "Marco Aedo", "Horas": ["Ju1550", "Ju1640", "Vi1400", "Vi1450"] + } + } + , + "Laboratorio": { + "Grupo A": { + "Docente": "Marco Aedo", "Horas": ["Lu1040", "Lu1130", "Ju1040", "Ju1130"] + } + , + "Grupo B": { + "Docente": "Marco Aedo", "Horas": ["Ju1400", "Ju1450", "Vi1550", "Vi1640"] + } + , + "Grupo C": { + "Docente": "Marco Aedo", "Horas": ["Ju0850", "Ju0940", "Vi1040", "Vi1130"] + } + , + "Grupo D": { + "Docente": "Karim Guevara", "Horas": ["Vi0850", "Vi0940", "Ju0850", "Ju0940"] + } + , + "Grupo E": { + "Docente": "Ernesto Suarez", "Horas": ["Mi1040", "Mi1130", "Ju0700", "Ju0750"] + } + } + } + , + "Comunicacion Integral->CI": { + "Teoria": { + "Grupo A": { + "Docente": "?", "Horas": ["Lu0700", "Lu0750", "Mi0700", "Mi0750"] + } + , + "Grupo B": { + "Docente": "?", "Horas": ["Ma1400", "Ma1450", "Ju1400", "Ju1450"] + } + } + } + , + "Realidad Nacional->RN": { + "Teoria": { + "Grupo A": { + "Docente": "?", "Horas": ["Ma0700", "Ma0750", "Ma0850"] + } + , + "Grupo B": { + "Docente": "?", "Horas": ["Lu1400", "Lu1450", "Lu1550"] + } + } + } + }, + "2do_anio" : { + "Ecologia y Medio Ambiente->ECA" : { + "Teoria" : { + "Grupo A" : { + "Docente" : "?", "Horas" : ["Lu0700", "Lu0750", "Lu0850"] + }, + "Grupo B" : { + "Docente" : "?", "Horas" : ["Mi1400", "Mi1450", "Mi1550"] + } + } + }, + "Estadistica y Matematica->EMAT" : { + "Teoria" : { + "Grupo A" : { + "Docente" : "Antonia Quispe", "Horas" : ["Mi0700","Mi0750","Vi0850","Vi0940"] + }, + "Grupo B" : { + "Docente" : "Esther Yanapa", "Horas" : ["Ma1550","Ma1640","Ju1830","Ju1920"] + } + }, + "Laboratorio" : { + "Grupo A" : { + "Docente" : "Antonia Quispe", "Horas" : ["Mi0850","Mi0940"] + }, + "Grupo B" : { + "Docente" : "Esther Yanapa", "Horas" : ["Ma1740","Ma1830"] + }, + "Grupo C" : { + "Docente" : "Esther Yanapa", "Horas" : ["Ma0700","Ma0750"] + }, + "Grupo D" : { + "Docente" : "Esther Yanapa", "Horas" : ["Ma0850","Ma0940"] + } + } + }, + "Arquitectura de Computadoras->AC" : { + "Teoria" : { + "Grupo A" : { + "Docente" : "Pedro Rodriguez Gonzales", "Horas" : ["Ju0850","Ju0940","Vi1040"] + }, + "Grupo B" : { + "Docente" : "Pedro Rodriguez Gonzales", "Horas" : ["Ju1550","Ju1640","Ju1740"] + } + }, + "Laboratorio" : { + "Grupo A" : { + "Docente" : "Pedro Rodriguez Gonzales", "Horas" : ["Ju0700","Ju0750"] + }, + "Grupo B" : { + "Docente" : "Pedro Rodriguez Gonzales", "Horas" : ["Vi1220","Vi1310"] + }, + "Grupo C" : { + "Docente" : "Pedro Rodriguez Gonzales", "Horas" : ["Vi0700","Vi0750"] + }, + "Grupo D" : { + "Docente" : "Pedro Rodriguez Gonzales", "Horas" : ["Vi0850","Vi0940"] + } + } + }, + "Metodos de Investigacion y Redaccion->MIR" : { + "Teoria" : { + "Grupo A" : { + "Docente" : "Jesus Zuniga Cueva", "Horas" : ["Mi1040","Mi1130","Mi1220"] + }, + "Grupo B" : { + "Docente" : "Jesus Zuniga Cueva", "Horas" : ["Lu1220","Lu1310","Mi1310"] + }, + "Grupo C" : { + "Docente" : "Jesus Zuniga Cueva", "Horas" : ["Ma1040","Ma1130","Ma1220"] + } + } + }, + "Interaccion Humano Computador->IHC" : { + "Teoria" : { + "Grupo A" : { + "Docente" : "Olha Sharhorodska", "Horas" : ["Ju1040","Ju1130","Vi1220","Vi1310"] + }, + "Grupo B" : { + "Docente" : "Olha Sharhorodska", "Horas" : ["Ju1400","Ju1450","Vi1400","Vi1450"] + } + }, + "Laboratorio" : { + "Grupo A" : { + "Docente" : "Richart Escobedo", "Horas" : ["Lu1040","Lu1130"] + }, + "Grupo B" : { + "Docente" : "Richart Escobedo", "Horas" : ["Lu1550","Lu1640"] + }, + "Grupo C" : { + "Docente" : "Richart Escobedo", "Horas" : ["Ma1740","Ma1830"] + }, + "Grupo D" : { + "Docente" : "Juan Ramirez Ticona", "Horas" : ["Lu1550","Lu1640"] + } + } + }, + "Enfoque Empresarial->EE" : { + "Teoria" : { + "Grupo A" : { + "Docente" : "Juan C. Juarez Bueno", "Horas" : ["Lu0940","Ma0850","Ma0940","Ju1220","Ju1310"] + }, + "Grupo B" : { + "Docente" : "Juan C. Juarez Bueno", "Horas" : ["Ma1310","Ma1400","Ma1450","Vi1550","Vi1640"] + } + } + }, + "Analisis y Disenio de Algoritmos->ADA" : { + "Teoria" : { + "Grupo A" : { + "Docente" : "Atencio Torres Carlos", "Horas" : ["Lu1400","Lu1450","Vi0700","Vi0750"] + } , + "Grupo B" : { + "Docente" : "Atencio Torres Carlos", "Horas" : ["Lu1740","Lu1830","Vi1740","Vi1830"] + } + }, + "Laboratorio" : { + "Grupo A" : { + "Docente" : "Christian Portugal", "Horas" : ["Lu1400","Lu1450"] + }, + "Grupo B" : { + "Docente" : "Christian Portugal", "Horas" : ["Mi1550","Mi1640"] + }, + "Grupo C" : { + "Docente" : "Christian Portugal", "Horas" : ["Mi1740","Mi1830"] + } + } + } + }, + "3er_anio" : { + "Construccion de Software->CS" : { + + }, + "Redes y Comunicacion de Datos-> RCD" : { + + }, + "Tecnologia de Objetos->TO":{ + + } + }, + "4to_anio" : { + "Aspectos Formales de Verif. y Esp.->AFVE" : { + + }, + "Gestion de Proyectos de Software->GPS" : { + + } + }, + "5to_anio" : { + "Topicos Avanzados en Ing. de Software->TAIS" : { + + }, + "Practicas Pre-Profesionales->PPP" : { + "Teoria" : { + "Grupo A" : { + "Docente" : "Ernesto Suarez", "Horas" : ["Ma1550","Ma1640","Mi0700","Mi0750","Ju0850","Ju0940"] + } + } + } + } +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..efc72ef --- /dev/null +++ b/index.html @@ -0,0 +1,149 @@ + + + + Sistema de Horarios + + + + + + + + + +
+ +
+ + Un sistema para la creación de horarios básico. La propia UNSA debería tener uno de estos... +
+ Puedes usar nombres completos de los cursos (no lo recomiendo) + o activar el modo nocturno.
+
+ Parametros:
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ Mi horario: +
+ keyboard_arrow_down +
+
+
+
+
+ +
+ Primer Año +
+ keyboard_arrow_down +
+
+
+
+
+ +
+ Segundo Año +
+ keyboard_arrow_down +
+
+
+
+
+ +
+ Tercer Año +
+ keyboard_arrow_down +
+
+
+
+
+ +
+ Cuarto Año +
+ keyboard_arrow_down +
+
+
+
+
+ +
+ Quinto Año +
+ keyboard_arrow_down +
+
+
+
+
+ +
+ +
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/process.js b/process.js new file mode 100644 index 0000000..a4898d8 --- /dev/null +++ b/process.js @@ -0,0 +1,513 @@ +let laData; + +let datosUsuario = { + ocultarCursosSolapan: true, + escribirCursosSeleccionados: true +}; + +let ajax = new XMLHttpRequest(); + +let miHorario = {}; + +ajax.onreadystatechange = () => { + if (ajax.status === 200 && ajax.readyState === 4) { + laData = JSON.parse(ajax.responseText); + + crearTablas(0, document.getElementById("Horario0anio")); + crearTablas(1, document.getElementById("Horario1anio")); + crearTablas(2, document.getElementById("Horario2anio")); + crearTablas(3, document.getElementById("Horario3anio")); + crearTablas(4, document.getElementById("Horario4anio")); + crearTablas(5, document.getElementById("Horario5anio")); + + ocultarTabla(0); + /*ocultarTabla(1);*/ + ocultarTabla(2); + ocultarTabla(3); + ocultarTabla(4); + ocultarTabla(5); + + crearDatos(laData, false); + } +}; + +ajax.open("GET", "./data.json", true); +ajax.send(); + +function crearDatos(data, nombreCompleto, ...limpiar) { + + if (data === undefined) { + data = laData; + } + + if (limpiar !== undefined) { + for (const a in limpiar) { + limpiarTabla(a); + limpiarDescripciones(a); + } + } + + for (let anio in data) { + let anioData = data[anio]; + + for (let curso in anioData) { + let cursoData = anioData[curso]; + + if (cursoData["oculto"] !== undefined && cursoData["oculto"] === true) continue; + + let cursoDataDiv = document.createElement("div"); + cursoDataDiv.className = "cursoDataDiv descrCurso--Light--On"; + cursoDataDiv.setAttribute("req",""); + + let nombreCurso = document.createElement("span"); + nombreCurso.style.fontWeight = "bold"; + nombreCurso.appendChild(document.createTextNode(curso.substring(0, curso.search("->")) + " - " + curso.substring(curso.search("->") + 2) + " ")); + cursoDataDiv.appendChild(nombreCurso); + + let input = document.createElement("input"); + input.type = "checkbox"; + input.checked = "checked"; + input.addEventListener("click", () => { + ocultarCurso(input.checked, cursoDataDiv, (curso.substring(curso.search("->") + 2)), anio) + }); + cursoDataDiv.appendChild(input); + + + for (let variante in cursoData) { + + if (variante === "oculto") continue; + + cursoDataDiv.appendChild(document.createElement("br")); + let span = document.createElement("span"); + span.innerText = variante + " = "; + cursoDataDiv.appendChild(span); + + /* Crea temporalmente un objeto para manejar los Grupos y Profesores */ + let gruposYProf = {}; + + let varianteData = cursoData[variante]; + for (let grupo in varianteData) { + + let grupoData = varianteData[grupo]; + + /* Inicializa el objeto */ + if (gruposYProf[grupoData["Docente"]] === undefined) { + gruposYProf[grupoData["Docente"]] = grupo.substring(grupo.indexOf(" ") + 1); + } else { + gruposYProf[grupoData["Docente"]] += "," + grupo.substring(grupo.indexOf(" ") + 1); + } + + /* NUEVO ESTANDAR PARA LOS DIV: + * En vez de que el DIV tenga ID 1er_anioLu0700 + * se reemplazará por Lu07001er_anio + * basicamente para evitar problemas con el DOM.*/ + for (let horaIndex in grupoData["Horas"]) { + let hora = grupoData["Horas"][horaIndex]; + let elDiv = document.getElementById(hora + anio); + + /* -> C1VTeoriaA1er_anio */ + let className = (curso.substring(curso.search("->") + 2)) + variante + (grupo.substring(grupo.indexOf(" ") + 1)) + anio; + + /* -> C1V1er_anio */ + let classGenerica = (curso.substring(curso.search("->") + 2)) + anio; + cursoDataDiv.id = `descr${classGenerica}`; + + /* -> C1V1er_anio */ + let classNV = (curso.substring(curso.search("->") + 2)) + variante + anio; + + let laData = document.createElement("div"); + laData.className = "nombreCursoTeoriaLight dropdown " + className + " " + classGenerica + " " + classNV; + laData.addEventListener("mouseover", () => { + cambiarBack(className, true) + }); + laData.addEventListener("mouseout", () => { + cambiarBack(className, false) + }); + + let laInnerData = document.createElement("div"); + laInnerData.className = "dropdown-content"; + let nombreCurso = document.createElement("span"); + nombreCurso.style.fontWeight = "bold"; + laInnerData.appendChild(nombreCurso); + laInnerData.appendChild(document.createElement("hr")); + + if (variante === "Laboratorio") { + cursoDataDiv.setAttribute("req",cursoDataDiv.getAttribute("req") + "L"); + + if (nombreCompleto) { + let labI = document.createElement("span"); + laData.className = laData.className.replace(/Teoria/,"Lab"); + labI.appendChild(document.createTextNode(curso.substring(0, curso.search("->")) + + grupo.substring(grupo.search(" ")) + " (L)")); + laData.appendChild(labI); + + nombreCurso.innerText = curso.substring(0, curso.search("->")); + + } else { + let labI = document.createElement("span"); + laData.className = laData.className.replace(/Teoria/,"Lab"); + labI.appendChild(document.createTextNode(curso.substring(curso.search("->") + 2) + + grupo.substring(grupo.search(" ")) + " (L)")); + laData.appendChild(labI); + + nombreCurso.innerText = curso.substring(0, curso.search("->")); + + } + laInnerData.appendChild(document.createTextNode(grupo + " (Lab)")); + } + else { + cursoDataDiv.setAttribute("req",cursoDataDiv.getAttribute("req") + "T"); + + if (nombreCompleto) { + + laData.appendChild(document.createTextNode(curso.substring(0, curso.search("->")) + + grupo.substring(grupo.search(" ")))); + + nombreCurso.innerText = curso.substring(0, curso.search("->")); + + } else { + + laData.appendChild(document.createTextNode(curso.substring(curso.search("->") + 2) + + grupo.substring(grupo.search(" ")))); + + nombreCurso.innerText = curso.substring(0, curso.search("->")); + + } + laInnerData.appendChild(document.createTextNode(grupo)); + } + + laInnerData.appendChild(document.createElement("br")); + laInnerData.appendChild(document.createTextNode(grupoData["Docente"])); + + if (anio.substring(0, 1) !== "0") { + laInnerData.appendChild(document.createElement("hr")); + let linkParaAnadir = document.createElement("span"); + linkParaAnadir.style.textDecoration = "underline"; + linkParaAnadir.style.color = "blue"; + linkParaAnadir.style.cursor = "pointer"; + linkParaAnadir.appendChild(document.createTextNode("Añadir a mi Horario")); + linkParaAnadir.addEventListener("click", () => { + anadirAMiHorario(anio, curso, variante, grupo) + }); + laInnerData.appendChild(linkParaAnadir); + } + + laData.appendChild(laInnerData); + + let texto = document.createTextNode(" | "); + + try { + elDiv.appendChild(laData); + elDiv.appendChild(texto); + } catch (e) { + console.log("El Div " + hora + anio + " no existe | " + curso + " " + variante + " " + + grupo + "\n\n" + e.stack); + } + + } + } + + for (let prof in gruposYProf) { + let data = gruposYProf[prof]; + let datos = " (" + data + ") "; + + let span2 = document.createElement("span"); + span2.innerText = datos + prof + ","; + + span.appendChild(span2); + } + + } + + document.getElementById("Horario" + anio.substring(0, 1) + "anio").appendChild(cursoDataDiv); + } + + } + + //modoNocturno(); +} + +function limpiarTabla(num) { + let rows = document.querySelector("#tablaHorario" + num + "anio").rows; + + for (let row of rows) { + for (let cell of row.cells) { + if (cell.id !== "") { + cell.innerHTML = ""; + } + } + } + +} + +function limpiarDescripciones(num) { + let mayorDiv = document.getElementById("Horario" + num + "anio"); + let valores = mayorDiv.children; + for (let a = 0; a < valores.length; a++) { + let node = valores[a]; + if (/cursoDataDiv/.test(node.className)) { + mayorDiv.removeChild(node); + a--; + } + } +} + +function ocultarTabla(num) { + let section = document.getElementById("Horario" + num + "anio"); + let isCollapsed = section.getAttribute('data-collapsed') === 'true'; + + if (isCollapsed) { + expandSection(section); + section.setAttribute('data-collapsed', 'false'); + } else { + collapseSection(section); + } +} + +function cambiarBack(nombreClase, paraAplicar) { + let data = document.querySelectorAll("." + nombreClase); + if (paraAplicar) { + for (let a = 0; a < data.length; a++) { + data[a].style.color = "black"; + let temp = data[a].parentNode; + chechAttribute(temp, false, 0); + } + } else { + for (let a = 0; a < data.length; a++) { + data[a].style = ""; + let temp = data[a].parentNode; + chechAttribute(temp, false, -1, true) + } + } +} + +function collapseSection(element) { + /* get the height of the element's inner content, regardless of its actual size*/ + let sectionHeight = element.scrollHeight; + + /* temporarily disable all css transitions*/ + let elementTransition = element.style.transition; + element.style.transition = ''; + + /* on the next frame (as soon as the previous style change has taken effect), + // explicitly set the element's height to its current pixel height, so we + // aren't transitioning out of 'auto'*/ + requestAnimationFrame(function () { + element.style.height = sectionHeight + 'px'; + element.style.transition = elementTransition; + + /* on the next frame (as soon as the previous style change has taken effect), + have the element transition to height: 0*/ + requestAnimationFrame(function () { + element.style.height = 0 + 'px'; + }); + }); + + /* mark the section as "currently collapsed"*/ + element.setAttribute('data-collapsed', 'true'); +} + +function expandSection(element) { + /* get the height of the element's inner content, regardless of its actual size*/ + let sectionHeight = element.scrollHeight; + + /* have the element transition to the height of its inner content*/ + element.style.height = sectionHeight + 'px'; + + /* when the next css transition finishes (which should be the one we just triggered)*/ + element.addEventListener('transitionend', function (e) { + // remove this event listener so it only gets triggered once + element.removeEventListener('transitionend', arguments.callee); + + /* remove "height" from the element's inline styles, so it can return to its initial value*/ + element.style.height = null; + }); + + /* mark the section as "currently not collapsed"*/ + element.setAttribute('data-collapsed', 'false'); +} + +function anadirAMiHorario(anio, curso, variante, grupo) { + + const idCurso = "descr" + (curso.substring(curso.search("->") + 2)) + anio; + + /* Si aun no se creo el horario */ + if (miHorario["0_anio"] === undefined) { + miHorario["0_anio"] = {}; + } + + /* Si el curso a añadir no existe */ + if (miHorario["0_anio"][curso] === undefined) { + miHorario["0_anio"][curso] = JSON.parse("{\"" + variante + "\" : { \"" + grupo + "\" : {}}}"); + miHorario["0_anio"][curso][variante][grupo] = laData[anio][curso][variante][grupo]; + reservarCeldas(variante, idCurso, ...(miHorario["0_anio"][curso][variante][grupo]["Horas"])); + } + /* El curso a añadir si existe */ + else { + /* El curso a añadir existe, pero no la variante(Teoria/Lab) */ + if (miHorario["0_anio"][curso][variante] === undefined) { + miHorario["0_anio"][curso][variante] = JSON.parse("{ \"" + grupo + "\" : {}}"); + miHorario["0_anio"][curso][variante][grupo] = laData[anio][curso][variante][grupo]; + reservarCeldas(variante, idCurso, ...(miHorario["0_anio"][curso][variante][grupo]["Horas"])); + } + /* El curso y la variante existen. Sospechoso...*/ + else { + /* El curso y la variante existen, pero no el grupo. ¿Quieres añadir otro grupo? Que extraño...*/ + if (miHorario["0_anio"][curso][variante][grupo] === undefined && confirm("¿Quieres añadir otro grupo de este curso?")) { + miHorario["0_anio"][curso][variante][grupo] = laData[anio][curso][variante][grupo]; + reservarCeldas(undefined, undefined, ...(miHorario["0_anio"][curso][variante][grupo]["Horas"])); + } + /*El curso, la variante y el grupo existen. ¿Quieres añadir un curso duplicado? Nope*/ + else { + alert("Este curso ya existe."); + } + } + } + crearDatos(miHorario, false, 0); +} + +function reservarCeldas(variante, idCurso, ...id) { + if (variante !== undefined && idCurso !== undefined) { + console.log(idCurso); + const elem = document.getElementById(idCurso); + elem.setAttribute(variante,"true"); + let condicion = false; + if (/T/.test(elem.getAttribute("req"))){ + if (/L/.test(elem.getAttribute("req"))){ + condicion = elem.getAttribute("Teoria") === "true" && elem.getAttribute("Laboratorio") === "true"; + } else { + condicion = elem.getAttribute("Teoria") === "true"; + } + } else if (/L/.test(elem.getAttribute("req"))){ + condicion = elem.getAttribute("Laboratorio") === "true"; + } + + if (condicion){ + elem.className = elem.className.replace(/On/,"OK"); + elem.className = elem.className.replace(/Off/,"OK"); + } + } + + for (let index in id) { + let valor = id[index]; + let divs = document.querySelectorAll("." + valor); + let div; + + for (let i = 0; i < divs.length, div = divs[i]; i++) { + chechAttribute(div, true); + } + } +} + +function chechAttribute(div, set = false, offset = 0, isOnMouseUp = false) { + const COLORES = ["#ABE77E", "#ffcb6b", "#b74d33", "#ff002f", "#454545", "#454545"]; + if (div.getAttribute("hora-ocupada") === "1") { + if (set) + div.setAttribute("hora-ocupada", "2"); + div.style.backgroundColor = COLORES[1 + offset]; + } else if (div.getAttribute("hora-ocupada") === "2") { + if (set) + div.setAttribute("hora-ocupada", "3"); + div.style.backgroundColor = COLORES[2 + offset]; + } else if (div.getAttribute("hora-ocupada") === "3") { + if (set) + div.setAttribute("hora-ocupada", "4"); + div.style.backgroundColor = COLORES[3 + offset]; + } else if (!isNaN(parseInt(div.getAttribute("hora-ocupada"))) && parseInt(div.getAttribute("hora-ocupada")) > 3) { + if (set) + div.setAttribute("hora-ocupada", "5"); + div.style.backgroundColor = COLORES[4 + offset]; + } else { + if (set) + div.setAttribute("hora-ocupada", "1"); + + if (isOnMouseUp) + div.style.backgroundColor = "transparent"; + else + div.style.backgroundColor = COLORES[0]; + + } +} + +function crearTablas(anio, divDestino, + indiceArray = ["Hora", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes"], + patronHoras = ["07:00", "07:50", ["08:40"], "08:50", "09:40", ["10:30"], "10:40", + "11:30", "12:20", "13:10", "14:00", "14:50", ["15:40"], "15:50", + "16:40", ["17:30"], "17:40", "18:30", "19:20"]) { + const nomenclaturaAnios = ["0_anio", "1er_anio", "2do_anio", "3er_anio", "4to_anio", "5to_anio"]; + const nombreAnio = nomenclaturaAnios[anio]; + + let tabla = document.createElement("table"); + tabla.id = "tablaHorario" + anio + "anio"; + tabla.className = "striped"; + + let thead = document.createElement("thead"); + let tr = document.createElement("tr"); + for (let index in indiceArray) { + let valor = indiceArray[index]; + let td = document.createElement("td"); + td.innerText = valor; + tr.appendChild(td); + } + thead.appendChild(tr); + tabla.appendChild(thead); + + let tbody = document.createElement("tbody"); + for (let index in patronHoras) { + let valor = patronHoras[index]; + let tr = document.createElement("tr"); + let isHoraDescanso = false; + if (typeof valor === "object") { + valor = valor[0]; + tr.className = "trDescansoLight"; + isHoraDescanso = true; + } + + for (let i in indiceArray) { + let td = document.createElement("td"); + if (i === "0") { + td.innerText = valor; + } else if (!isHoraDescanso) { + td.id = indiceArray[i].substring(0, 2) + valor.replace(":", "") + nombreAnio; + td.className = indiceArray[i].substring(0, 2) + valor.replace(":", ""); + } + tr.appendChild(td); + } + tbody.appendChild(tr); + } + tabla.appendChild(tbody); + + divDestino.appendChild(tabla); +} + +function ocultarCurso(ocultar, div, curso, anio) { + if (ocultar) { + + div.className = div.className.replace(/Off/,"On"); + + let lista = document.querySelectorAll("." + curso + anio); + let iDiv; + for (let i = 0; i < lista.length, iDiv = lista[i]; i++) { + iDiv.style.display = "inline-block"; + } + } else { + + div.className = div.className.replace(/On/,"Off"); + + let lista = document.querySelectorAll("." + curso + anio); + console.log("Query: " + "." + curso + anio); + let iDiv; + for (let i = 0; i < lista.length; i++) { + iDiv = lista[i]; + iDiv.style.display = "none"; + } + } +} + +function ocultarVariante(ocultar, div, anio, curso, variante) { + +} + +function ocultarGrupo(ocultar, div, anio, curso, variante, grupo) { + +} \ No newline at end of file diff --git a/process.min.js b/process.min.js new file mode 100644 index 0000000..34cc130 --- /dev/null +++ b/process.min.js @@ -0,0 +1 @@ +let laData,datosUsuario={ocultarCursosSolapan:!0,escribirCursosSeleccionados:!0},ajax=new XMLHttpRequest,miHorario={};function crearDatos(e,t,...a){if(void 0===e&&(e=laData),void 0!==a)for(const e in a)limpiarTabla(e),limpiarDescripciones(e);for(let a in e){let r=e[a];for(let e in r){let o=r[e];if(void 0!==o.oculto&&!0===o.oculto)continue;let n=document.createElement("div");n.className="cursoDataDiv descrCurso--Light--On",n.setAttribute("req","");let i=document.createElement("span");i.style.fontWeight="bold",i.appendChild(document.createTextNode(e.substring(0,e.search("->"))+" - "+e.substring(e.search("->")+2)+" ")),n.appendChild(i);let l=document.createElement("input");l.type="checkbox",l.checked="checked",l.addEventListener("click",()=>{ocultarCurso(l.checked,n,e.substring(e.search("->")+2),a)}),n.appendChild(l);for(let r in o){if("oculto"===r)continue;n.appendChild(document.createElement("br"));let i=document.createElement("span");i.innerText=r+" = ",n.appendChild(i);let l={},c=o[r];for(let o in c){let i=c[o];void 0===l[i.Docente]?l[i.Docente]=o.substring(o.indexOf(" ")+1):l[i.Docente]+=","+o.substring(o.indexOf(" ")+1);for(let l in i.Horas){let c=i.Horas[l],s=document.getElementById(c+a),d=e.substring(e.search("->")+2)+r+o.substring(o.indexOf(" ")+1)+a,u=e.substring(e.search("->")+2)+a;n.id=`descr${u}`;let m=e.substring(e.search("->")+2)+r+a,p=document.createElement("div");p.className="nombreCursoTeoriaLight dropdown "+d+" "+u+" "+m,p.addEventListener("mouseover",()=>{cambiarBack(d,!0)}),p.addEventListener("mouseout",()=>{cambiarBack(d,!1)});let b=document.createElement("div");b.className="dropdown-content";let h=document.createElement("span");if(h.style.fontWeight="bold",b.appendChild(h),b.appendChild(document.createElement("hr")),"Laboratorio"===r){if(n.setAttribute("req",n.getAttribute("req")+"L"),t){let t=document.createElement("span");p.className=p.className.replace(/Teoria/,"Lab"),t.appendChild(document.createTextNode(e.substring(0,e.search("->"))+o.substring(o.search(" "))+" (L)")),p.appendChild(t),h.innerText=e.substring(0,e.search("->"))}else{let t=document.createElement("span");p.className=p.className.replace(/Teoria/,"Lab"),t.appendChild(document.createTextNode(e.substring(e.search("->")+2)+o.substring(o.search(" "))+" (L)")),p.appendChild(t),h.innerText=e.substring(0,e.search("->"))}b.appendChild(document.createTextNode(o+" (Lab)"))}else n.setAttribute("req",n.getAttribute("req")+"T"),t?(p.appendChild(document.createTextNode(e.substring(0,e.search("->"))+o.substring(o.search(" ")))),h.innerText=e.substring(0,e.search("->"))):(p.appendChild(document.createTextNode(e.substring(e.search("->")+2)+o.substring(o.search(" ")))),h.innerText=e.substring(0,e.search("->"))),b.appendChild(document.createTextNode(o));if(b.appendChild(document.createElement("br")),b.appendChild(document.createTextNode(i.Docente)),"0"!==a.substring(0,1)){b.appendChild(document.createElement("hr"));let t=document.createElement("span");t.style.textDecoration="underline",t.style.color="blue",t.style.cursor="pointer",t.appendChild(document.createTextNode("Añadir a mi Horario")),t.addEventListener("click",()=>{anadirAMiHorario(a,e,r,o)}),b.appendChild(t)}p.appendChild(b);let g=document.createTextNode(" | ");try{s.appendChild(p),s.appendChild(g)}catch(t){console.log("El Div "+c+a+" no existe | "+e+" "+r+" "+o+"\n\n"+t.stack)}}}for(let e in l){let t=" ("+l[e]+") ",a=document.createElement("span");a.innerText=t+e+",",i.appendChild(a)}}document.getElementById("Horario"+a.substring(0,1)+"anio").appendChild(n)}}}function limpiarTabla(e){let t=document.querySelector("#tablaHorario"+e+"anio").rows;for(let e of t)for(let t of e.cells)""!==t.id&&(t.innerHTML="")}function limpiarDescripciones(e){let t=document.getElementById("Horario"+e+"anio"),a=t.children;for(let e=0;e")+2)+e;void 0===miHorario["0_anio"]&&(miHorario["0_anio"]={}),void 0===miHorario["0_anio"][t]?(miHorario["0_anio"][t]=JSON.parse('{"'+a+'" : { "'+r+'" : {}}}'),miHorario["0_anio"][t][a][r]=laData[e][t][a][r],reservarCeldas(a,o,...miHorario["0_anio"][t][a][r].Horas)):void 0===miHorario["0_anio"][t][a]?(miHorario["0_anio"][t][a]=JSON.parse('{ "'+r+'" : {}}'),miHorario["0_anio"][t][a][r]=laData[e][t][a][r],reservarCeldas(a,o,...miHorario["0_anio"][t][a][r].Horas)):void 0===miHorario["0_anio"][t][a][r]&&confirm("¿Quieres añadir otro grupo de este curso?")?(miHorario["0_anio"][t][a][r]=laData[e][t][a][r],reservarCeldas(void 0,void 0,...miHorario["0_anio"][t][a][r].Horas)):alert("Este curso ya existe."),crearDatos(miHorario,!1,0)}function reservarCeldas(e,t,...a){if(void 0!==e&&void 0!==t){console.log(t);const a=document.getElementById(t);a.setAttribute(e,"true");let r=!1;/T/.test(a.getAttribute("req"))?r=/L/.test(a.getAttribute("req"))?"true"===a.getAttribute("Teoria")&&"true"===a.getAttribute("Laboratorio"):"true"===a.getAttribute("Teoria"):/L/.test(a.getAttribute("req"))&&(r="true"===a.getAttribute("Laboratorio")),r&&(a.className=a.className.replace(/On/,"OK"),a.className=a.className.replace(/Off/,"OK"))}for(let e in a){let t,r=a[e],o=document.querySelectorAll("."+r);for(let e=0;o.length,t=o[e];e++)chechAttribute(t,!0)}}function chechAttribute(e,t=!1,a=0,r=!1){const o=["#ABE77E","#ffcb6b","#b74d33","#ff002f","#454545","#454545"];"1"===e.getAttribute("hora-ocupada")?(t&&e.setAttribute("hora-ocupada","2"),e.style.backgroundColor=o[1+a]):"2"===e.getAttribute("hora-ocupada")?(t&&e.setAttribute("hora-ocupada","3"),e.style.backgroundColor=o[2+a]):"3"===e.getAttribute("hora-ocupada")?(t&&e.setAttribute("hora-ocupada","4"),e.style.backgroundColor=o[3+a]):!isNaN(parseInt(e.getAttribute("hora-ocupada")))&&parseInt(e.getAttribute("hora-ocupada"))>3?(t&&e.setAttribute("hora-ocupada","5"),e.style.backgroundColor=o[4+a]):(t&&e.setAttribute("hora-ocupada","1"),e.style.backgroundColor=r?"transparent":o[0])}function crearTablas(e,t,a=["Hora","Lunes","Martes","Miercoles","Jueves","Viernes"],r=["07:00","07:50",["08:40"],"08:50","09:40",["10:30"],"10:40","11:30","12:20","13:10","14:00","14:50",["15:40"],"15:50","16:40",["17:30"],"17:40","18:30","19:20"]){const o=["0_anio","1er_anio","2do_anio","3er_anio","4to_anio","5to_anio"][e];let n=document.createElement("table");n.id="tablaHorario"+e+"anio",n.className="striped";let i=document.createElement("thead"),l=document.createElement("tr");for(let e in a){let t=a[e],r=document.createElement("td");r.innerText=t,l.appendChild(r)}i.appendChild(l),n.appendChild(i);let c=document.createElement("tbody");for(let e in r){let t=r[e],n=document.createElement("tr"),i=!1;"object"==typeof t&&(t=t[0],n.className="trDescansoLight",i=!0);for(let e in a){let r=document.createElement("td");"0"===e?r.innerText=t:i||(r.id=a[e].substring(0,2)+t.replace(":","")+o,r.className=a[e].substring(0,2)+t.replace(":","")),n.appendChild(r)}c.appendChild(n)}n.appendChild(c),t.appendChild(n)}function ocultarCurso(e,t,a,r){if(e){t.className=t.className.replace(/Off/,"On");let e,o=document.querySelectorAll("."+a+r);for(let t=0;o.length,e=o[t];t++)e.style.display="inline-block"}else{t.className=t.className.replace(/On/,"Off");let e,o=document.querySelectorAll("."+a+r);console.log("Query: ."+a+r);for(let t=0;t{200===ajax.status&&4===ajax.readyState&&(laData=JSON.parse(ajax.responseText),crearTablas(0,document.getElementById("Horario0anio")),crearTablas(1,document.getElementById("Horario1anio")),crearTablas(2,document.getElementById("Horario2anio")),crearTablas(3,document.getElementById("Horario3anio")),crearTablas(4,document.getElementById("Horario4anio")),crearTablas(5,document.getElementById("Horario5anio")),ocultarTabla(0),ocultarTabla(2),ocultarTabla(3),ocultarTabla(4),ocultarTabla(5),crearDatos(laData,!1))}),ajax.open("GET","./data.json",!0),ajax.send(); \ No newline at end of file diff --git a/raw3anioData.json b/raw3anioData.json new file mode 100644 index 0000000..259b6ab --- /dev/null +++ b/raw3anioData.json @@ -0,0 +1,147 @@ +{ + "Hoja1": [ + [ + "SEMESTRE: TERCER AÑO – AULA 302" + ], + [ + "HORA", + "LUNES", + "MARTES", + "MIERCOLES", + "JUEVES", + "VIERNES" + ], + [ + "07:00-07:50", + "CS-A(P.HUERTAS)", + "SO-A(K.GUEVARA)", + "RCA-A(L.DELGADO)", + "SO-A(K.GUEVARA)", + "SO-A(K.GUEVARA)" + ], + [ + "07:50-08:40", + "CS-A(P.HUERTAS)", + "SO-A(K.GUEVARA)", + "RCA-A(L.DELGADO)", + "SO-A(K.GUEVARA)", + "SO-A(K.GUEVARA)" + ], + [], + [ + "08:50-09:40", + "CS-C(JORGE R,)", + "CS-A(T)(P.HUERTAS)", + "RCD-A(L.DELGADO)", + "FSI-A(V.CORNEJO)", + "CS-C(JORGE R)-PROY" + ], + [ + "09:40 -10:30", + "CS-C(JORGE R,)", + "CS-A(T)(P.HUERTAS)", + "RCD-A(L.DELGADO)", + "FSI-A(V.CORNEJO)", + "CS-C(JORGE R)-PROY" + ], + [], + [ + "10:40-11:30", + "RCD-A(L.DELGADO)", + "FSI-A(V.CORNEJO)", + "RCD-C(L.DELGADO)", + "MIR-A(J.ZUÑIGA)" + ], + [ + "11:30-12:20", + "RCD-A(L.DELGADO)", + "FSI-A(V.CORNEJO)", + "RCD-C(L.DELGADO)", + "MIR-A(J.ZUÑIGA)" + ], + [ + "12:20-13:10", + "RCD-C(L.DELGADO)", + "FSI-A(V.CORNEJO)", + null, + "MIR-A(J.ZUÑIGA)", + "TO(V.MACHACA)" + ], + [ + "13:10-14:00", + "RCD-C(L.DELGADO)", + null, + null, + null, + "TO(V.MACHACA)" + ], + [ + "14:00-14:50", + "RCD-B(L.DELGADO)", + "SO-B(K.GUEVARA)", + "TO-A(CH.PORTUGAL)", + "SO-C(K.GUEVARA)", + "CS-A(P.HUERTAS)" + ], + [ + "14:50-15:40", + "RCD-B(L.DELGADO)", + "SO-B(K.GUEVARA)", + "TO-A(CH.PORTUGAL)", + "SO-C(K.GUEVARA)", + "CS-A(P.HUERTAS)" + ], + [], + [ + "15:50-16:40", + "FSI-B(JC.JUAREZ)", + "TO-B(CH.PORTUGAL)", + null, + "FSI-B(JC.JUAREZ)" + ], + [ + "16:40-17:30", + "FSI-B(JC.JUAREZ)", + "TO-B(CH.PORTUGAL)", + null, + "FSI-B(JC.JUAREZ)" + ], + [], + [ + "17:40-18:30", + "FSI-B(JC.JUAREZ)", + "TO-C(CH.PORTUGAL)", + "TO(V.MACHACA)" + ], + [ + "18:30-19:20", + null, + "TO-C(CH.PORTUGAL)", + "TO(V.MACHACA)" + ], + [ + "19:20-20:10" + ], + [ + "20:10-21:00" + ], + [ + "CS= Construcción de Software (A)(T)(L)(A) Percy Huertas (B)Giovani Cabrera ( C ) Jorge Ramirez " + ], + [ + "RCD=Redes y Comunicación de Datos (A,B)(T)(A,C)(L) Lucy Delgado (B,D)(L) Juan Ramirez Ticona" + ], + [ + "TO=Tecnologías de Objetos(A)(T) Vicente Machaca (L)(A,B,C) Christian Portugal" + ], + [ + "SO=Sistemas Operativos (A) Karim Guevara P. de la Vega" + ], + [ + "FSI=Fundamentos de Sistemas de Informacion (A) Victor Cornejo Aparicio (B) Juan C. Juarez Bueno" + ], + [ + "MIR=Métodos de Investigación y Redacción (A) Jesús Zuñiga Cueva" + ] + ] +} \ No newline at end of file diff --git a/rawJsonCreator.js b/rawJsonCreator.js new file mode 100644 index 0000000..434ab51 --- /dev/null +++ b/rawJsonCreator.js @@ -0,0 +1,66 @@ +let fs = require('fs'); + +const tabla = {}; + +fs.readFile('./raw3anioData.json',(err, data) => { + const miData = JSON.parse(data); + crearData(miData); +}); + + +function crearData(data) { + let datos = data["Hoja1"]; + + let indiceAnios = []; + let indiceDatos = [undefined,undefined]; + let cursosMap = {}; + let anioActual = -1; + /* datos contiene un Array con las filas, cada una de estas filas es un array con las posiciones. */ + + const DIAS = ["Lunes","Martes","Miercoles","Jueves","Viernes"]; + const NOMBRES_ANIOS = "(primer | segundo | tercer | cuarto | quinto)"; + const regexNombresAnios = new RegExp(NOMBRES_ANIOS,"i"); + const regexHoras = new RegExp("\d\d\s*[:]\s*\d\d\s*[-]\s*\d\d\s*[:]\s*\d\d","i"); + + for (let index in datos) { + let fila = datos[index]; + + for (let indexF in fila) { + let celda = fila[indexF]; + + let horaActual = ""; + let diaActual = 0; + + /* Revisa si es un inicio de anio */ + if ((/semestre/i).test(celda) === true) { + console.log("Celda semestre: " + celda); + let nombreAnio = (regexNombresAnios.exec(celda))[0].trim(); + console.log("Datos tras regex: '" + nombreAnio + "'"); + anioActual++; + indiceAnios.push(nombreAnio); + tabla[nombreAnio] = {}; + } + /* Revisa la hora actual */ + else if (regexHoras.test(celda)) { + + } + else if ((/\w+\s?=\s?\w+/i).test(celda) === false) { + if (indiceDatos[0] === undefined) indiceDatos[0] = index; + } + /* Mapea los cursos y sus abreviaturas en cursosMap para poder acceder a ellos facilmente */ + else { + if (indiceDatos[1] === undefined) indiceDatos[1] = index-1; + let regex = /(\w+)(\s*=\s*)(\w+\s*)+(([(]\s?\w(,\w)*\s?[)]\s*)+(\w+\.?\s*)+)+/g; + let datosRegex = regex.exec(celda); + console.log("Datos tras regex\n" + celda + "\n" + datosRegex); + } + } + } + + console.log(`Al final el obj es:\n\n${JSON.stringify(tabla)}\n\n`); +} + + + + + diff --git a/style.css b/style.css new file mode 100644 index 0000000..2c9c45b --- /dev/null +++ b/style.css @@ -0,0 +1,161 @@ +body { + font-family: Roboto, sans-serif; +} + +a { + text-decoration: underline; + color: #545bff; + cursor: pointer; +} + +.tablasHorarios { + overflow-y: hidden; + transition: height 300ms ease-out; + height: auto; + padding: 5px; +} + +#nav-bar { + padding: 20px; + font-size: x-large; + text-transform: uppercase; + font-family: Roboto, sans-serif; + text-align: center; + background: #64001d; + color: #FFFFFF; + margin: 0; + box-shadow: 0 3px 5px gray; +} + +.container { + margin: 0 auto; + max-width: 1280px; + width: 90%; + border-radius: 2px; + box-shadow: 2px 2px 2px lightgray; + padding: 15px; + background-color: #FFFFFF; +} + +.expandOccultButton { + display: inline-block; + cursor: pointer; + float: right +} + +.descanso { + background-color: lightgreen; +} + +table { + width: 100%; +} + +table tr, table tr td { + text-align: center; + padding: 3px; +} + +table.striped > tbody > tr:nth-child(odd) { + background-color: #f2f2f2; +} + +table.stripedD > tbody > tr:nth-child(odd) { + background-color: #353c44; +} + +table.striped > tbody > tr > td { + transition: background-color 150ms, color 150ms; + border-radius: 0; +} + +.dropdown { + position: relative; + display: inline-block; + cursor: pointer; +} + +.dropdown-content { + right: 0; + display: none; + position: absolute; + background-color: #f9f9f9; + min-width: 150px; + box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); + padding: 10px; + z-index: 1; + cursor: default; + text-align: left; + color: black; +} + +.dropdown:hover { + text-decoration: underline; +} + +.dropdown:hover .dropdown-content { + display: block; +} + +.botonAdd { + cursor: pointer; + display: inline-block; + color: #33F; +} + +.botonAdd:hover { + text-decoration: underline; +} + +.cursoDataDiv { + padding: 10px; + display: inline-block +} + +table > tbody > tr.trDescansoLight > td { + background-color: #e4ffed +} + +table > tbody > tr.trDescansoDark > td { + background-color: #48544c +} + +.nombreCursoTeoriaLight { + color: blue; +} + +.nombreCursoTeoriaDark { + color: #82aaff; +} + +.nombreCursoLabLight { + color: #ff563c +} + +.nombreCursoLabDark { + color: #f07178 +} + +.descrCurso--Light--On { + color: black; +} + +.descrCurso--Light--Off { + color: #ababab; +} + +.descrCurso--Dark--On { + color: #ababab; +} + +.descrCurso--Dark--Off { + color: #656d78; +} + +.descrCurso--Light--OK { + +} + +.descrCurso--Dark--OK { + color: #93e78c; +}