diff --git a/app/js/section/section.controllers.js b/app/js/section/section.controllers.js index e87b93d..8cd6934 100644 --- a/app/js/section/section.controllers.js +++ b/app/js/section/section.controllers.js @@ -15,17 +15,7 @@ sections.query( function (successResult){ - vm.matricula = successResult; - angular.forEach(vm.matricula, function (value){ - matriculaArray.push({ - section:value.section, - code:value.code, - course:value.course, - semester:value.semester, - student: value.student - }); - }); - vm.listaMatricula = matriculaArray; + vm.section = successResult; }, function (){ console.log("Error al obtener los datos."); @@ -65,9 +55,9 @@ $rootScope.otroBotonOk = true; $rootScope.botonCancelar = false; $rootScope.urlLo = 'listarMatricula'; - var name = vm.matricula[index].section; + var name = vm.section[index].name; - sections.delete({ id: vm.matricula[index]._id }, + sections.delete({ id: vm.section[index]._id }, function () { $rootScope.rsplice = true; $rootScope.mensaje = "Sección " + name + " eliminada"; @@ -79,7 +69,7 @@ vm.eliminarMatriculaSplice = function (index, rsplice) { if(rsplice){ - vm.listaMatricula.splice(index, 1); + vm.section.splice(index, 1); $rootScope.rsplice = false; } }; @@ -88,11 +78,12 @@ vm.modificarMatricula = function (index) { - matriculaSeleccionada.Nombre = vm.matricula[index].Nombre; - matriculaSeleccionada.Codigo = vm.matricula[index].Codigo; - matriculaSeleccionada.Materia = vm.matricula[index].Materia; - matriculaSeleccionada.Semestre = vm.matricula[index].Semestre; - matriculaSeleccionada.Estudiantes= vm.matricula[index].Estudiantes; + matriculaSeleccionada._id = vm.section[index]._id; + matriculaSeleccionada.name = vm.section[index].name; + matriculaSeleccionada.code = vm.section[index].code; + matriculaSeleccionada.course = vm.section[index].course; + matriculaSeleccionada.semester = vm.section[index].semester; + matriculaSeleccionada.students = vm.section[index].students; $location.url('actualizarMatricula'); }; @@ -121,7 +112,9 @@ var vm = this; vm.submitted = false; + vm.semester, vm.section, vm.materias; $rootScope.mensaje = ""; + vm.students = []; courses.query( function (successResult) { @@ -131,16 +124,15 @@ vm.materias = null; }); - vm.submit = function() { + vm.submit = function () { if (vm.data_input_form.$valid){ - vm.section = { - - "section": vm.matricula.Nombre, - "code": vm.valorMateria.Codigo, - "course": vm.valorMateria.Nombre, - "semester": vm.matricula.Semestre, - "students": vm.matricula.Estudiantes, + vm.package = { + "name": vm.name, + "code": vm.valorMateria.code, + "course": vm.valorMateria.name, + "semester": vm.semester, + "students": vm.students }; $scope.modalInstance = $modal.open({ @@ -155,16 +147,16 @@ } }); - sections.save(vm.section, + sections.save(vm.package, function(){ $rootScope.botonOk = true; $rootScope.urlLo = 'listarMatricula'; - $rootScope.mensaje = "Sección " + vm.matricula.Nombre + " creada"; + $rootScope.mensaje = "Sección " + vm.name + " creada"; }, function(){ $rootScope.botonOk = true; $rootScope.urlLo = 'listarMatricula'; - $rootScope.mensaje = "Error creando la seccion " + vm.matricula.Nombre; + $rootScope.mensaje = "Error creando la seccion " + vm.name; }); }else{ vm.submitted = true; @@ -173,37 +165,44 @@ var xlf = document.getElementById('xlf'); function handleFile(e) { - console.log("DO SOME STUFF"); - /*rABS = document.getElementsByName("userabs")[0].checked; - use_worker = document.getElementsByName("useworker")[0].checked; var files = e.target.files; - var f = files[0]; - { + var i,f,z; + var student = {}; + for (i = 0, f = files[i]; i != files.length; ++i) { var reader = new FileReader(); var name = f.name; reader.onload = function(e) { - if(typeof console !== 'undefined') console.log("onload", new Date(), rABS, use_worker); var data = e.target.result; - if(use_worker) { - xw(data, process_wb); - } else { - var wb; - if(rABS) { - wb = X.read(data, {type: 'binary'}); - } else { - var arr = fixdata(data); - wb = X.read(btoa(arr), {type: 'base64'}); - } - process_wb(wb); - } - }; - if(rABS) reader.readAsBinaryString(f); - else reader.readAsArrayBuffer(f); - }*/ - } - vm.cargarEstudiantes = function () { + var workbook = XLSX.read(data, {type: 'binary'}); + var sheet = workbook.SheetNames[0]; + var worksheet = workbook.Sheets[sheet]; - }; + /* Find desired cell containing semester and section */ + vm.semester = worksheet['B5'].v; + vm.name = worksheet['B9'].v; + $scope.$apply(); + + for (z in worksheet) { + /* all keys that do not begin with "!" correspond to cell addresses */ + if (z[0] === '!') continue; + if ((z[0] >'B') && (z[1] > 0) && (z[2] > 1)) { + /* Cells that start in the C column represent the sttudent id in the worksheet, the same applies to name and lastname being in D and E columns*/ + if (z[0] =='C') student.id = worksheet[z].v; + if (z[0] =='D') student.name = worksheet[z].v; + if (z[0] =='E') { + student.lastname = worksheet[z].v; + /*Since we are only going to use these 3 attributes from the students then we push only this data to the students array*/ + vm.students.push(student); + student = {}; + } + + } + }; + }; + reader.readAsBinaryString(f); + } + } + if(xlf.addEventListener) xlf.addEventListener('change', handleFile, false); $scope.ok = function (urlLo) { $location.url(urlLo); @@ -224,27 +223,12 @@ function actualizarMatriculaCtrl($scope, $rootScope, $location, sections, $modal, matriculaSeleccionada){ var vm = this; - vm.lista = true; - $rootScope.loading = true; - $rootScope.table = false; - vm.matricula = matriculaSeleccionada; - vm.listaEstudiantes = vm.matricula.Estudiantes; + vm.section = matriculaSeleccionada; + vm.students = matriculaSeleccionada.students; vm.actualizarMatricula = function() { - sections.update(section, - function(){ - $rootScope.botonOk = true; - $rootScope.botonCancelar = false; - $rootScope.urlLo = 'listarMatricula'; - $rootScope.mensaje = "Sección actualizada"; - }, - function(){ - $rootScope.botonOk = true; - $rootScope.botonCancelar = false; - $rootScope.urlLo = 'listarMatricula'; - $rootScope.mensaje = "Error al actualizar la Sección "; - }); + } vm.retirarEstudianteModal = function (index) { @@ -256,7 +240,7 @@ $rootScope.rsplice = false; $rootScope.eliminarLoading = false; - $rootScope.mensaje = "¿Desea retirar este estudiante de la Sección?"; + $rootScope.mensaje = "¿Desea retirar al estudiante "+ vm.students[index].lastname +", "+ vm.students[index].name + "?"; $scope.modalInstance = $modal.open({ animation: $rootScope.animationsEnabled, @@ -272,24 +256,36 @@ }; vm.retirarEstudiante = function (index) { - $rootScope.botonOk = false; - $rootScope.otroBotonOk = true; - $rootScope.botonCancelar = false; - $rootScope.urlLo = 'actualizarMatricula'; + $rootScope.rsplice = true; }; vm.retirarEstudianteSplice = function(index, rsplice) { - if(rsplice){ - vm.listaEstudiantes.splice(index, 1); + if (rsplice) { + vm.students.splice(index, 1); $rootScope.rsplice = false; - var section = { - 'section': vm.matricula.Nombre, - 'code': vm.matricula.Codigo, - 'course': vm.matricula.Seccion, - 'semester': vm.matricula.Semestre, - 'students': vm.listaEstudiantes + vm.section = { + "_id": vm.section._id, + "name": vm.section.name, + "code": vm.section.code, + "course": vm.section.name, + "semester": vm.section.semester, + "students": vm.students }; + + sections.update(vm.section, + function (){ + $rootScope.botonOk = false; + $rootScope.otroBotonOk = true; + $rootScope.botonCancelar = false; + $rootScope.mensaje = "Sección "+ vm.section.name +" actualizada"; + }, + function (){ + $rootScope.botonOk = false; + $rootScope.otroBotonOk = true; + $rootScope.botonCancelar = false; + $rootScope.mensaje = "Error al actualizar la Sección "+ vm.section.name; + }); } }; @@ -299,8 +295,7 @@ $rootScope.opened = true; }; - $scope.ok = function (urlLo) { - $location.url(urlLo); + $scope.ok = function () { $scope.modalInstance.dismiss('cancel'); }; diff --git a/app/partials/section/create_section.html b/app/partials/section/create_section.html index 95dda27..5906f30 100644 --- a/app/partials/section/create_section.html +++ b/app/partials/section/create_section.html @@ -20,13 +20,13 @@ + ng-model="vm.valorMateria.code" required/>