Create M.A.S.A Version 1.0

This commit is contained in:
Reynaldo Reyes
2016-04-11 00:05:59 -04:30
parent 7fff896e43
commit 1ee3577fe4
60 changed files with 1673 additions and 2137 deletions

View File

@@ -1,67 +0,0 @@
<div class="row clearfix">
<h4>Listado de Estudiantes</h4>
<br>
<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="20%">
<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>
<th width="20%">
<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="20%" style="text-align: center">
<a>Modificar</a>
</th>
<th width="20%" style="text-align: center">
<a>Borrar</a>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="estudiante in vm.listaEstudiantes">
<td style="vertical-align:middle">{{ estudiante.Cedula }}</td>
<td style="vertical-align:middle">{{ estudiante.Nombre }}</td>
<td style="vertical-align:middle">{{ estudiante.Apellido }}</td>
<td style="text-align: center">
<span title="Click aqui para Modificar un Estudiante" class="glyphicon glyphicon-edit" aria-hidden="true"
ng-click="vm.modificarEstudiante($index)"
style="cursor:pointer"></span>
</td>
<td style="text-align: center">
<span title="Click aqui para Eliminar un Estudiante"
class="glyphicon glyphicon-remove" aria-hidden="true"
ng-click="vm.eliminarEstudianteModal($index)"
style="cursor:pointer"></span>
</td>
</tr>
</tbody>
</table>
</div>
<div ng-show=false > {{vm.removeEstudianteSplice(index, rsplice)}}</div>
</div>

View File

@@ -1,281 +0,0 @@
(function(){
'use strict';
angular
.module('app.student')
.controller('listarEstudianteCtrl', listarEstudianteCtrl)
.controller('crearEstudianteCtrl', crearEstudianteCtrl)
.controller('actualizarEstudianteCtrl', actualizarEstudianteCtrl)
listarEstudianteCtrl.$inject = [ '$scope', '$rootScope', '$location', 'students', '$modal', 'estudianteSeleccionado' ];
function listarEstudianteCtrl( $scope, $rootScope, $location, students, $modal, estudianteSeleccionado ){
var vm = this;
vm.lista = true;
$rootScope.actOk = false;
$rootScope.loading = true;
$rootScope.table = false;
var estudiantesArray = [];
students.query(
function(data){
vm.estudiantes = data;
angular.forEach(vm.estudiantes, function (value){
estudiantesArray.push({
Cedula:value.id,
Nombre:value.name,
Apellido:value.lastname,
Telefono:value.number,
Correo: value.email
});
});
$rootScope.loading = false;
$rootScope.table = true;
vm.listaEstudiantes = estudiantesArray;
},
function(){
console.log("Error al obtener los datos.");
});
vm.eliminarEstudianteModal = function (index) {
$rootScope.index = index;
$rootScope.botonOK = true;
$rootScope.botonCancelar = true;
$rootScope.acceptButton = false;
$rootScope.rsplice = false;
$rootScope.listarEstudiantesLoading = true;
$rootScope.mensaje = "¿Seguro que desea eliminar el Estudiante?";
$scope.modalInstance = $modal.open({
animation: $rootScope.animationsEnabled,
templateUrl: 'partials/students/modal/list_students_modal.html',
scope: $scope,
size: 'sm',
resolve: {
items: function () {
return "";
}
}
});
};
vm.eliminarEstudiante = function (index) {
$rootScope.botonOK = false;
$rootScope.acceptButton = true;
$rootScope.botonCancelar = false;
$rootScope.urlLo = 'listarEstudiante';
$rootScope.listarEstudiantesLoading = true;
students.delete({id: vm.estudiantes[index]._id},
function (successResult) {
$rootScope.listarEstudiantesLoading = false;
$rootScope.rsplice = true;
$rootScope.mensaje = "Usuario " + vm.estudiantes[index].name + " eliminado";
},
function (errorResult) {
$rootScope.listarEstudiantesLoading = false;
$rootScope.mensaje = "Error eliminando al Usuario " + vm.estudiantes[index].name;
});
};
vm.removeEstudianteSplice = function(index, rsplice) {
if(rsplice){
vm.listaEstudiantes.splice(index, 1);
$rootScope.rsplice = false;
}
};
vm.modificarEstudiante = function (index) {
estudianteSeleccionado._id = vm.estudiantes[index]._id;
estudianteSeleccionado.Cedula = vm.estudiantes[index].id;
estudianteSeleccionado.Nombre = vm.estudiantes[index].name;
estudianteSeleccionado.Apellido= vm.estudiantes[index].lastname;
estudianteSeleccionado.Telefono = vm.estudiantes[index].number;
estudianteSeleccionado.Correo= vm.estudiantes[index].email;
$location.url('actualizarEstudiante');
};
$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;
};
crearEstudianteCtrl.$inject = ['$scope', '$rootScope', '$location', 'professors', '$modal', 'selectedSection', 'selectedCourse'];
function crearEstudianteCtrl($scope, $rootScope, $location, professors, $modal, selectedSection, selectedCourse){
var vm = this;
var duplicated = false;
var professorid = '56f5fd3a20047f3c15b05f0e';
vm.professor = {};
$rootScope.mensaje = "";
$rootScope.actOk = false;
professors.get({ id: professorid },
function (successResult){
vm.professor = successResult;
},
function (){
console.log("Error al obtener los datos.");
});
vm.submit = function() {
if (vm.data_input_form.$valid){
var person = {
"id": vm.estudiante.Cedula,
"name": vm.estudiante.Nombre,
"lastname": vm.estudiante.Apellido,
"email": vm.estudiante.Correo
};
$rootScope.crearEstudianteLoading = true;
$rootScope.botonOk = false;
$scope.modalInstance = $modal.open({
animation: $rootScope.animationsEnabled,
templateUrl: 'partials/students/modal/create_students_modal.html',
scope: $scope,
size: 'sm',
resolve: {
items: function () {
return $rootScope.items;
}
}
});
angular.forEach (vm.professor.courses[selectedCourse.index].sections[selectedSection.index].students,
function (value){
if(value.id == vm.estudiante.Cedula) duplicated = true;
});
if (!duplicated){
vm.professor.courses[selectedCourse.index].sections[selectedSection.index].students.push(person);
professors.update({ id: professorid }, vm.professor,
function(){
$rootScope.botonOk = true;
$rootScope.urlLo = 'actualizarMatricula';
$rootScope.mensaje = "Estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre + " agregado";
$rootScope.crearEstudianteLoading = false;
},
function(){
$rootScope.botonOk = true;
$rootScope.urlLo = 'actualizarMatricula';
$rootScope.mensaje = "Error al agregar al estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre;
$rootScope.crearEstudianteLoading = false;
});
} else {
$rootScope.botonOk = true;
$rootScope.urlLo = 'actualizarMatricula';
$rootScope.mensaje = "Estudiante con cedula " + vm.estudiante.Cedula + " ya esta en la lista.";
$rootScope.crearEstudianteLoading = false;
}
}else{
vm.submitted = true;
}
}
$scope.ok = function (urlLo) {
$location.url(urlLo);
$scope.modalInstance.dismiss('cancel');
};
$scope.cancel = function () {
$scope.modalInstance.dismiss('cancel');
};
$rootScope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$rootScope.opened = true;
};
return vm;
};
actualizarEstudianteCtrl.$inject = [ '$scope','$rootScope', '$location', 'students', '$modal', 'estudianteSeleccionado' ];
function actualizarEstudianteCtrl ( $scope, $rootScope, $location, students, $modal, estudianteSeleccionado ){
var vm = this;
vm.estudiante = estudianteSeleccionado;
$rootScope.mensaje = "";
$rootScope.actOk = false;
vm.submit = function() {
var student = {
"_id": vm.estudiante._id,
"id": vm.estudiante.Cedula,
"name": vm.estudiante.Nombre,
"lastname": vm.estudiante.Apellido,
"email": vm.estudiante.Correo,
"number": vm.estudiante.Telefono,
};
$rootScope.botonOk = false;
$rootScope.modificarEstudianteLoading = true;
$scope.modalInstance = $modal.open({
animation: $rootScope.animationsEnabled,
templateUrl: 'partials/students/modal/update_students_modal.html',
scope: $scope,
size: 'sm',
resolve: {
items: function () {
return $rootScope.items;
}
}
});
students.update(student,
function(){
$rootScope.botonOk = true;
$rootScope.botonCancelar = false;
$rootScope.urlLo = 'listarEstudiante';
$rootScope.mensaje = "Estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre + " actualizado";
},
function(){
$rootScope.botonOk = true;
$rootScope.botonCancelar = false;
$rootScope.urlLo = 'listarEstudiante';
$rootScope.mensaje = "Error al modificar al estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre;
});
}
$scope.ok = function (urlLo) {
$location.url(urlLo);
$scope.modalInstance.dismiss('cancel');
};
$scope.cancel = function () {
$scope.modalInstance.dismiss('cancel');
};
$rootScope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$rootScope.opened = true;
};
return vm;
};
})();

View File

@@ -14,62 +14,25 @@
getRoutes.$inject = ['$stateProvider', '$urlRouterProvider'];
function getRoutes($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise('/listarEstudiante');
$urlRouterProvider.otherwise('/StudentCreate');
$stateProvider
.state('listarEstudiante', {
url: '/listarEstudiante',
.state('StudentCreate', {
url: '/StudentCreate',
views: {
sidebar: {
templateUrl: 'partials/sidebar/sidebar.html',
controller: 'sidebarCtrl'
templateUrl: 'partials/sidebar/sidebar.html',
controller: 'SidebarCtrl'
},
navbar: {
templateUrl: 'partials/sidebar/navbar.html'
templateUrl: 'partials/sidebar/navbar.html'
},
content: {
templateUrl: 'partials/students/list_students.html',
controller: 'listarEstudianteCtrl',
controllerAs: 'vm'
}
}
})
.state('crearEstudiante', {
url: '/crearEstudiante',
views: {
sidebar: {
templateUrl: 'partials/sidebar/sidebar.html',
controller: 'sidebarCtrl'
},
navbar: {
templateUrl: 'partials/sidebar/navbar.html'
},
content: {
templateUrl: 'partials/students/create_students.html',
controller: 'crearEstudianteCtrl',
controllerAs: 'vm'
}
}
})
.state('actualizarEstudiante', {
url: '/actualizarEstudiante',
views: {
sidebar: {
templateUrl: 'partials/sidebar/sidebar.html',
controller: 'sidebarCtrl'
},
navbar: {
templateUrl: 'partials/sidebar/navbar.html'
},
content: {
templateUrl: 'partials/students/update_students.html',
controller: 'actualizarEstudianteCtrl',
controllerAs: 'vm'
}
}
templateUrl: 'partials/students/student_create.html',
controller: 'StudentCreateCtrl',
controllerAs: 'vm'
}
}
})
};
})();

View File

@@ -0,0 +1,103 @@
(function(){
'use strict';
angular
.module('app.student')
.controller('StudentCreateCtrl', StudentCreateCtrl)
StudentCreateCtrl.$inject = ['$scope', '$rootScope', '$state', 'professors', '$modal', 'selectedSection', 'selectedCourse'];
function StudentCreateCtrl($scope, $rootScope, $state, professors, $modal, selectedSection, selectedCourse){
var vm = this;
var duplicated = false;
var professorid = $rootScope.professorId;
vm.professor = {};
$rootScope.mensaje = "";
$rootScope.actOk = false;
professors.get({ id: professorid },
function (successResult){
vm.professor = successResult;
},
function (){
console.log("Error al obtener los datos.");
});
vm.submit = function() {
if (vm.data_input_form.$valid){
var person = {
"id": vm.estudiante.Cedula,
"name": vm.estudiante.Nombre,
"lastname": vm.estudiante.Apellido,
"email": vm.estudiante.Correo
};
$rootScope.crearEstudianteLoading = true;
$rootScope.botonOk = false;
$scope.modalInstance = $modal.open({
animation: $rootScope.animationsEnabled,
templateUrl: 'partials/students/modal/create_students_modal.html',
scope: $scope,
size: 'sm',
resolve: {
items: function () {
return $rootScope.items;
}
}
});
angular.forEach (vm.professor.courses[selectedCourse.index].sections[selectedSection.index].students,
function (value){
if(value.id == vm.estudiante.Cedula) duplicated = true;
});
if (!duplicated){
vm.professor.courses[selectedCourse.index].sections[selectedSection.index].students.push(person);
professors.update({ id: professorid }, vm.professor,
function(){
$rootScope.botonOk = true;
$rootScope.urlLo = 'actualizarMatricula';
$rootScope.mensaje = "Estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre + " agregado";
$rootScope.crearEstudianteLoading = false;
},
function(){
$rootScope.botonOk = true;
$rootScope.mensaje = "Error al agregar al estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre;
$rootScope.crearEstudianteLoading = false;
});
} else {
$rootScope.botonOk = true;
$rootScope.mensaje = "Estudiante con cedula " + vm.estudiante.Cedula + " ya esta en la lista.";
$rootScope.crearEstudianteLoading = false;
}
}else{
vm.submitted = true;
}
}
$scope.ok = function (urlLo) {
$state.go('SectionUpdate');
$scope.modalInstance.dismiss('cancel');
};
$scope.cancel = function () {
$scope.modalInstance.dismiss('cancel');
};
$rootScope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$rootScope.opened = true;
};
vm.back = function () {
$state.go('SectionUpdate');
};
return vm;
};
})();

View File

@@ -79,5 +79,5 @@
</div>
</div>
</form>
<a href="#actualizarMatricula" class="btn-warning btn" style=" margin: 10px">Regresar</a>
<a class="btn-warning btn" style="margin: 10px" ng-click="vm.back()">Regresar</a>
</div>