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

@@ -0,0 +1,170 @@
(function(){
'use strict';
angular
.module('app.course')
.controller('listarMateriaCtrl',listarMateriaCtrl)
.controller('crearMateriaCtrl', crearMateriaCtrl)
listarMateriaCtrl.$inject =
['$scope', '$rootScope', '$location', 'professors', '$modal', 'profesorSeleccionado', 'selectedCourse'];
function listarMateriaCtrl($scope, $rootScope, $location, professors, $modal, profesorSeleccionado, selectedCourse) {
var vm = this;
var professorid = '56f5fd3a20047f3c15b05f0e';
professors.get({ id: professorid },
function (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;
$rootScope.botonOk = true;
$rootScope.otroBotonOk = false;
$rootScope.botonCancelar = true;
$rootScope.rsplice = false;
$rootScope.mensaje = "¿Seguro que desea eliminar la materia?";
$scope.modalInstance = $modal.open({
animation: $rootScope.animationsEnabled,
templateUrl: '/partials/course/modal/delete_course_modal.html',
scope: $scope,
size: 'sm',
resolve: {
items: function () {
return "";
}
}
});
};
vm.eliminarMateria = function (index) {
$rootScope.botonOk = false;
$rootScope.otroBotonOk = true;
$rootScope.botonCancelar = false;
$rootScope.urlLo = 'listarMateria';
var name = vm.course[index].name;
vm.professor.courses.splice(index, 1);
professors.update({ id: professorid }, vm.professor,
function () {
$rootScope.mensaje = "Materia " + name + " eliminada";
},
function () {
$rootScope.mensaje = "Error eliminando la materia" + name;
});
};
/*vm.modificarMateria = function (index) {
$location.url('modificarMateria');
};*/
$scope.ok = function (urlLo) {
$location.url(urlLo);
$scope.modalInstance.dismiss('cancel');
};
$scope.cancel = function () {
$scope.modalInstance.dismiss('cancel');
};
$rootScope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$rootScope.opened = true;
};
return vm;
};
crearMateriaCtrl.$inject =
['$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() {
if (vm.data_input_form.$valid){
vm.course = {
"code": vm.course.code,
"name": vm.course.name,
"credits": vm.course.credits,
"description" : vm.course.description,
};
$scope.modalInstance = $modal.open({
animation: $rootScope.animationsEnabled,
templateUrl:
'/partials/course/modal/create_course_modal.html',
scope: $scope,
size: 'sm',
resolve: {
items: function () {
return $rootScope.items;
}
}
});
vm.professor.courses.push(vm.course);
professors.update({ id: professorid }, vm.professor,
function(){
$rootScope.botonOk = true;
$rootScope.urlLo = 'listarMateria';
$rootScope.mensaje =
"Materia " + vm.course.name + " creada";
},
function(){
$rootScope.botonOk = true;
$rootScope.urlLo = 'listarMateria';
$rootScope.mensaje =
"Error creando la materia " + vm.course.name;
});
}else{
vm.submitted = true;
}
}
$scope.ok = function (urlLo) {
$location.url(urlLo);
$scope.modalInstance.dismiss('cancel');
};
$scope.cancel = function () {
$scope.modalInstance.dismiss('cancel');
};
$rootScope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$rootScope.opened = true;
};
return vm;
};
})();

View File

@@ -0,0 +1,57 @@
(function(){
'use strict';
angular
.module("app.course", ['ui.router', 'ui.bootstrap'])
.run(addStateToScope)
.config(getRoutes);
addStateToScope.$inject = ['$rootScope', '$state', '$stateParams'];
function addStateToScope($rootScope, $state, $stateParams){
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
};
getRoutes.$inject = ['$stateProvider', '$urlRouterProvider'];
function getRoutes($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise('/listarMaterias');
$stateProvider
.state('listarMateria', {
url: '/listarMateria',
views: {
sidebar: {
templateUrl: 'partials/sidebar/sidebar.html',
controller: 'sidebarCtrl'
},
navbar: {
templateUrl: 'partials/sidebar/navbar.html'
},
content: {
templateUrl: 'partials/course/list_course.html',
controller: 'listarMateriaCtrl',
controllerAs: "vm"
}
}
})
.state('crearMateria', {
url: '/crearMateria',
views: {
sidebar: {
templateUrl: 'partials/sidebar/sidebar.html',
controller: 'sidebarCtrl'
},
navbar: {
templateUrl: 'partials/sidebar/navbar.html'
},
content: {
templateUrl: 'partials/course/create_course.html',
controller: 'crearMateriaCtrl',
controllerAs: "vm"
}
}
})
};
})();

View File

@@ -0,0 +1,12 @@
(function(){
'use strict';
angular
.module('app.course')
.factory('courses', courses);
courses.$inject = ['$resource','$rootScope'];
function courses($resource, $rootScope){
return $resource('http://'+$rootScope.domainUrl+'/courses/:id', null);
};
})();

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>
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>
</th>
<th width="20%">
<a href="" ng-click="sortType = 'name';
sortReverse = !sortReverse">
Nombre
<span ng-show="sortType == 'name' &&
!sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'name' &&
sortReverse" class="fa fa-caret-up"></span>
</a>
Nombre
<span ng-show="sortType == 'name' &&
!sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'name' &&
sortReverse" class="fa fa-caret-up"></span>
</th>
<th width="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>
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>
</th>
<th width="50%" style="text-align: center">
<a href="">
Descripción
</a>
<th width="40%" style="text-align: center">
Descripción
</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>