Update routes, mongoose schema and web flow

This commit is contained in:
Reynaldo Reyes
2016-03-27 23:24:28 -04:30
parent b8b65e64d7
commit 7fff896e43
34 changed files with 735 additions and 631 deletions

View File

@@ -2,25 +2,21 @@
<form name="vm.data_input_form" role="form" novalidate
ng-submit="vm.submit()">
<div class="row clearfix">
<h4>Nueva Matricula</h4>
<h4>Nueva Sección</h4>
<br>
<div class="col-md-12 column well">
<div class="row">
<div class="col-md-4 column">
<label>Nombre de la Materia</label>
<select
class="form-control"
ng-model="vm.valorMateria"
ng-options="materia.name for materia in vm.materias"
>
<option value="">{{materia.name}}</option>
</select>
<input type="text" class="form-control"
name="materia" readonly="readonly"
ng-model="vm.course.name" required/>
</div>
<div class="col-md-4 column">
<label for="codigo">Codigo de la Materia</label>
<input type="text" class="form-control"
name="codigo" readonly="readonly"
ng-model="vm.valorMateria.code" required/>
ng-model="vm.course.code" required/>
</div>
<div class="col-md-4 column">
<label for="semestre">Semestre</label>
@@ -72,6 +68,49 @@
</p>
</div>
</div>
</div>
</div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th width="20%">
<a href="" ng-click="sortType = 'Cedula';
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>
</a>
</th>
<th width="40%">
<a href="" ng-click="sortType = 'Apellido';
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>
</a>
</th>
<th width="40%">
<a href="" ng-click="sortType = 'Nombre';
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>
</a>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in vm.students">
<td style="vertical-align:middle">{{ student.id }}</td>
<td style="vertical-align:middle">{{ student.lastname }}</td>
<td style="vertical-align:middle">{{ student.name }}</td>
</tr>
</tbody>
</table>
</form>
</div>

View File

@@ -1,50 +1,42 @@
<div class="row clearfix">
<h4>Listado de Secciones</h4></br>
<div>
<button class="btn-success btn" ng-click="vm.createSection()" style="margin: 10px"> Crear Sección </button>
</br>
</br>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th width="20%">
<a href="" ng-click="sortType = 'name';
sortReverse = !sortReverse">
Sección
<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 = 'course'; sortReverse = !sortReverse">
Nombre de la Materia
<span ng-show="sortType == 'course' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'course' && sortReverse" class="fa fa-caret-up"></span>
</a>
</th>
<th width="20%">
<a href="" ng-click="sortType = 'code'; sortReverse = !sortReverse">
Codigo de la Materia
<span ng-show="sortType == 'code' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'code' && sortReverse" class="fa fa-caret-up"></span>
</a>
</th>
<th width="20%">
<a href="" ng-click="sortType = 'semester'; sortReverse = !sortReverse">
Semestre
<span ng-show="sortType == 'semester' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'semester' && sortReverse" class="fa fa-caret-up"></span>
</a>
</th>
<th width="10%" style="text-align: center">
<a>Modificar</a>
Modificar
</th>
<th width="10%" style="text-align: center">
<a>Borrar</a>
Borrar
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = "section in vm.section | orderBy:sortType:sortReverse | filter:searchUser">
<tr ng-repeat = "section in vm.section">
<td style="vertical-align:middle">{{ section.name }}</td>
<td style="vertical-align:middle">{{ section.course }}</td>
<td style="vertical-align:middle">{{ section.code }}</td>
@@ -65,5 +57,5 @@
</tbody>
</table>
</div>
<div ng-show=false > {{ vm.eliminarMatriculaSplice(index, rsplice) }}</div>
<a href="#listarMateria" class="btn-warning btn" style=" margin: 10px">Regresar</a>
</div>

View File

@@ -0,0 +1,328 @@
(function(){
'use strict';
angular
.module('app.section')
.controller('listarMatriculaCtrl', listarMatriculaCtrl)
.controller('crearMatriculaCtrl', crearMatriculaCtrl)
.controller('actualizarMatriculaCtrl', actualizarMatriculaCtrl)
listarMatriculaCtrl.$inject = [ '$scope', '$rootScope', '$location', 'professors', '$modal', 'selectedCourse', 'selectedSection'];
function listarMatriculaCtrl ( $scope, $rootScope, $location, professors, $modal, selectedCourse, selectedSection ){
var vm = this;
var professorid = '56f5fd3a20047f3c15b05f0e';
vm.section = [];
vm.professor = null;
professors.get({ id: professorid },
function (successResult){
vm.professor = successResult;
angular.forEach (vm.professor.courses,
function (value, key){
if (value._id == selectedCourse._id ) {
vm.index = key;
vm.section = value.sections;
}
});
},
function (){
console.log("Error al obtener los datos.");
});
/**************************Eliminar Matricula**************************/
/* En este proceso, primero se llama a un Modal el cual se cerciora que
el usuario se asegure de eliminar la matricula escogida, el usuario al
confirmar su decision llama automaticamente a la funcion que hara la
llamada a servicio que borrara la matricula de la base de datos.
*/
vm.createSection = function () {
$location.url('crearMatricula');
};
vm.eliminarMatriculaModal = function (index) {
$rootScope.index = index;
$rootScope.botonOk = true;
$rootScope.otroBotonOk = false;
$rootScope.botonCancelar = true;
$rootScope.rsplice = false;
$rootScope.mensaje = "¿Seguro que desea eliminar la sección?";
$scope.modalInstance = $modal.open({
animation: $rootScope.animationsEnabled,
templateUrl: '/partials/section/modal/delete_section_modal.html',
scope: $scope,
size: 'sm',
resolve: {
items: function () {
return "";
}
}
});
};
vm.eliminarMatricula = function (index) {
$rootScope.botonOk = false;
$rootScope.otroBotonOk = true;
$rootScope.botonCancelar = false;
$rootScope.urlLo = 'listarMatricula';
var name = vm.section[index].name;
vm.professor.courses[vm.index].sections.splice(index, 1);
professors.update({ id: professorid }, vm.professor,
function () {
$rootScope.rsplice = true;
$rootScope.mensaje = "Sección " + name + " eliminada";
},
function () {
$rootScope.mensaje = "Error eliminando la sección " + name;
});
};
vm.eliminarMatriculaSplice = function (index, rsplice) {
if(rsplice){
}
};
/*************************Fin de Eliminar Matricula*******************/
vm.modificarMatricula = function (index) {
selectedSection._id = vm.section[index]._id;
selectedCourse.index = vm.index;
$location.url('actualizarMatricula');
};
$rootScope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$rootScope.opened = true;
};
$scope.ok = function (urlLo) {
$location.url(urlLo);
$scope.modalInstance.dismiss('cancel');
};
$scope.cancel = function () {
$scope.modalInstance.dismiss('cancel');
};
return vm;
};
crearMatriculaCtrl.$inject =
['$scope','$rootScope', '$location', 'professors', '$modal', 'selectedCourse'];
function crearMatriculaCtrl($scope, $rootScope, $location, professors, $modal, selectedCourse){
var professorid = '56f5fd3a20047f3c15b05f0e';
var vm = this;
vm.course = {};
vm.selectedCourse = selectedCourse;
vm.submitted = false;
vm.semester, vm.section, vm.materias;
$rootScope.mensaje = "";
vm.students = [];
professors.get({ id: professorid },
function (successResult){
vm.professor = successResult;
angular.forEach (vm.professor.courses,
function (value, key){
if (value._id == vm.selectedCourse._id ) {
vm.index = key;
vm.section = value.sections;
vm.course.code = value.code;
vm.course.name = value.name;
}
});
},
function (){
console.log("Error al obtener los datos.");
});
vm.submit = function () {
if (vm.data_input_form.$valid){
vm.package = {
"name": vm.name,
"code": vm.course.code,
"course": vm.course.name,
"semester": vm.semester,
"students": vm.students
};
$scope.modalInstance = $modal.open({
animation: $rootScope.animationsEnabled,
templateUrl: 'partials/section/modal/create_section_modal.html',
scope: $scope,
size: 'sm',
resolve: {
items: function () {
return $rootScope.items;
}
}
});
vm.professor.courses[vm.index].sections.push(vm.package);
professors.update({ id: professorid }, vm.professor,
function(){
$rootScope.botonOk = true;
$rootScope.urlLo = 'listarMatricula';
$rootScope.mensaje = "Sección " + vm.name + " creada";
},
function(){
$rootScope.botonOk = true;
$rootScope.urlLo = 'listarMatricula';
$rootScope.mensaje = "Error creando la seccion " + vm.name;
});
}else{
vm.submitted = true;
}
};
var xlf = document.getElementById('xlf');
function handleFile(e) {
var files = e.target.files;
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) {
var data = e.target.result;
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;
if (z[0] =='F') {
student.email = 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 = {};
}
}
};
$scope.$apply();
};
reader.readAsBinaryString(f);
}
}
if(xlf.addEventListener) xlf.addEventListener('change', handleFile, false);
$scope.ok = function (urlLo) {
$location.url(urlLo);
$scope.modalInstance.dismiss('cancel');
};
$rootScope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$rootScope.opened = true;
};
return vm;
};
actualizarMatriculaCtrl.$inject = ['$scope', '$rootScope', '$location', 'professors', '$modal', 'selectedSection', 'selectedCourse'];
function actualizarMatriculaCtrl($scope, $rootScope, $location, professors, $modal, selectedSection, selectedCourse){
var professorid = '56f5fd3a20047f3c15b05f0e';
var vm = this;
vm.section = {};
vm.students = [];
professors.get({ id: professorid },
function (successResult){
vm.professor = successResult;
angular.forEach (vm.professor.courses[selectedCourse.index].sections,
function (value, key){
if (value._id == selectedSection._id ) {
selectedSection.index = key;
vm.students = value.students;
vm.section = value;
}
});
},
function (){
console.log("Error al obtener los datos.");
});
vm.addStudent = function (index) {
$location.url('crearEstudiante');
};
vm.retirarEstudianteModal = function (index) {
$rootScope.index = index;
$rootScope.botonOk = true;
$rootScope.otroBotonOk = false;
$rootScope.botonCancelar = true;
$rootScope.eliminarLoading = false;
$rootScope.mensaje = "¿Desea retirar al estudiante "+ vm.students[index].lastname +", "+ vm.students[index].name + "?";
$scope.modalInstance = $modal.open({
animation: $rootScope.animationsEnabled,
templateUrl: 'partials/section/modal/update_section_modal.html',
scope: $scope,
size: 'sm',
resolve: {
items: function () {
return "";
}
}
});
};
vm.retirarEstudiante = function (index) {
vm.professor.courses[selectedCourse.index].sections[selectedSection.index].students.splice(index, 1);
professors.update({ id: professorid }, vm.professor,
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;
});
};
$rootScope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$rootScope.opened = true;
};
$scope.ok = function () {
$scope.modalInstance.dismiss('cancel');
};
$scope.cancel = function () {
$scope.modalInstance.dismiss('cancel');
};
return vm;
};
})();

View File

@@ -0,0 +1,78 @@
(function(){
'use strict';
angular
.module("app.section", ['ui.router', 'ui.bootstrap'])
.run(addStateToScope)
.config(getRoutes);
addStateToScope.$inject = ['$rootScope', '$state', '$stateParams'];
function addStateToScope($rootScope, $state, $stateParams){
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
};
getRoutes.$inject = ['$stateProvider', '$urlRouterProvider'];
function getRoutes($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise('/listarMatricula');
$stateProvider
.state('listarMatricula', {
url: '/listarMatricula',
views: {
sidebar: {
templateUrl: 'partials/sidebar/sidebar.html',
controller: 'sidebarCtrl'
},
navbar: {
templateUrl: 'partials/sidebar/navbar.html'
},
content: {
templateUrl: 'partials/section/list_section.html',
controller: 'listarMatriculaCtrl',
controllerAs: 'vm'
}
}
})
.state('crearMatricula', {
url: '/crearMatricula',
views: {
sidebar: {
templateUrl: 'partials/sidebar/sidebar.html',
controller: 'sidebarCtrl'
},
navbar: {
templateUrl: 'partials/sidebar/navbar.html'
},
content: {
templateUrl: 'partials/section/create_section.html',
controller: 'crearMatriculaCtrl',
controllerAs: 'vm'
}
}
})
.state('actualizarMatricula', {
url: '/actualizarMatricula',
views: {
sidebar: {
templateUrl: 'partials/sidebar/sidebar.html',
controller: 'sidebarCtrl'
},
navbar: {
templateUrl: 'partials/sidebar/navbar.html'
},
content: {
templateUrl: 'partials/section/update_section.html',
controller: 'actualizarMatriculaCtrl',
controllerAs: 'vm'
}
}
})
};
})();

View File

@@ -0,0 +1,16 @@
(function(){
'use strict';
angular
.module('app.section')
.factory('sections', sections)
.value('matriculaSeleccionada',{});
sections.$inject = ['$resource','$rootScope'];
function sections($resource, $rootScope){
return $resource('http://'+$rootScope.domainUrl+'/sections/:id', null,
{
'update': {method:'PUT'}
});
};
})();

View File

@@ -1,41 +1,42 @@
<div class="row clearfix">
<h4>Estudiantes Inscritos en {{ vm.section.course }} - Seccion {{ vm.section.name }} - Semestre {{ vm.section.semester }}</h4>
<br>
<button class="btn-success btn" ng-click="vm.addStudent()" style="margin: 10px"> Agregar Estudiante </button><br><br>
<div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th width="20%">
<a href="" ng-click="sortType = 'id'; sortReverse = !sortReverse">
Cedula
<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 width="10%">
Cedula
<span ng-show="sortType == 'id' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'id' && sortReverse" class="fa fa-caret-up"></span>
</th>
<th width="20%">
<a href="" ng-click="sortType = 'name'; sortReverse = !sortReverse">
Nombre
<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>
Nombre
<span ng-show="sortType == 'name' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'name' && sortReverse" class="fa fa-caret-up"></span>
</th>
<th width="20%">
<a href="" ng-click="sortType = 'lastname'; sortReverse = !sortReverse">
Apellido
<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>
Apellido
<span ng-show="sortType == 'lastname' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'lastname' && sortReverse" class="fa fa-caret-up"></span>
</th>
<th width="20%" style="text-align: center">
<a>Retirar</a>
<th width="30%">
Correo
<span ng-show="sortType == 'email' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'email' && sortReverse" class="fa fa-caret-up"></span>
</th>
<th width="10%" style="text-align: center">
Retirar
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in vm.students | orderBy:sortType:sortReverse | filter:searchUser">
<tr ng-repeat="student in vm.students">
<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="vertical-align:middle">{{ student.email }}</td>
<td style="text-align: center">
<span title="Click aqui para Eliminar un Estudiante"
class="glyphicon glyphicon-remove" aria-hidden="true"
@@ -46,8 +47,6 @@
</tbody>
</table>
</div>
<button type="button" class="btn-primary btn" ng-click="vm.actualizarMatricula()">Guardar Cambios</button>
<div ng-show = false> {{ vm.retirarEstudianteSplice(index, rsplice) }}</div>
<div class="container-fluid ">
<a href="#listarMatricula" class="btn-warning btn" style=" margin: 10px">Regresar</a>
</div>