Add the xls student load, student list and removal by course

This commit is contained in:
Reynaldo Reyes
2016-03-06 13:36:00 -04:30
parent feeada3fd7
commit b8b65e64d7
5 changed files with 110 additions and 115 deletions

View File

@@ -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');
};

View File

@@ -20,13 +20,13 @@
<label for="codigo">Codigo de la Materia</label>
<input type="text" class="form-control"
name="codigo" readonly="readonly"
ng-model="vm.valorMateria.code"/>
ng-model="vm.valorMateria.code" required/>
</div>
<div class="col-md-4 column">
<label for="semestre">Semestre</label>
<input type="text" class="form-control"
name="semestre"
ng-model="vm.matricula.Semestre" required/>
name="semestre" readonly="readonly"
ng-model="vm.semester" required/>
<div class="error" ng-show="vm.submitted &&
vm.data_input_form.semestre.$invalid">
<small class="error"
@@ -41,7 +41,7 @@
<div class="col-md-4 column">
<label for="seccion">Sección</label>
<input type="text" class="form-control"
name="seccion" ng-model="vm.matricula.Nombre"
name="seccion" readonly="readonly" ng-model="vm.name"
required/>
<div class="error" ng-show="vm.submitted &&
vm.data_input_form.seccion.$invalid">

View File

@@ -5,11 +5,11 @@
<thead>
<tr>
<th width="20%">
<a href="" ng-click="sortType = 'section';
<a href="" ng-click="sortType = 'name';
sortReverse = !sortReverse">
Sección
<span ng-show="sortType == 'section' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'section' && sortReverse" class="fa fa-caret-up"></span>
<span ng-show="sortType == 'name' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'name' && sortReverse" class="fa fa-caret-up"></span>
</a>
</th>
<th width="20%">
@@ -44,11 +44,11 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="matricula in vm.listaMatricula | orderBy:sortType:sortReverse | filter:searchUser">
<td style="vertical-align:middle">{{ matricula.section }}</td>
<td style="vertical-align:middle">{{ matricula.course }}</td>
<td style="vertical-align:middle">{{ matricula.code }}</td>
<td style="vertical-align:middle">{{ matricula.semester }}</td>
<tr ng-repeat = "section in vm.section | orderBy:sortType:sortReverse | filter:searchUser">
<td style="vertical-align:middle">{{ section.name }}</td>
<td style="vertical-align:middle">{{ section.course }}</td>
<td style="vertical-align:middle">{{ section.code }}</td>
<td style="vertical-align:middle">{{ section.semester }}</td>
<td style="text-align: center">
<span title="Click aqui para Modificar la Matricula"
class="glyphicon glyphicon-edit" aria-hidden="true"

View File

@@ -8,7 +8,7 @@
<button class="btn btn-primary" ng-show="botonOk" type="button"
ng-click="vm.retirarEstudiante(index)">OK</button>
<button class="btn btn-primary" ng-show="otroBotonOk" type="button"
ng-click="ok(urlLo)">Aceptar</button>
ng-click="ok()">Aceptar</button>
<button class="btn btn-warning" ng-show="botonCancelar" type="button"
ng-click="cancel()">Cancelar</button>
</div>

View File

@@ -1,29 +1,29 @@
<div class="row clearfix">
<h4>Estudiantes Inscritos en {{ vm.matricula.Nombre }} - Seccion {{ vm.matricula.Seccion }} - Semestre {{ vm.matricula.Semestre }}</h4>
<h4>Estudiantes Inscritos en {{ vm.section.course }} - Seccion {{ vm.section.name }} - Semestre {{ vm.section.semester }}</h4>
<br>
<div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th width="20%">
<a href="" ng-click="sortType = 'Cedula'; sortReverse = !sortReverse">
<a href="" ng-click="sortType = 'id'; sortReverse = !sortReverse">
Cedula
<span ng-show="sortType == 'Cedula' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'Cedula' && sortReverse" class="fa fa-caret-up"></span>
<span ng-show="sortType == 'id' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'id' && sortReverse" class="fa fa-caret-up"></span>
</a>
</th>
<th width="20%">
<a href="" ng-click="sortType = 'Nombre'; sortReverse = !sortReverse">
<a href="" ng-click="sortType = 'name'; sortReverse = !sortReverse">
Nombre
<span ng-show="sortType == 'Nombre' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'Nombre' && sortReverse" class="fa fa-caret-up"></span>
<span ng-show="sortType == 'name' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'name' && sortReverse" class="fa fa-caret-up"></span>
</a>
</th>
<th width="20%">
<a href="" ng-click="sortType = 'Apellido'; sortReverse = !sortReverse">
<a href="" ng-click="sortType = 'lastname'; sortReverse = !sortReverse">
Apellido
<span ng-show="sortType == 'Apellido' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'Apellido' && sortReverse" class="fa fa-caret-up"></span>
<span ng-show="sortType == 'lastname' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'lastname' && sortReverse" class="fa fa-caret-up"></span>
</a>
</th>
<th width="20%" style="text-align: center">
@@ -32,10 +32,10 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="estudiante in vm.listaEstudiantes | orderBy:sortType:sortReverse | filter:searchUser">
<td style="vertical-align:middle">{{ estudiante.Cedula }}</td>
<td style="vertical-align:middle">{{ estudiante.Nombre }}</td>
<td style="vertical-align:middle">{{ estudiante.Apellido }}</td>
<tr ng-repeat="student in vm.students | orderBy:sortType:sortReverse | filter:searchUser">
<td style="vertical-align:middle">{{ student.id }}</td>
<td style="vertical-align:middle">{{ student.name }}</td>
<td style="vertical-align:middle">{{ student.lastname }}</td>
<td style="text-align: center">
<span title="Click aqui para Eliminar un Estudiante"
class="glyphicon glyphicon-remove" aria-hidden="true"