From 7fff896e43e8fdf445e6cc4520fc3ba7307152c1 Mon Sep 17 00:00:00 2001 From: Reynaldo Reyes Date: Sun, 27 Mar 2016 23:24:28 -0430 Subject: [PATCH] Update routes, mongoose schema and web flow --- app/{js => }/app.js | 19 +- app/index.html | 42 +-- app/js/login/login.controllers.js | 175 ----------- app/js/sidebar/sidebar.controllers.js | 97 ------ .../course/course.controllers.js | 49 ++-- app/{js => partials}/course/course.module.js | 8 +- .../course/course.services.js | 0 app/partials/course/list_course.html | 64 ++-- app/partials/login/login.controllers.js | 86 ++++++ app/{ => partials/login}/login.html | 2 +- app/{js => partials}/login/login.module.js | 8 +- app/{js => partials}/login/login.services.js | 9 +- app/partials/professor/create_professor.html | 9 + app/partials/professor/list_professor.html | 29 +- .../professor/professor.controllers.js | 11 +- .../professor/professor.module.js | 12 +- .../professor/professor.services.js | 2 + .../report/report.controllers.js | 0 app/{js => partials}/report/report.module.js | 4 +- .../report/report.services.js | 0 app/partials/section/create_section.html | 59 +++- app/partials/section/list_section.html | 22 +- .../section/section.controllers.js | 167 ++++++----- .../section/section.module.js | 13 +- .../section/section.services.js | 0 app/partials/section/update_section.html | 41 ++- app/partials/{ => sidebar}/navbar.html | 5 +- app/partials/sidebar/sidebar.controllers.js | 69 +++++ app/partials/{ => sidebar}/sidebar.html | 0 app/partials/students/create_students.html | 16 +- .../students}/student.controllers.js | 59 ++-- .../students}/student.module.js | 12 +- .../students}/student.services.js | 0 app/server.js | 277 ++++++++++++++---- 34 files changed, 735 insertions(+), 631 deletions(-) rename app/{js => }/app.js (68%) delete mode 100644 app/js/login/login.controllers.js delete mode 100644 app/js/sidebar/sidebar.controllers.js rename app/{js => partials}/course/course.controllers.js (77%) rename app/{js => partials}/course/course.module.js (85%) rename app/{js => partials}/course/course.services.js (100%) create mode 100644 app/partials/login/login.controllers.js rename app/{ => partials/login}/login.html (97%) rename app/{js => partials}/login/login.module.js (86%) rename app/{js => partials}/login/login.services.js (86%) rename app/{js => partials}/professor/professor.controllers.js (96%) rename app/{js => partials}/professor/professor.module.js (83%) rename app/{js => partials}/professor/professor.services.js (85%) rename app/{js => partials}/report/report.controllers.js (100%) rename app/{js => partials}/report/report.module.js (95%) rename app/{js => partials}/report/report.services.js (100%) rename app/{js => partials}/section/section.controllers.js (66%) rename app/{js => partials}/section/section.module.js (84%) rename app/{js => partials}/section/section.services.js (100%) rename app/partials/{ => sidebar}/navbar.html (87%) create mode 100644 app/partials/sidebar/sidebar.controllers.js rename app/partials/{ => sidebar}/sidebar.html (100%) rename app/{js/student => partials/students}/student.controllers.js (79%) rename app/{js/student => partials/students}/student.module.js (84%) rename app/{js/student => partials/students}/student.services.js (100%) diff --git a/app/js/app.js b/app/app.js similarity index 68% rename from app/js/app.js rename to app/app.js index 8536ab6..2ae0a7d 100644 --- a/app/js/app.js +++ b/app/app.js @@ -2,14 +2,14 @@ 'user strict'; angular.module('app', [ - 'app.course', - 'app.login', - 'app.professor', - 'app.reports', - 'app.section', - 'app.student', - 'ngResource', - 'ui.router' + 'app.course', + 'app.login', + 'app.professor', + 'app.reports', + 'app.section', + 'app.student', + 'ngResource', + 'ui.router' ]) .config(function($stateProvider, $urlRouterProvider) { @@ -21,7 +21,7 @@ url: '/login', views: { content: { - templateUrl: 'login.html', + templateUrl: 'partials/login/login.html', controller: 'loginCtrl', controllerAs: 'vm' } @@ -33,5 +33,4 @@ $rootScope.domainUrl = 'Localhost:3000'; }); - })(); diff --git a/app/index.html b/app/index.html index a024b96..6cd6bba 100644 --- a/app/index.html +++ b/app/index.html @@ -33,7 +33,7 @@ - + @@ -62,33 +62,33 @@ - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - - - + + + diff --git a/app/js/login/login.controllers.js b/app/js/login/login.controllers.js deleted file mode 100644 index 14c00ff..0000000 --- a/app/js/login/login.controllers.js +++ /dev/null @@ -1,175 +0,0 @@ -(function(){ - 'use strict'; - - angular - .module('app.login') - .controller('loginCtrl', loginCtrl) - .controller('ModalInstanceLoginCtrl', ModalInstanceLoginCtrl) - .constant('datepickerPopupConfig', { - datepickerPopup: 'yyyy-MM-dd', - html5Types: { - date: 'yyyy-MM-dd', - 'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss', - 'month': 'yyyy-MM' - }, - currentText: 'Hoy', - clearText: 'Limpiar', - closeText: 'Cerrar', - closeOnDateSelection: true, - appendToBody: false, - showButtonBar: true - }); - - - ModalInstanceLoginCtrl.$inject = ['$scope', '$modalInstance', 'items', '$location']; - function ModalInstanceLoginCtrl($scope, $modalInstance, items, $location){ - - $scope.items = items; - - $scope.okLogin = function (actOk, urlLo) { - //$modalInstance.close($scope.selected.item); - if(actOk){ - $location.url(urlLo); - $modalInstance.dismiss('cancel'); - } - }; - - $scope.cancel = function () { - $modalInstance.dismiss('cancel'); - }; - - - }; - - loginCtrl.$inject = ['$rootScope', '$location', 'Login', 'Rol','GetRol', 'hash', '$http', 'user', '$modal']; - function loginCtrl($rootScope, $location, Login, Rol, GetRol, hash, $http, user, $modal){ - var vm = this; - - - //$http.get("http://cesar:12316/api/Rol") - //.success(function(response) {$rootScope.namesw = response.Data;}); - - vm.user = user; - vm.submitted = false; - vm.mayorque = false; - $rootScope.items = ""; - $rootScope.mensaje = ""; - vm.submit = function() { - //var verificar = false; - if (vm.data_input_form.$valid){ - // se implementa todo lo necesario antes de pasar a la siguiente página. - vm.pkg = { - - "Nickname": vm.user.Nickname, - "Password": $rootScope.password - - }; - //$rootScope.mostrar = false; - $rootScope.loadingLogin = true; - $rootScope.mensaje = ""; - $rootScope.bcancel = false; - $modal.open({ - animation: $rootScope.animationsEnabled, - templateUrl: 'myModalContentLogin.html', - controller: 'ModalInstanceLoginCtrl', - size: 'sm', - resolve: { - items: function () { - return $rootScope.items; - } - } - }); - Login.save(vm.pkg, - function(data){ - //$rootScope.mostrar = true; - $rootScope.loadingLogin = false; - //verificar = data.Data._value; - if(data.Data._value != null){ - //$rootScope.bok = true; - $rootScope.actOk = true; - $rootScope.urlLo = 'mapasReportes'; - $rootScope.bcancel = false; - - }else{ - $rootScope.bcancel = true; - $rootScope.mensaje = data.Data._error; - } - }, - function(data){ - verificar = data.Data; - if(verificar){ - alert("no existe el usuario"); - } - - }) - GetRol.get({id:vm.user.Nickname}, function(data){ - $rootScope.role = data.Data; - } - - ); - - //$location.url('/preview/'); - }else{ - - vm.submitted = true; - } - } - - vm.onSelectChange = function () { - if(vm.genero == "Masculino"){ - $rootScope.Gender = "M"; - //alert("hola " + vm.valorRol.Name); - } - if(vm.genero == "Femenino"){ - $rootScope.Gender = "F"; - } - }; - - //$rootScope.password="s3cret"; - $rootScope.getHash = function(message) { - var hashResult = hash(message); - $rootScope.password = hashResult; - return hashResult; - }; - - vm.generos = ['', 'Masculino', 'Femenino']; - vm.genero = vm.generos[0]; - - Rol.get( - function(data){ - $rootScope.rol = data.Data; - } - ); - - - vm.toggleMin = function() { - vm.maxDate = vm.maxDate ? null : new Date(); - }; - vm.toggleMin(); - - $rootScope.open = function($event) { - $event.preventDefault(); - $event.stopPropagation(); - - $rootScope.opened = true; - }; - - $rootScope.open2 = function($eventt) { - $eventt.preventDefault(); - $eventt.stopPropagation(); - - $rootScope.openedd = true; - }; - - $rootScope.dateOptions = { - formatYear: 'yy', - startingDay: 1 - }; - - return vm; - }; - - - - -})(); diff --git a/app/js/sidebar/sidebar.controllers.js b/app/js/sidebar/sidebar.controllers.js deleted file mode 100644 index 657e7f7..0000000 --- a/app/js/sidebar/sidebar.controllers.js +++ /dev/null @@ -1,97 +0,0 @@ -(function(){ - 'use strict'; - - angular - .module('app') - .controller('sidebarCtrl', ['$scope', - function($scope) { - - var that = this; - $scope.showChilds = function(item){ - item.active = !item.active;}; - - $scope.items = [ - { - - text: 'Modulo de Administración', - subItems: [ - { - state: 'listarProfesor', - text: 'Listar Profesores' - }, - { - state: 'crearProfesor', - text: 'Agregar Profesores' - } - ] - }, - { - - text: 'Modulo de Materias', - subItems: [ - { - state: 'listarMateria', - text: 'Listar Materias' - }, - { - state: 'crearMateria', - text: 'Agregar Materia' - } - ] - }, - { - - text: 'Modulo de Estudiantes', - subItems: [ - { - state: 'listarEstudiante', - text: 'Listar Estudiantes' - }, - { - state: 'crearEstudiante', - text: 'Agregar Estudiantes' - } - ] - }, - { - - text: 'Modulo de Matriculas', - subItems: [ - { - state: 'listarMatricula', - text: 'Listar Matricula' - }, - { - state: 'crearMatricula', - text: 'Crear Matricula' - } - ] - }, - { - - text: 'Modulo de Reportes', - subItems: [ - { - state: 'reportesAlumno', - text: 'Reportes por Alumno' - }, - { - state: 'reportesClase', - text: 'Reportes por Clase' - }, - { - state: 'reportesSeccion', - text: 'Reportes por Seccion' - }, - { - state: 'reportesMateria', - text: 'Reportes por Materia' - } - ] - } - ]; - - - }]) - -})(); diff --git a/app/js/course/course.controllers.js b/app/partials/course/course.controllers.js similarity index 77% rename from app/js/course/course.controllers.js rename to app/partials/course/course.controllers.js index 8b49e78..99d3666 100644 --- a/app/js/course/course.controllers.js +++ b/app/partials/course/course.controllers.js @@ -7,21 +7,25 @@ .controller('crearMateriaCtrl', crearMateriaCtrl) - listarMateriaCtrl.$inject = - ['$scope', '$rootScope', '$location', 'courses', '$modal']; - function listarMateriaCtrl($scope, $rootScope, $location, courses, $modal) { + ['$scope', '$rootScope', '$location', 'professors', '$modal', 'profesorSeleccionado', 'selectedCourse']; + function listarMateriaCtrl($scope, $rootScope, $location, professors, $modal, profesorSeleccionado, selectedCourse) { var vm = this; - var array = []; + var professorid = '56f5fd3a20047f3c15b05f0e'; - courses.query( + professors.get({ id: professorid }, function (successResult){ - vm.course = successResult; + vm.professor = successResult; + vm.course = vm.professor.courses; }, function (){ console.log("Error al obtener los datos."); }); + vm.listarSecciones = function (index) { + selectedCourse._id = vm.course[index]._id; + $location.url('listarMatricula'); + }; vm.eliminarMateriaModal = function (index) { $rootScope.index = index; @@ -51,10 +55,10 @@ $rootScope.botonCancelar = false; $rootScope.urlLo = 'listarMateria'; var name = vm.course[index].name; + vm.professor.courses.splice(index, 1); - courses.delete({ id: vm.course[index]._id }, + professors.update({ id: professorid }, vm.professor, function () { - $rootScope.rsplice = true; $rootScope.mensaje = "Materia " + name + " eliminada"; }, function () { @@ -62,16 +66,9 @@ }); }; - vm.eliminarMateriaSplice = function(index, rsplice) { - if(rsplice){ - vm.course.splice(index, 1); - $rootScope.rsplice = false; - } - }; - - vm.modificarMateria = function (index) { + /*vm.modificarMateria = function (index) { $location.url('modificarMateria'); - }; + };*/ $scope.ok = function (urlLo) { $location.url(urlLo); @@ -92,13 +89,22 @@ }; crearMateriaCtrl.$inject = - ['$scope','$rootScope', '$modal', '$location', 'courses']; - function crearMateriaCtrl($scope, $rootScope, $modal, $location, courses) { - + ['$scope','$rootScope', '$modal', '$location', 'professors']; + function crearMateriaCtrl($scope, $rootScope, $modal, $location, professors) { var vm = this; vm.submitted = false; vm.mayorque = false; $rootScope.mensaje = ""; + var professorid = '56f5fd3a20047f3c15b05f0e'; + + professors.get({ id: professorid }, + function (successResult){ + vm.professor = successResult; + }, + function (){ + console.log("Error al obtener los datos."); + + }); vm.submit = function() { @@ -123,7 +129,8 @@ } }); - courses.save(vm.course, + vm.professor.courses.push(vm.course); + professors.update({ id: professorid }, vm.professor, function(){ $rootScope.botonOk = true; $rootScope.urlLo = 'listarMateria'; diff --git a/app/js/course/course.module.js b/app/partials/course/course.module.js similarity index 85% rename from app/js/course/course.module.js rename to app/partials/course/course.module.js index 1d595ca..a5a8b87 100644 --- a/app/js/course/course.module.js +++ b/app/partials/course/course.module.js @@ -21,11 +21,11 @@ url: '/listarMateria', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/course/list_course.html', @@ -39,11 +39,11 @@ url: '/crearMateria', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/course/create_course.html', diff --git a/app/js/course/course.services.js b/app/partials/course/course.services.js similarity index 100% rename from app/js/course/course.services.js rename to app/partials/course/course.services.js diff --git a/app/partials/course/list_course.html b/app/partials/course/list_course.html index 06894ef..9843517 100644 --- a/app/partials/course/list_course.html +++ b/app/partials/course/list_course.html @@ -7,52 +7,52 @@ - - Código - - - + Código + + - - Nombre - - - + Nombre + + - - Creditos - - - + Creditos + + - - - Descripción - + + + Descripción + - Eliminar + Secciones + + + Eliminar - - + {{ course.code }} {{ course.name }} {{ course.credits }} {{ course.description }} + + + - -
{{ vm.eliminarMateriaSplice(index, rsplice) }}
\ No newline at end of file diff --git a/app/partials/login/login.controllers.js b/app/partials/login/login.controllers.js new file mode 100644 index 0000000..f5fe6ff --- /dev/null +++ b/app/partials/login/login.controllers.js @@ -0,0 +1,86 @@ +(function(){ + 'use strict'; + + angular + .module('app.login') + .controller('loginCtrl', loginCtrl) + + loginCtrl.$inject = ['$rootScope', '$scope', '$location']; + function loginCtrl($rootScope, $scope, $location){ + /*var vm = this; + vm.user = user; + vm.submitted = false; + vm.mayorque = false; + $rootScope.items = ""; + $rootScope.mensaje = ""; + vm.submit = function() { + if (vm.data_input_form.$valid){ + vm.pkg = { + "Nickname": vm.user.Nickname, + "Password": $rootScope.password + }; + + $rootScope.mensaje = ""; + $rootScope.bcancel = false; + $scope.modalInstance = $modal.open({ + animation: $rootScope.animationsEnabled, + templateUrl: 'LoginModal.html', + scope: $scope, + size: 'sm', + resolve: { + items: function () { + return $rootScope.items; + } + } + }); + + Login.save(vm.pkg, + function(data){ + if(data.Data._value != null){ + $rootScope.actOk = true; + $rootScope.urlLo = 'listarProfesor'; + $rootScope.bcancel = false; + + }else{ + $rootScope.bcancel = true; + $rootScope.mensaje = data.Data._error; + } + }, + function(data){ + verificar = data.Data; + if(verificar){ + alert("no existe el usuario"); + } + }) + GetRol.get({id:vm.user.Nickname}, + function(data){ + $rootScope.role = data.Data; + }, + function(){ + + }); + + }else{ + vm.submitted = true; + } + } + + $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; */ + }; + +})(); diff --git a/app/login.html b/app/partials/login/login.html similarity index 97% rename from app/login.html rename to app/partials/login/login.html index 5e11b4e..e66f8c0 100644 --- a/app/login.html +++ b/app/partials/login/login.html @@ -6,7 +6,7 @@
- +
diff --git a/app/js/login/login.module.js b/app/partials/login/login.module.js similarity index 86% rename from app/js/login/login.module.js rename to app/partials/login/login.module.js index ec202c4..eb76e60 100644 --- a/app/js/login/login.module.js +++ b/app/partials/login/login.module.js @@ -1,5 +1,4 @@ (function(){ - 'use strict'; angular @@ -16,19 +15,16 @@ getRoutes.$inject = ['$stateProvider', '$urlRouterProvider']; function getRoutes($stateProvider, $urlRouterProvider){ $urlRouterProvider.otherwise('/'); - $stateProvider .state('root', { url: '', views: { content: { - templateUrl: 'login.html', - controller: 'LoginCtrl', + templateUrl: 'partials/login/login.html', + controller: 'loginCtrl', controllerAs: 'vm' } } }) - - }; })(); diff --git a/app/js/login/login.services.js b/app/partials/login/login.services.js similarity index 86% rename from app/js/login/login.services.js rename to app/partials/login/login.services.js index 5f2ca5b..8debeed 100644 --- a/app/js/login/login.services.js +++ b/app/partials/login/login.services.js @@ -4,7 +4,6 @@ angular .module('app.login') .factory('Login', Login) - .factory('Rol', Rol) .factory('GetRol', GetRol) .factory('hash', hash) .value('algoritmo','SHA-1') @@ -14,13 +13,7 @@ Login.$inject = ['$resource','$rootScope']; function Login($resource, $rootScope){ - return $resource('http://'+$rootScope.domainUrl+'/api/VerifyUser'); - - }; - - Rol.$inject = ['$resource','$rootScope']; - function Rol($resource, $rootScope){ - return $resource('http://'+$rootScope.domainUrl+'/api/Rol'); + return $resource('http://'+$rootScope.domainUrl+'/api/VerifyUser'); }; GetRol.$inject = ['$resource','$rootScope']; diff --git a/app/partials/professor/create_professor.html b/app/partials/professor/create_professor.html index 9cac0e3..057c6b2 100644 --- a/app/partials/professor/create_professor.html +++ b/app/partials/professor/create_professor.html @@ -75,6 +75,15 @@ El Formato del Número de Teléfono es incorrecto.
+
+ + +
+ + La Contraseña del Profesor es obligatorio. + +
+
diff --git a/app/partials/professor/list_professor.html b/app/partials/professor/list_professor.html index da24bb2..956c020 100644 --- a/app/partials/professor/list_professor.html +++ b/app/partials/professor/list_professor.html @@ -6,31 +6,25 @@ - - Cedula - - - + Cedula + + - - Nombre - - - + Nombre + + - - Apellido - - - + Apellido + + - Modificar + Modificar - Borrar + Borrar @@ -49,5 +43,4 @@ -
{{ vm.removeProfesorSplice(index, rsplice) }}
diff --git a/app/js/professor/professor.controllers.js b/app/partials/professor/professor.controllers.js similarity index 96% rename from app/js/professor/professor.controllers.js rename to app/partials/professor/professor.controllers.js index 9d157ac..26f9ee2 100644 --- a/app/js/professor/professor.controllers.js +++ b/app/partials/professor/professor.controllers.js @@ -19,8 +19,8 @@ var profesorArray = []; professors.query( - function(data){ - vm.profesor = data; + function (successResult){ + vm.profesor = successResult; angular.forEach(vm.profesor, function (value){ profesorArray.push({ Cedula:value.id, @@ -132,6 +132,8 @@ "lastname": vm.profesor.Apellido, "email": vm.profesor.Correo, "number": vm.profesor.Telefono, + "role": "professor", + "password": vm.profesor.Password }; $rootScope.botonOk = false; @@ -197,12 +199,13 @@ vm.submit = function() { var professor = { - "_id": vm.profesor._id, "id": vm.profesor.Cedula, "name": vm.profesor.Nombre, "lastname": vm.profesor.Apellido, "email": vm.profesor.Correo, "number": vm.profesor.Telefono, + "role": "professor", + "password": vm.profesor.Password }; $rootScope.botonOk = false; @@ -218,7 +221,7 @@ } }); - professors.update(professor, + professors.update({ id: vm.profesor._id}, professor, function(){ $rootScope.botonOk = true; $rootScope.botonCancelar = false; diff --git a/app/js/professor/professor.module.js b/app/partials/professor/professor.module.js similarity index 83% rename from app/js/professor/professor.module.js rename to app/partials/professor/professor.module.js index ab1a73d..2e8ae2a 100644 --- a/app/js/professor/professor.module.js +++ b/app/partials/professor/professor.module.js @@ -21,12 +21,12 @@ url: '/listarProfesor', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/professor/list_professor.html', @@ -40,11 +40,11 @@ url: '/crearProfesor', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/professor/create_professor.html', @@ -58,11 +58,11 @@ url: '/actualizarProfesor', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/professor/update_professor.html', diff --git a/app/js/professor/professor.services.js b/app/partials/professor/professor.services.js similarity index 85% rename from app/js/professor/professor.services.js rename to app/partials/professor/professor.services.js index 8e1b8c1..d03ee0f 100644 --- a/app/js/professor/professor.services.js +++ b/app/partials/professor/professor.services.js @@ -4,6 +4,8 @@ angular .module('app.professor') .factory('professors', professors) + .value('selectedCourse',{}) + .value('selectedSection',{}) .value('profesorSeleccionado',{}); professors.$inject = ['$resource','$rootScope']; diff --git a/app/js/report/report.controllers.js b/app/partials/report/report.controllers.js similarity index 100% rename from app/js/report/report.controllers.js rename to app/partials/report/report.controllers.js diff --git a/app/js/report/report.module.js b/app/partials/report/report.module.js similarity index 95% rename from app/js/report/report.module.js rename to app/partials/report/report.module.js index 6864232..13e124d 100644 --- a/app/js/report/report.module.js +++ b/app/partials/report/report.module.js @@ -22,11 +22,11 @@ url: '/reportes', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/reportes/reportes.html', diff --git a/app/js/report/report.services.js b/app/partials/report/report.services.js similarity index 100% rename from app/js/report/report.services.js rename to app/partials/report/report.services.js diff --git a/app/partials/section/create_section.html b/app/partials/section/create_section.html index 5906f30..b440097 100644 --- a/app/partials/section/create_section.html +++ b/app/partials/section/create_section.html @@ -2,25 +2,21 @@
-

Nueva Matricula

+

Nueva Sección


- +
+ ng-model="vm.course.code" required/>
@@ -72,6 +68,49 @@

-
+
+ + + + + + + + + + + + + + + +
+ + Cedula + + + + + + Apellido + + + + + + Nombre + + + +
{{ student.id }}{{ student.lastname }}{{ student.name }}
\ No newline at end of file diff --git a/app/partials/section/list_section.html b/app/partials/section/list_section.html index b8998b7..8714f71 100644 --- a/app/partials/section/list_section.html +++ b/app/partials/section/list_section.html @@ -1,50 +1,42 @@

Listado de Secciones


+ +
+
- - + @@ -65,5 +57,5 @@
- Sección - - Nombre de la Materia - - Codigo de la Materia - - Semestre - - Modificar + Modificar - Borrar + Borrar
{{ section.name }} {{ section.course }} {{ section.code }}
-
{{ vm.eliminarMatriculaSplice(index, rsplice) }}
+ Regresar
\ No newline at end of file diff --git a/app/js/section/section.controllers.js b/app/partials/section/section.controllers.js similarity index 66% rename from app/js/section/section.controllers.js rename to app/partials/section/section.controllers.js index 8cd6934..4020977 100644 --- a/app/js/section/section.controllers.js +++ b/app/partials/section/section.controllers.js @@ -7,15 +7,23 @@ .controller('crearMatriculaCtrl', crearMatriculaCtrl) .controller('actualizarMatriculaCtrl', actualizarMatriculaCtrl) - listarMatriculaCtrl.$inject = [ '$scope', '$rootScope', '$location', 'sections', '$modal', 'matriculaSeleccionada']; - function listarMatriculaCtrl ( $scope, $rootScope, $location, sections, $modal, matriculaSeleccionada ){ - + listarMatriculaCtrl.$inject = [ '$scope', '$rootScope', '$location', 'professors', '$modal', 'selectedCourse', 'selectedSection']; + function listarMatriculaCtrl ( $scope, $rootScope, $location, professors, $modal, selectedCourse, selectedSection ){ var vm = this; - var matriculaArray = []; + var professorid = '56f5fd3a20047f3c15b05f0e'; + vm.section = []; + vm.professor = null; - sections.query( + professors.get({ id: professorid }, function (successResult){ - vm.section = 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."); @@ -29,6 +37,11 @@ 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; @@ -57,7 +70,8 @@ $rootScope.urlLo = 'listarMatricula'; var name = vm.section[index].name; - sections.delete({ id: vm.section[index]._id }, + 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"; @@ -69,28 +83,21 @@ vm.eliminarMatriculaSplice = function (index, rsplice) { if(rsplice){ - vm.section.splice(index, 1); - $rootScope.rsplice = false; + } }; - /*************************Fin de Eliminar Matricula********************/ - + /*************************Fin de Eliminar Matricula*******************/ vm.modificarMatricula = function (index) { - 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; + selectedSection._id = vm.section[index]._id; + selectedCourse.index = vm.index; $location.url('actualizarMatricula'); }; $rootScope.open = function($event) { $event.preventDefault(); $event.stopPropagation(); - $rootScope.opened = true; }; @@ -107,30 +114,43 @@ }; crearMatriculaCtrl.$inject = - ['$scope','$rootScope', '$location', 'sections', '$modal', 'courses']; - function crearMatriculaCtrl($scope, $rootScope, $location, sections, $modal, courses){ - + ['$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 = []; - courses.query( - function (successResult) { - vm.materias = successResult; + 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 () { - vm.materias = null; - }); + function (){ + console.log("Error al obtener los datos."); + + }); + vm.submit = function () { if (vm.data_input_form.$valid){ vm.package = { "name": vm.name, - "code": vm.valorMateria.code, - "course": vm.valorMateria.name, + "code": vm.course.code, + "course": vm.course.name, "semester": vm.semester, "students": vm.students }; @@ -147,7 +167,8 @@ } }); - sections.save(vm.package, + vm.professor.courses[vm.index].sections.push(vm.package); + professors.update({ id: professorid }, vm.professor, function(){ $rootScope.botonOk = true; $rootScope.urlLo = 'listarMatricula'; @@ -180,7 +201,7 @@ /* Find desired cell containing semester and section */ vm.semester = worksheet['B5'].v; vm.name = worksheet['B9'].v; - $scope.$apply(); + //$scope.$apply(); for (z in worksheet) { /* all keys that do not begin with "!" correspond to cell addresses */ @@ -189,8 +210,9 @@ /* 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] =='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 = {}; @@ -198,6 +220,7 @@ } }; + $scope.$apply(); }; reader.readAsBinaryString(f); } @@ -219,26 +242,38 @@ return vm; }; - actualizarMatriculaCtrl.$inject = ['$scope', '$rootScope', '$location', 'sections', '$modal', 'matriculaSeleccionada']; - function actualizarMatriculaCtrl($scope, $rootScope, $location, sections, $modal, matriculaSeleccionada){ - + 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 = matriculaSeleccionada; - vm.students = matriculaSeleccionada.students; + 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.actualizarMatricula = function() { - - } + vm.addStudent = function (index) { + $location.url('crearEstudiante'); + }; vm.retirarEstudianteModal = function (index) { $rootScope.index = index; - $rootScope.botonOk = true; $rootScope.otroBotonOk = false; $rootScope.botonCancelar = true; - - $rootScope.rsplice = false; $rootScope.eliminarLoading = false; $rootScope.mensaje = "¿Desea retirar al estudiante "+ vm.students[index].lastname +", "+ vm.students[index].name + "?"; @@ -256,37 +291,21 @@ }; vm.retirarEstudiante = function (index) { - $rootScope.rsplice = true; - }; + vm.professor.courses[selectedCourse.index].sections[selectedSection.index].students.splice(index, 1); - vm.retirarEstudianteSplice = function(index, rsplice) { - if (rsplice) { - vm.students.splice(index, 1); - $rootScope.rsplice = false; - - 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; - }); - } + 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) { diff --git a/app/js/section/section.module.js b/app/partials/section/section.module.js similarity index 84% rename from app/js/section/section.module.js rename to app/partials/section/section.module.js index 93c6231..d8afa7e 100644 --- a/app/js/section/section.module.js +++ b/app/partials/section/section.module.js @@ -1,5 +1,4 @@ (function(){ - 'use strict'; angular @@ -23,11 +22,11 @@ url: '/listarMatricula', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/section/list_section.html', @@ -41,11 +40,11 @@ url: '/crearMatricula', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/section/create_section.html', @@ -59,11 +58,11 @@ url: '/actualizarMatricula', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/section/update_section.html', diff --git a/app/js/section/section.services.js b/app/partials/section/section.services.js similarity index 100% rename from app/js/section/section.services.js rename to app/partials/section/section.services.js diff --git a/app/partials/section/update_section.html b/app/partials/section/update_section.html index 246206b..06d0093 100644 --- a/app/partials/section/update_section.html +++ b/app/partials/section/update_section.html @@ -1,41 +1,42 @@

Estudiantes Inscritos en {{ vm.section.course }} - Seccion {{ vm.section.name }} - Semestre {{ vm.section.semester }}


+

- - + - + +
- - Cedula - - - + + Cedula + + - - Nombre - - - + Nombre + + - - Apellido - - - + Apellido + + - Retirar + + Correo + + + + Retirar
{{ student.id }} {{ student.name }} {{ student.lastname }}{{ student.email }}
- -
{{ vm.retirarEstudianteSplice(index, rsplice) }}
diff --git a/app/partials/navbar.html b/app/partials/sidebar/navbar.html similarity index 87% rename from app/partials/navbar.html rename to app/partials/sidebar/navbar.html index 63db001..22280f6 100644 --- a/app/partials/navbar.html +++ b/app/partials/sidebar/navbar.html @@ -13,8 +13,9 @@
diff --git a/app/partials/sidebar/sidebar.controllers.js b/app/partials/sidebar/sidebar.controllers.js new file mode 100644 index 0000000..a440304 --- /dev/null +++ b/app/partials/sidebar/sidebar.controllers.js @@ -0,0 +1,69 @@ +(function(){ + 'use strict'; + + angular + .module('app') + .controller('sidebarCtrl', sidebarCtrl) + + sidebarCtrl.$inject = ['$scope']; + function sidebarCtrl($scope) { + + var that = this; + $scope.showChilds = function(item){ + item.active = !item.active; + }; + + $scope.items = [ + { + + text: 'Modulo de Administración', + subItems: [ + { + state: 'listarProfesor', + text: 'Listar Profesores' + }, + { + state: 'crearProfesor', + text: 'Agregar Profesores' + } + ] + }, + { + + text: 'Modulo de Materias', + subItems: [ + { + state: 'listarMateria', + text: 'Listar Materias' + }, + { + state: 'crearMateria', + text: 'Agregar Materia' + } + ] + }, + { + + text: 'Modulo de Reportes', + subItems: [ + { + state: 'reportesAlumno', + text: 'Reportes por Alumno' + }, + { + state: 'reportesClase', + text: 'Reportes por Clase' + }, + { + state: 'reportesSeccion', + text: 'Reportes por Seccion' + }, + { + state: 'reportesMateria', + text: 'Reportes por Materia' + } + ] + } + ]; + }; +})(); diff --git a/app/partials/sidebar.html b/app/partials/sidebar/sidebar.html similarity index 100% rename from app/partials/sidebar.html rename to app/partials/sidebar/sidebar.html diff --git a/app/partials/students/create_students.html b/app/partials/students/create_students.html index 010574e..8eed4d3 100644 --- a/app/partials/students/create_students.html +++ b/app/partials/students/create_students.html @@ -46,7 +46,7 @@

- + @@ -62,17 +62,6 @@
-
- - - - El Formato del Numero de Telefono es incorrecto. - -
@@ -83,11 +72,12 @@

+ Agregar Alumno

+ Regresar \ No newline at end of file diff --git a/app/js/student/student.controllers.js b/app/partials/students/student.controllers.js similarity index 79% rename from app/js/student/student.controllers.js rename to app/partials/students/student.controllers.js index 49d3d70..cef6a1e 100644 --- a/app/js/student/student.controllers.js +++ b/app/partials/students/student.controllers.js @@ -116,13 +116,25 @@ return vm; }; - crearEstudianteCtrl.$inject = ['$scope','$rootScope', '$location', 'students', '$modal']; - function crearEstudianteCtrl($scope, $rootScope, $location, students, $modal){ + 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){ @@ -130,8 +142,7 @@ "id": vm.estudiante.Cedula, "name": vm.estudiante.Nombre, "lastname": vm.estudiante.Apellido, - "email": vm.estudiante.Correo, - "number": vm.estudiante.Telefono, + "email": vm.estudiante.Correo }; $rootScope.crearEstudianteLoading = true; @@ -148,22 +159,34 @@ } }); - students.save(person, - function(){ - $rootScope.botonOk = true; - $rootScope.urlLo = 'listarEstudiante'; - $rootScope.mensaje = "Estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre + " agregado"; - $rootScope.crearEstudianteLoading = false; - }, + 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); - function(){ - $rootScope.botonOk = true; - $rootScope.urlLo = 'listarEstudiante'; - $rootScope.mensaje = "Error al agregar al estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre; - $rootScope.crearEstudianteLoading = false; - }); + 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; } } diff --git a/app/js/student/student.module.js b/app/partials/students/student.module.js similarity index 84% rename from app/js/student/student.module.js rename to app/partials/students/student.module.js index 13f4f13..365607a 100644 --- a/app/js/student/student.module.js +++ b/app/partials/students/student.module.js @@ -21,12 +21,12 @@ url: '/listarEstudiante', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/students/list_students.html', @@ -40,11 +40,11 @@ url: '/crearEstudiante', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/students/create_students.html', @@ -58,11 +58,11 @@ url: '/actualizarEstudiante', views: { sidebar: { - templateUrl: 'partials/sidebar.html', + templateUrl: 'partials/sidebar/sidebar.html', controller: 'sidebarCtrl' }, navbar: { - templateUrl: 'partials/navbar.html' + templateUrl: 'partials/sidebar/navbar.html' }, content: { templateUrl: 'partials/students/update_students.html', diff --git a/app/js/student/student.services.js b/app/partials/students/student.services.js similarity index 100% rename from app/js/student/student.services.js rename to app/partials/students/student.services.js diff --git a/app/server.js b/app/server.js index b052f64..a7c328b 100644 --- a/app/server.js +++ b/app/server.js @@ -1,54 +1,201 @@ +var mongoose = require('mongoose'); var express = require('express'); var app = express(); -var mongojs = require('mongojs'); -var db = mongojs('AttendanceDB', - ['Courses', 'Professors', 'Sections', 'Students']); +var db = mongoose.connection; +//var Professor = require('./models/professor'); var bodyParser = require('body-parser'); app.use(express.static(__dirname)); app.use(bodyParser.json()); -app.get('/students', function(req, res){ - console.log('Received get all request'); - db.Students.find(function(err, docs){ +db.on('error', console.error); +db.once('open', function() { + + var assitanceSchema = new mongoose.Schema({ + day: Date + }); + + var studentSchema = new mongoose.Schema({ + id: Number, + name: String, + lastname: String, + email: String, + assistance: Number, + btaddress: String, + assistanceTotal: [Date] + }); + + var sectionSchema = new mongoose.Schema({ + name: String, + code: Number, + course: String, + semester: String, + assistance: Number, + students: [studentSchema] + }); + + var courseSchema = new mongoose.Schema({ + code: Number, + name: String, + credits: Number, + description: String, + sections: [sectionSchema] + }); + + var professorSchema = new mongoose.Schema({ + id: Number, + name: String, + lastname: String, + email: String, + number: String, + role: String, + password: String, + courses: [courseSchema] + }); + + var Professor = mongoose.model('Professor', professorSchema); + + //Professor CRUD + + app.get('/professors', function(req, res){ + console.log('Received get all professors request'); + Professor.find(function(err, docs){ + console.log(docs); + res.json(docs); + }) + }); + + app.get('/professors/:id', function(req, res){ + console.log('Received get professor request'); + console.log(req.params); + Professor.findOne(req.params.id, + function(err, docs){ + console.log(docs); + res.json(docs); + }) + }); + + app.post('/professors', function(req, res){ + console.log('Received add professor request'); + console.log(req.body); + + var professor = new Professor({ + id: req.body.id, + name: req.body.name, + lastname: req.body.lastname, + email: req.body.email, + number: req.body.number, + role: req.body.role, + password: req.body.password, + course: [ + { name:"Materia" } + ] + }) + + professor.save( + function(err, docs){ + console.log(docs); + res.json(docs); + }) + }); + + app.delete('/professors/:id', function(req, res){ + console.log("Received delete professor request..."); + console.log(req.params); + Professor.findByIdAndRemove(req.params.id, + function(err, docs){ + console.log(docs); + res.json(docs); + }); + }); + + app.put('/professors/:id', function(req, res){ + console.log("Received update professor request"); + console.log("params:" + req.params); + console.log("body:" + req.body); + Professor.findById(req.params.id, function (err, professor) { + if (err) + res.send(err); + if (typeof req.body.email != 'undefined') professor.email = req.body.email; + if (typeof req.body.number != 'undefined') professor.number = req.body.number; + if (typeof req.body.courses != 'undefined') professor.courses = req.body.courses; + + professor.save(function(err, docs){ + if (err) + res.send(err); + console.log(docs); + res.json(docs); + }); + }); + }); +}); + +mongoose.connect('mongodb://localhost/AttendanceDB'); + +app.listen(3000); +console.log("server running on port 3000"); + + +/*var debug = require('debug')('passport-mongo'); +var app = require('./app'); + +app.set('port', process.env.PORT || 3000); + +var server = app.listen(app.get('port'), function() { + debug('Express server listening on port ' + server.address().port); +});*/ +/* +var express = require('express'); +var app = express(); +var mongojs = require('mongojs'); +var db = mongojs('AttendanceDB', + ['DB', 'Courses', 'Professors', 'Sections', 'Students']); +var bodyParser = require('body-parser'); + +app.use(express.static(__dirname)); +app.use(bodyParser.json()); + +app.get('/professors', function(req, res){ + console.log('Received get all professors request'); + db.DB.find(function(err, docs){ console.log(docs); res.json(docs); }) }); -app.get('/students/:id', function(req, res){ - console.log('Received get request'); - db.Students.findOne( - {_id: new mongojs.ObjectId(req.params.id)}, function(err, docs){ +app.get('/professors/:id', function(req, res){ + console.log('Received get professor request'); + db.DB.findOne({_id: new mongojs.ObjectId(req.params.id)}, + function(err, docs){ console.log(docs); res.json(docs); }) }); -app.post('/students', function(req, res){ - console.log('Received add request'); +app.post('/professors', function(req, res){ + console.log('Received add professor request'); console.log(req.body); - db.Students.insert(req.body, function(docs){ + db.DB.insert(req.body, function(docs){ console.log(docs); res.json(docs); }) }); -app.delete('/students/:id', function(req, res){ - console.log("Received delete request..."); - db.Students.remove( - {_id: new mongojs.ObjectId(req.params.id)}, function(err, docs){ +app.delete('/professors/:id', function(req, res){ + console.log("Received delete professor request..."); + db.DB.remove({_id: new mongojs.ObjectId(req.params.id)}, + function(err, docs){ console.log(docs); res.json(docs); }); }); -app.put('/students', function(req, res){ - console.log("Received update request"); +app.put('/professors', function(req, res){ + console.log("Received update professor request"); console.log(req.body); - db.Students.findAndModify({query: + db.DB.findAndModify({query: {"_id": new mongojs.ObjectId(req.body._id)}, - update: {$set: {email: req.body.email, number: req.body.number}} + update: {$set: {email: req.body.email, number: req.body.number, courses: req.body.courses}} }, function(err, docs){ console.log(docs); res.json(docs); @@ -56,51 +203,63 @@ app.put('/students', function(req, res){ }); app.get('/courses', function(req, res){ - console.log('Received get all request'); - db.Courses.find(function(err, docs){ + console.log('Received get all courses request'); + db.DB.find(function(err, docs){ console.log(docs); res.json(docs); }) }); app.get('/courses/:id', function(req, res){ - console.log('Received get request'); - db.Courses.findOne( - {_id: new mongojs.ObjectId(req.params.id)}, function(err, docs){ + console.log('Received get courses request'); + db.DB.findOne({_id: new mongojs.ObjectId(req.params.id)}, + function(err, docs){ console.log(docs); res.json(docs); }) }); app.post('/courses', function(req, res){ - console.log('Received add request'); + console.log('Received add courses request'); console.log(req.body); - db.Courses.insert(req.body, function(docs){ + db.DB.insert(req.body, function(docs){ console.log(docs); res.json(docs); }) }); app.delete('/courses/:id', function(req, res){ - console.log("Received delete request..."); - db.Courses.remove( - {_id: new mongojs.ObjectId(req.params.id)}, function(err, docs){ + console.log("Received delete courses request..."); + db.DB.remove({_id: new mongojs.ObjectId(req.params.id)}, + function(err, docs){ console.log(docs); res.json(docs); }); }); +app.put('/courses', function(req, res){ + console.log("Received update courses request"); + console.log(req.body); + db.DB.findAndModify({query: + {"_id": new mongojs.ObjectId(req.body._id)}, + update: {$set: {sections: req.body.sections}} + }, function(err, docs){ + console.log(docs); + res.json(docs); + }) +}); + app.get('/sections', function(req, res){ - console.log('Received get all request'); - db.Sections.find(function(err, docs){ + console.log('Received get all sections request'); + db.DB.find(function(err, docs){ console.log(docs); res.json(docs); }) }); app.get('/sections/:id', function(req, res){ - console.log('Received get request'); - db.Sections.findOne( + console.log('Received get section request'); + db.DB.findOne( {_id: new mongojs.ObjectId(req.params.id)}, function(err, docs){ console.log(docs); res.json(docs); @@ -108,17 +267,17 @@ app.get('/sections/:id', function(req, res){ }); app.post('/sections', function(req, res){ - console.log('Received add request'); + console.log('Received add section request'); console.log(req.body); - db.Sections.insert(req.body, function(docs){ + db.DB.insert(req.body, function(docs){ console.log(docs); res.json(docs); }) }); app.delete('/sections/:id', function(req, res){ - console.log("Received delete request..."); - db.Sections.remove( + console.log("Received delete section request..."); + db.DB.remove( {_id: new mongojs.ObjectId(req.params.id)}, function(err, docs){ console.log(docs); res.json(docs); @@ -126,9 +285,9 @@ app.delete('/sections/:id', function(req, res){ }); app.put('/sections', function(req, res){ - console.log("Received update request"); + console.log("Received update section request"); console.log(req.body); - db.Sections.findAndModify({query: + db.DB.findAndModify({query: {"_id": new mongojs.ObjectId(req.body._id)}, update: {$set: {students: req.body.students}} }, function(err, docs){ @@ -137,45 +296,45 @@ app.put('/sections', function(req, res){ }) }); -app.get('/professors', function(req, res){ - console.log('Received get all request'); - db.Professors.find(function(err, docs){ +app.get('/students', function(req, res){ + console.log('Received get all students request'); + db.DB.find(function(err, docs){ console.log(docs); res.json(docs); }) }); -app.get('/professors/:id', function(req, res){ - console.log('Received get request'); - db.Professors.findOne({_id: new mongojs.ObjectId(req.params.id)}, - function(err, docs){ +app.get('/students/:id', function(req, res){ + console.log('Received get student request'); + db.DB.findOne( + {_id: new mongojs.ObjectId(req.params.id)}, function(err, docs){ console.log(docs); res.json(docs); }) }); -app.post('/professors', function(req, res){ - console.log('Received add request'); +app.post('/students', function(req, res){ + console.log('Received add student request'); console.log(req.body); - db.Professors.insert(req.body, function(docs){ + db.DB.insert(req.body, function(docs){ console.log(docs); res.json(docs); }) }); -app.delete('/professors/:id', function(req, res){ - console.log("Received delete request..."); - db.Professors.remove({_id: new mongojs.ObjectId(req.params.id)}, - function(err, docs){ +app.delete('/students/:id', function(req, res){ + console.log("Received delete student request..."); + db.DB.remove( + {_id: new mongojs.ObjectId(req.params.id)}, function(err, docs){ console.log(docs); res.json(docs); }); }); -app.put('/professors', function(req, res){ - console.log("Received update request"); +app.put('/students', function(req, res){ + console.log("Received update student request"); console.log(req.body); - db.Professors.findAndModify({query: + db.DB.findAndModify({query: {"_id": new mongojs.ObjectId(req.body._id)}, update: {$set: {email: req.body.email, number: req.body.number}} }, function(err, docs){ @@ -185,4 +344,4 @@ app.put('/professors', function(req, res){ }); app.listen(3000); -console.log("server running on port 3000"); \ No newline at end of file +console.log("server running on port 3000");*/ \ No newline at end of file