Skip to content

Commit

Permalink
Add restric info/actions and paths logic (#128)
Browse files Browse the repository at this point in the history
- Add paths, info and actions restrictions for students access
- Add info/actions logic restriction based on app status
- Add filters to all remaining views
- Fix footer style to go to bottom if necessary
- Fix broken Paths links
- Fix error messages on some controller (e.g.: CourseEditCtrl)
- Remove edit grade on students grades
- Add navDataService saveUserOn method
- Add navDataService checkUserIsAdmin method
  - This is used to restrict admin access only
- Add subSidebar content on all remaining views
- Change default route to /not_found
- Updates final inscriptions logic to show, close, qualify, & being remove
- Update style of btn-info to btn-action
- Fix delete final redirection
- Fix problem of logging in/out having multiple tabs
- Fix some translations
  • Loading branch information
MatiasComercio committed Feb 6, 2017
1 parent 1ecfde0 commit 016848b
Show file tree
Hide file tree
Showing 42 changed files with 264 additions and 161 deletions.
1 change: 1 addition & 0 deletions app/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ require([
'angular',
'restangular',
'paw',
'services/navDataService',
'controllers/BodyCtrl'
],
function() {
Expand Down
3 changes: 3 additions & 0 deletions app/scripts/controllers/LoginCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ function(paw) {
function(Paths, $log, Authentication, navDataService, flashMessages, $route) {
var _this = this;

navDataService.remove('user');

this.login = function(user) {
// user would never be undefined as the form has to be valid before calling this method
// and that means that the user has to have some value defined
Authentication.login(user).then(function(authToken) {
navDataService.remove('user');
Authentication.setToken(authToken);
navDataService.fetchUser();
Paths.get().index().go();
Expand Down
9 changes: 6 additions & 3 deletions app/scripts/controllers/admins/AdminsNewCtrl.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
'use strict';

define(['paw', 'services/Admins', 'services/flashMessages'], function(paw) {
define(['paw', 'services/Admins', 'services/flashMessages', 'services/navDataService'
], function(paw) {
paw.controller('AdminsNewCtrl',
['$window', 'Paths', 'Admins', 'flashMessages', '$route', '$log', '$filter',
function($window, Paths, Admins, flashMessages, $route, $log, $filter) {
['$window', 'Paths', 'Admins', 'flashMessages', '$route', '$log', '$filter', 'navDataService',
function($window, Paths, Admins, flashMessages, $route, $log, $filter, navDataService) {
var _this = this;
_this.student = {};

_this.maxDate = new Date();

navDataService.checkUserIsAdmin();

this.new = function(admin) {
_this.errors = [];
var newAdmin = angular.copy(admin);
Expand Down
9 changes: 2 additions & 7 deletions app/scripts/controllers/courses/CoursesCorrelativesNewCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define(['paw','services/Courses','services/Paths', 'controllers/modals/AddCorrel
var courseId = $routeParams.courseId;

this.filter = {
id: $routeParams.id,
courseId: $routeParams.id,
name: $routeParams.name
};
this.resetSearch = function() {
Expand All @@ -15,19 +15,14 @@ define(['paw','services/Courses','services/Paths', 'controllers/modals/AddCorrel

Courses.get(courseId).then(function(course) {
_this.course = course;
Courses.setOnSubSidebar(course);
_this.course.all('correlatives').customGET('available').then(function(correlatives) {
_this.course.availableCorrelatives = correlatives;
});
}, function(response) {
$log.info('Response status: ' + response.status);
if (response.status === 404) {
Paths.get().notFound().go();
}
});

this.getCoursePath = function(courseId) {
return Paths.get().courses({courseId: courseId}).path;
};

}]);
});
20 changes: 15 additions & 5 deletions app/scripts/controllers/courses/CoursesEditCtrl.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'use strict';

define(['paw', 'services/Courses', 'services/flashMessages'], function(paw) {
define(['paw', 'services/Courses', 'services/flashMessages', 'services/navDataService'],
function(paw) {
paw.controller('CoursesEditCtrl',
['$window', 'Paths', 'Courses', 'flashMessages', '$route', '$log', '$filter', '$routeParams',
function($window, Paths, Courses, flashMessages, $route, $log, $filter, $routeParams) {
'navDataService',
function($window, Paths, Courses, flashMessages, $route, $log, $filter, $routeParams, navDataService) {
var _this = this;

var courseId = $routeParams.courseId;

navDataService.checkUserIsAdmin();

Courses.get(courseId).then(function(course) {
_this.course = course;
Courses.setOnSubSidebar(course);
Expand All @@ -23,9 +27,15 @@ define(['paw', 'services/Courses', 'services/flashMessages'], function(paw) {
Paths.get().courses({courseId: course.courseId}).go();
}, function(response) {
if (response.status === 409) { // course id repeated
_this.errors = [
'i18nCourseWithCourseIdAlreadyExists'
];
if (response.data.conflictField === 'semester') {
_this.errors = [
'i18nCourseInvalidSemesterLogic'
];
} else {
_this.errors = [
'i18nCourseWithCourseIdAlreadyExists'
];
}
return;
}
$log.warn(JSON.stringify(response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

define(['paw', 'services/Courses', 'services/flashMessages'], function(paw) {
paw.controller('CoursesFinalInscriptionNewCtrl',
['$routeParams', 'Courses', '$window', '$filter', 'flashMessages', '$log', '$route', 'Paths',
function($routeParams, Courses, $window, $filter, flashMessages, $log, $route, Paths) {

['$routeParams', 'Courses', '$window', '$filter', 'flashMessages', '$log', '$route', 'Paths', 'navDataService',
function($routeParams, Courses, $window, $filter, flashMessages, $log, $route, Paths, navDataService) {
var _this = this;
this.courseId = $routeParams.courseId;

navDataService.checkUserIsAdmin();

this.currentDate = new Date();

Courses.get(this.courseId).then(function(course) {
_this.course = course;
Courses.setOnSubSidebar(course);
}, function(response) {
$log.info('Response status: ' + response.status);
if (response.status === 404) {
Expand Down
24 changes: 19 additions & 5 deletions app/scripts/controllers/courses/CoursesFinalInscriptionShowCtrl.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
'use strict';

define(['paw','services/Courses','services/Paths', 'services/flashMessages'], function(paw) {
define(['paw','services/Courses','services/Paths', 'services/flashMessages',
'controllers/modals/DeleteFinalController',
'controllers/modals/CloseFinalController'],
function(paw) {
paw.controller('CoursesFinalInscriptionShowCtrl',
['$routeParams', 'Courses', '$log', 'Paths', 'flashMessages', '$route',
function($routeParams, Courses, $log, Paths, flashMessages, $route) {
['$routeParams', 'Courses', '$log', 'Paths', 'flashMessages', '$route', 'navDataService',
function($routeParams, Courses, $log, Paths, flashMessages, $route, navDataService) {
var _this = this;
var courseId = $routeParams.courseId;
var inscriptionId = $routeParams.inscriptionId;

this.qualifyAll = false;
navDataService.saveUserTo(_this);

this.qualifyAll = false;
this.qualify = function() {
var qualifiedStudents = _this.course.inscription.students.map(function(student) {
if (student.grade) {
Expand All @@ -18,9 +22,19 @@ define(['paw','services/Courses','services/Paths', 'services/flashMessages'], fu
}).filter(function(s) {
return s !== undefined;
});

if (qualifiedStudents.length === 0) {
_this.qualifyAll = !_this.qualifyAll;
return;
}

Courses.qualifyFinalInscription(_this.course, inscriptionId, qualifiedStudents).then(function(response) {
flashMessages.setSuccess('i18nQualifySuccessfully');
$route.reload();
if (response.status === 204) {
Paths.get().courses(_this.course).finalInscriptions().go();
} else {
$route.reload();
}
}, function(response) {
flashMessages.setError('i18nFormErrors');
$log.warn('[ERROR] - Response: ' + JSON.stringify(response));
Expand Down
8 changes: 5 additions & 3 deletions app/scripts/controllers/courses/CoursesNewCtrl.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict';

define(['paw', 'services/Paths', 'services/Courses', 'services/flashMessages'], function(paw) {
define(['paw', 'services/Paths', 'services/Courses', 'services/flashMessages', 'services/navDataService'], function(paw) {
paw.controller('CoursesNewCtrl',
['$window', 'Paths', 'Courses', '$log', '$route', 'flashMessages',
function($window, Paths, Courses, $log, $route, flashMessages) {
['$window', 'Paths', 'Courses', '$log', '$route', 'flashMessages', 'navDataService',
function($window, Paths, Courses, $log, $route, flashMessages, navDataService) {
var _this = this;

navDataService.checkUserIsAdmin();

this.new = function(course) {
_this.errors = [];
Courses.new(course).then(function(response) {
Expand Down
15 changes: 8 additions & 7 deletions app/scripts/controllers/courses/CoursesShowCtrl.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
'use strict';

define(['paw','services/Courses','services/Paths', 'controllers/modals/DeleteCorrelativeController', 'controllers/modals/DeleteFinalController', 'controllers/modals/CloseFinalController'], function(paw) {
paw.controller('CoursesShowCtrl', ['$routeParams', 'Courses', '$log', 'Paths', function($routeParams, Courses, $log, Paths) {
define(['paw','services/Courses','services/Paths',
'controllers/modals/DeleteCorrelativeController',
'controllers/modals/CloseFinalController'], function(paw) {
paw.controller('CoursesShowCtrl',
['$routeParams', 'Courses', '$log', 'Paths', 'navDataService',
function($routeParams, Courses, $log, Paths, navDataService) {
var _this = this;
var courseId = $routeParams.courseId;

navDataService.saveUserTo(_this);

Courses.get(courseId).then(function(course) {
_this.course = course;
Courses.setOnSubSidebar(course);
Expand All @@ -14,11 +20,6 @@ define(['paw','services/Courses','services/Paths', 'controllers/modals/DeleteCor
_this.course.getList('finalInscriptions').then(function(finalInscriptions) {
_this.course.finalInscriptions = finalInscriptions;
});
}, function(response) {
$log.info('Response status: ' + response.status);
if (response.status === 404) {
Paths.get().notFound().go();
}
});

this.getCorrelativePath = function(correlativeId) {
Expand Down
14 changes: 11 additions & 3 deletions app/scripts/controllers/courses/CoursesStudentsIndexCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
define(['paw','services/Courses','services/Paths',
'controllers/modals/UnenrollController', 'services/flashMessages'], function(paw) {
paw.controller('CoursesStudentsIndexCtrl',
['$routeParams', 'Courses', '$log', 'Paths', '$route', 'flashMessages',
function($routeParams, Courses, $log, Paths, $route, flashMessages) {
['$routeParams', 'Courses', '$log', 'Paths', '$route', 'flashMessages', 'navDataService',
function($routeParams, Courses, $log, Paths, $route, flashMessages, navDataService) {
var _this = this;
var courseId = $routeParams.courseId;

Expand All @@ -18,8 +18,9 @@ define(['paw','services/Courses','services/Paths',
this.filter = {};
};

this.qualifyAll = false;
navDataService.saveUserTo(_this);

this.qualifyAll = false;
this.qualify = function() {
var qualifiedStudents = _this.course.students.map(function(student) {
if (student.grade) {
Expand All @@ -28,6 +29,12 @@ define(['paw','services/Courses','services/Paths',
}).filter(function(s) {
return s !== undefined;
});

if (qualifiedStudents.length === 0) {
_this.qualifyAll = !_this.qualifyAll;
return;
}

Courses.qualify(_this.course, qualifiedStudents).then(function(response) {
flashMessages.setSuccess('i18nQualifySuccessfully');
$route.reload();
Expand All @@ -40,6 +47,7 @@ define(['paw','services/Courses','services/Paths',

Courses.get(courseId).then(function(course) {
_this.course = course;
Courses.setOnSubSidebar(course);
_this.course.getList('students').then(function(students) {
_this.course.students = students;
});
Expand Down
17 changes: 12 additions & 5 deletions app/scripts/controllers/courses/CoursesStudentsPassedCtrl.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
'use strict';

define(['paw','services/Courses','services/Paths'], function(paw) {
paw.controller('CoursesStudentsPassedCtrl', ['$routeParams', 'Courses', '$log', 'Paths', function($routeParams, Courses, $log, Paths) {
paw.controller('CoursesStudentsPassedCtrl',
['$routeParams', 'Courses', '$log', 'Paths', 'navDataService',
function($routeParams, Courses, $log, Paths, navDataService) {
var _this = this;
var courseId = $routeParams.courseId;

navDataService.saveUserTo(_this);

this.filter = {
docket: $routeParams.docket,
firstName: $routeParams.firstName,
lastName: $routeParams.lastName
student: {
docket: $routeParams.docket,
firstName: $routeParams.firstName,
lastName: $routeParams.lastName
}
};

this.resetSearch = function() {
this.filter = {};
this.filter.student = {};
};

Courses.get(courseId).then(function(course) {
_this.course = course;
Courses.setOnSubSidebar(course);
_this.course.all('students').customGET('passed').then(function(students) {
_this.course.passedStudents = students;
});
Expand Down
6 changes: 3 additions & 3 deletions app/scripts/controllers/modals/DeleteFinalController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

define(['paw', 'services/modalFactory', 'services/Courses', 'services/flashMessages'], function(paw) {
paw.controller('DeleteFinalController',
['modalFactory', '$log', 'Courses', '$route', 'flashMessages',
function (modalFactory, $log, Courses, $route, flashMessages) {
['modalFactory', '$log', 'Courses', '$route', 'flashMessages', 'Paths',
function (modalFactory, $log, Courses, $route, flashMessages, Paths) {
var modalTemplateUrl = 'views/modals/delete_final.html';
var onSuccess = function(result) {
Courses.deleteFinalInscription(result.courseId, result.id)
.then(function(response) {
flashMessages.setSuccess('i18nDeleteFinalSuccess');
$route.reload();
Paths.get().courses({courseId: result.courseId}).go();
}, function(response) {
flashMessages.setError('i18nFormErrors');
$log.warn('[ERROR] - Response: ' + JSON.stringify(response));
Expand Down
13 changes: 10 additions & 3 deletions app/scripts/controllers/students/StudentsCoursesIndexCtrl.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
'use strict';

define(['paw','services/Students','services/Paths', 'controllers/modals/UnenrollController'], function(paw) {
paw.controller('StudentsCoursesIndexCtrl', ['$routeParams', 'Students', '$log', 'Paths', function($routeParams, Students, $log, Paths) {
define(['paw','services/Students','services/Paths',
'services/navDataService',
'controllers/modals/UnenrollController'], function(paw) {
paw.controller('StudentsCoursesIndexCtrl',
['$routeParams', 'Students', '$log', 'Paths', 'navDataService',
function($routeParams, Students, $log, Paths, navDataService) {
var _this = this;
var docket = $routeParams.docket; // For future Service calls

this.filter = {
id: $routeParams.id,
courseId: $routeParams.id,
name: $routeParams.name
};
this.resetSearch = function() {
this.filter = {};
};

navDataService.saveUserTo(_this);

Students.get(docket).then(function(student) {
_this.student = student;
Students.setOnSubSidebar(student);

_this.student.getList('courses').then(function(courses) {
_this.student.courses = courses;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
'use strict';

define(['paw','services/Students','services/Paths', 'controllers/modals/FinalEnrollController', 'controllers/modals/FinalUnenrollController'], function(paw) {
paw.controller('StudentsFinalInscriptionsCtrl', ['$routeParams', 'Students', '$log', 'Paths', function($routeParams, Students, $log, Paths) {

define(['paw','services/Students','services/Paths',
'controllers/modals/FinalEnrollController',
'controllers/modals/FinalUnenrollController'],
function(paw) {
paw.controller('StudentsFinalInscriptionsCtrl',
['$routeParams', 'Students', '$log', 'Paths',
function($routeParams, Students, $log, Paths) {
var _this = this;
var docket = $routeParams.docket;

Students.get(docket).then(function(student) {
_this.student = student;
Students.setOnSubSidebar(student);

_this.student.getList('finalInscriptions').then(function(finalInscriptions) {
_this.student.finalInscriptionsTaken = finalInscriptions;
Expand All @@ -16,16 +21,10 @@ define(['paw','services/Students','services/Paths', 'controllers/modals/FinalEnr
_this.student.all('finalInscriptions').customGET('available').then(function(finalInscriptions) {
_this.student.finalInscriptionsAvailable = finalInscriptions;
});
}, function(response) {
$log.info('Response status: ' + response.status);
if (response.status === 404) {
Paths.get().notFound().go();
}
});

this.getFinalInscriptionPath = function(courseId, finalInscriptionId) {
return Paths.get().courses({courseId: courseId}).finals({inscriptionId: finalInscriptionId}).path;
};

}]);
});
Loading

0 comments on commit 016848b

Please sign in to comment.