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

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

View File

@@ -33,7 +33,7 @@
</div>
</div>
<!-- Thirdpary JavaScript and modules. -->
<!-- Thirdparty JavaScript and modules. -->
<!-- ================================================== -->
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
@@ -62,33 +62,33 @@
<!-- Application Javascript -->
<!-- ====================================================-->
<script src="js/app.js"></script>
<script src="app.js"></script>
<script src="js/course/course.module.js"></script>
<script src="js/course/course.controllers.js"></script>
<script src="js/course/course.services.js"></script>
<script src="partials/course/course.module.js"></script>
<script src="partials/course/course.controllers.js"></script>
<script src="partials/course/course.services.js"></script>
<script src="js/login/login.module.js"></script>
<script src="js/login/login.controllers.js"></script>
<script src="js/login/login.services.js"></script>
<script src="partials/login/login.module.js"></script>
<script src="partials/login/login.controllers.js"></script>
<script src="partials/login/login.services.js"></script>
<script src="js/professor/professor.module.js"></script>
<script src="js/professor/professor.controllers.js"></script>
<script src="js/professor/professor.services.js"></script>
<script src="partials/professor/professor.module.js"></script>
<script src="partials/professor/professor.controllers.js"></script>
<script src="partials/professor/professor.services.js"></script>
<script src="js/report/report.module.js"></script>
<script src="js/report/report.controllers.js"></script>
<script src="js/report/report.services.js"></script>
<script src="partials/report/report.module.js"></script>
<script src="partials/report/report.controllers.js"></script>
<script src="partials/report/report.services.js"></script>
<script src="js/section/section.module.js"></script>
<script src="js/section/section.controllers.js"></script>
<script src="js/section/section.services.js"></script>
<script src="partials/section/section.module.js"></script>
<script src="partials/section/section.controllers.js"></script>
<script src="partials/section/section.services.js"></script>
<script src="js/sidebar/sidebar.controllers.js"></script>
<script src="partials/sidebar/sidebar.controllers.js"></script>
<script src="js/student/student.module.js"></script>
<script src="js/student/student.controllers.js"></script>
<script src="js/student/student.services.js"></script>
<script src="partials/students/student.module.js"></script>
<script src="partials/students/student.controllers.js"></script>
<script src="partials/students/student.services.js"></script>
<!-- Angular ui.bootstrap's Javascript instead of Bootstrap Javascript -->
<!-- ==================================================== -->

View File

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

View File

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

View File

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

View File

@@ -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',

View File

@@ -7,52 +7,52 @@
<thead>
<tr>
<th width="10%">
<a href="" ng-click="sortType = 'code';
sortReverse = !sortReverse">
Código
<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 = '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>
</th>
<th width="10%">
<a href=""
ng-click="sortType = 'credits';
sortReverse = !sortReverse">
Creditos
<span ng-show="sortType == 'credits' &&
!sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'credits' && sortReverse" class="fa fa-caret-up"></span>
</a>
</th>
<th width="50%" style="text-align: center">
<a href="">
<th width="40%" style="text-align: center">
Descripción
</a>
</th>
<th width="10%" style="text-align: center">
<a>Eliminar</a>
Secciones
</th>
<th width="10%" style="text-align: center">
Eliminar
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="course in vm.course | orderBy:sortType:sortReverse | filter:searchUser">
<tr ng-repeat="course in vm.course">
<td style="vertical-align:middle">{{ course.code }}</td>
<td style="vertical-align:middle">{{ course.name }}</td>
<td style="vertical-align:middle">{{ course.credits }}</td>
<td style="vertical-align:middle">{{ course.description }}</td>
<td style="text-align: center">
<span
title="Click aqui para ver Secciones"
class="glyphicon glyphicon-list"
aria-hidden="true"
ng-click="vm.listarSecciones($index)"
style="cursor:pointer"></span>
</td>
<td style="text-align: center">
<span
title="Click aqui para Eliminar la Materia"
@@ -61,10 +61,8 @@
ng-click="vm.eliminarMateriaModal($index)"
style="cursor:pointer"></span>
</td>
</tr>
</tbody>
</table>
</div>
<div ng-show=false > {{ vm.eliminarMateriaSplice(index, rsplice) }}</div>
</div>

View File

@@ -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; */
};
})();

View File

@@ -6,7 +6,7 @@
<div class="col-md-4 column">
</div>
<div class="col-md-4 column">
<label for="nickname">Nombre de Usuario</label>
<label for="nickname">Cedula de Identidad del Profesor</label>
<input type="text" class="form-control" id="nickname" name="nickname" ng-model="vm.user.Nickname" required/>
<div class="error" ng-show="vm.submitted && vm.data_input_form.nickname.$invalid">
<small class="error" ng-show="vm.data_input_form.nickname.$error.required">

View File

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

View File

@@ -4,7 +4,6 @@
angular
.module('app.login')
.factory('Login', Login)
.factory('Rol', Rol)
.factory('GetRol', GetRol)
.factory('hash', hash)
.value('algoritmo','SHA-1')
@@ -15,12 +14,6 @@
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');
};
GetRol.$inject = ['$resource','$rootScope'];

View File

@@ -75,6 +75,15 @@
El Formato del Número de Teléfono es incorrecto.
</small>
</div>
<div class="col-md-4 column">
<label for="password">Contraseña</label>
<input type="password" class="form-control" ng-model="vm.profesor.Password" maxlength="8" required/>
<div class="error" ng-show="vm.submitted && vm.data_input_form.password.$invalid">
<small class="error" ng-show="vm.data_input_form.password.$error.required">
La Contraseña del Profesor es obligatorio.
</small>
</div>
</div>
</div>
</div>
</div>

View File

@@ -6,31 +6,25 @@
<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>
Modificar
</th>
<th width="20%" style="text-align: center">
<a>Borrar</a>
Borrar
</th>
</tr>
</thead>
@@ -49,5 +43,4 @@
</tbody>
</table>
</div>
<div ng-show=false > {{ vm.removeProfesorSplice(index, rsplice) }}</div>
</div>

View File

@@ -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;

View File

@@ -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',

View File

@@ -4,6 +4,8 @@
angular
.module('app.professor')
.factory('professors', professors)
.value('selectedCourse',{})
.value('selectedSection',{})
.value('profesorSeleccionado',{});
professors.$inject = ['$resource','$rootScope'];

View File

@@ -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',

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>
@@ -73,5 +69,48 @@
</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

@@ -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(
professors.get({ id: professorid },
function (successResult){
vm.materias = 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;
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.actualizarMatricula = function() {
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.rsplice = false;
$rootScope.eliminarLoading = false;
$rootScope.mensaje = "¿Desea retirar al estudiante "+ vm.students[index].lastname +", "+ vm.students[index].name + "?";
@@ -256,24 +291,9 @@
};
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,
professors.update({ id: professorid }, vm.professor,
function (){
$rootScope.botonOk = false;
$rootScope.otroBotonOk = true;
@@ -286,7 +306,6 @@
$rootScope.botonCancelar = false;
$rootScope.mensaje = "Error al actualizar la Sección "+ vm.section.name;
});
}
};
$rootScope.open = function($event) {

View File

@@ -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',

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">
<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>
</a>
</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>
</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>
</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>

View File

@@ -14,7 +14,8 @@
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<div class="container-fluid">
<a href="#login" class="btn-warning btn" style=" margin: 10px">Salir</a>
</br>
<a href="#login" class="btn-danger btn" style=" margin: 10px">Salir</a>
</div>
</ul>
</div>

View File

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

View File

@@ -46,7 +46,7 @@
<br><br></div></div>
<div class="row">
<div class="col-md-4 column">
<label for="correo">Direccion de Correo</label>
<label for="correo">Dirección de Correo</label>
<input type="correo" class="form-control"
name="correo" ng-model="vm.estudiante.Correo"
ng-pattern="/^[a-z]+[a-z0-9._]+@[a-z]+\.[a-z.]{2,5}$/" placeholder="me@example.com" required/>
@@ -62,17 +62,6 @@
</small>
</div>
</div>
<div class="col-md-4 column">
<label for="telefono">Numero de Telefono</label>
<input type="telefono" class="form-control"
name="telefono" ng-model="vm.estudiante.Telefono"
ng-pattern="/\d{4}-\d{3}-\d{4}/" maxlength="13"
placeholder="0424-123-9876"/>
<small class="error"
ng-show="vm.data_input_form.telefono.$error.pattern">
El Formato del Numero de Telefono es incorrecto.
</small>
</div>
</div>
</div>
</div>
@@ -90,4 +79,5 @@
</div>
</div>
</form>
<a href="#actualizarMatricula" class="btn-warning btn" style=" margin: 10px">Regresar</a>
</div>

View File

@@ -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,
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 = 'listarEstudiante';
$rootScope.urlLo = 'actualizarMatricula';
$rootScope.mensaje = "Estudiante " + vm.estudiante.Apellido + ", " + vm.estudiante.Nombre + " agregado";
$rootScope.crearEstudianteLoading = false;
},
function(){
$rootScope.botonOk = true;
$rootScope.urlLo = 'listarEstudiante';
$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;
}
}

View File

@@ -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',

View File

@@ -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('/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');
console.log(req.params);
Professor.findOne(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){
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('/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...");
console.log(req.params);
Professor.findByIdAndRemove(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/: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('/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('/professors', function(req, res){
console.log('Received add professor request');
console.log(req.body);
db.Students.findAndModify({query:
db.DB.insert(req.body, function(docs){
console.log(docs);
res.json(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('/professors', function(req, res){
console.log("Received update professor request");
console.log(req.body);
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");
console.log("server running on port 3000");*/