Skip to content

Commit

Permalink
Add new and edit API integrations (#114)
Browse files Browse the repository at this point in the history
- Add Admins setOnSubSidebar
- Add Students setOnSubSidebar
- Add Courses setOnSubSidebar
- Add admins new and edit views API integration
- Add students new and edit views API integration
- Add courses new and edit views API integration

- Add admins index filter
- Add students index authorities on buttons
  - If user is a student, only show my profile button
- Add front filters on
  - Admins index
  - Students index
  - Courses index
- Fix sidebar issue
  - Logging in as admin, logout, then as student may cause Admins sidebar
    section being enabled
- Fix small issues
  - Students grades career percentage text displaying with decimals
  - Date issue on admins and students new and edit views
  - Genre value on admins and students new and edit views
  - Update admins and students form validations on new and edit views
  • Loading branch information
MatiasComercio committed Feb 5, 2017
1 parent 433471b commit 9bb30a5
Show file tree
Hide file tree
Showing 27 changed files with 408 additions and 210 deletions.
3 changes: 3 additions & 0 deletions app/scripts/controllers/BodyCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ define(
_this.flashMessages.errors = flashMessages.getErrors();
_this.flashMessages.successes = flashMessages.getSuccesses();
flashMessages.clear();

// restart subSidebar
navDataService.remove('subSidebar');
});
}]);
}
Expand Down
70 changes: 30 additions & 40 deletions app/scripts/controllers/admins/AdminsEditCtrl.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
'use strict';

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

var dni = $routeParams.adminDni;
var dni = $routeParams.adminDni;

this.admin = {
firstName: 'Matías',
lastName: 'Mercado',
email: 'mmercado@itba.edu.ar',
genre: 'Masculino',
dni: '38917403',
birthday: '1995-05-04',
address: {
country: 'Argentina',
city: 'Buenos Aires',
neighborhood: 'Almagro',
number: '682',
street: 'Corrientes',
floor: '2',
door: 'A',
telephone: '1544683390',
zipCode: '1100'
}
};
Admins.get(dni).then(function(admin) {
_this.admin = admin;
Admins.setOnSubSidebar(admin);
_this.admin.birthday = new Date(_this.admin.birthday);
// Restangular method to clone the current admin object
_this.editedAdmin = Admins.copy(admin);
});

this.editedAdmin = angular.copy(this.admin);
this.update = function(admin) {
var editedAdmin = Admins.copy(admin);
editedAdmin.birthday = $filter('date')(admin.birthday, 'yyyy-MM-dd');
Admins.update(editedAdmin).then(function(response) {
flashMessages.setSuccess('i18nAdminSuccessfullyUpdated');
Paths.get().admins(_this.admin).go();
}, function(response) {
$log.warn(JSON.stringify(response));
flashMessages.setError('i18nFormErrors');
$route.reload();
});
};

this.cancel = function() {
$window.history.back();
};

this.update = function(editedAdmin) {
var path = Paths.get().admins(_this.admin);
$log.info('POST ' + path.absolutePath() + ' ' + JSON.stringify(editedAdmin));
path.go();
};
}]);
});
this.cancel = function() {
$window.history.back();
};
}]);
});
31 changes: 27 additions & 4 deletions app/scripts/controllers/admins/AdminsNewCtrl.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
'use strict';

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

_this.maxDate = new Date();

this.new = function(admin) {
_this.errors = [];
var newAdmin = angular.copy(admin);
newAdmin.birthday = $filter('date')(admin.birthday, 'yyyy-MM-dd');
Admins.new(newAdmin).then(function(response) {
flashMessages.setSuccess('i18nAdminSuccessfullyCreated');
Paths.get().admins().go();
}, function(response) {
if (response.status === 409) { // dni repeated
_this.errors = [
'i18nUserWithGIvenDNIExists'
];
return;
}
$log.warn(JSON.stringify(response));
flashMessages.setError('i18nFormErrors');
$route.reload();
});
};
this.cancel = function() {
$window.history.back();
Expand Down
8 changes: 2 additions & 6 deletions app/scripts/controllers/admins/AdminsShowCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
define(['paw','services/Admins','services/Paths'], function(paw) {
paw.controller('AdminsShowCtrl', ['$routeParams', 'Admins', '$log', 'Paths', function($routeParams, Admins, $log, Paths) {
var _this = this;
var dni = $routeParams.adminDni; // For future Service calls
var dni = $routeParams.adminDni;

Admins.get(dni).then(function(admin) {
_this.admin = admin;
}, function(response) {
$log.info('Response status: ' + response.status);
if (response.status === 404) {
Paths.get().notFound().go();
}
Admins.setOnSubSidebar(admin);
});
}]);
});
56 changes: 33 additions & 23 deletions app/scripts/controllers/courses/CoursesEditCtrl.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
'use strict';

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

this.course = {
courseId: '72.03',
credits: 3,
name: 'Introducción a Informática',
semester: 1
};
var courseId = $routeParams.courseId;

this.editedCourse = angular.copy(this.course);
Courses.get(courseId).then(function(course) {
_this.course = course;
Courses.setOnSubSidebar(course);
// Restangular method to clone the current course object
_this.editedCourse = Courses.copy(course);
});

this.update = function(editedCourse) {
var path = Paths.get().courses(_this.course);
$log.info('POST ' + path.absolutePath() + ' ' + JSON.stringify(editedCourse));
path.go();
};
this.update = function(course) {
_this.errors = [];
Courses.update(_this.course, course).then(function(response) {
flashMessages.setSuccess('i18nCourseSuccessfullyUpdated');
// redirect to the new course, possibly with new Id
Paths.get().courses({courseId: course.courseId}).go();
}, function(response) {
if (response.status === 409) { // course id repeated
_this.errors = [
'i18nCourseWithCourseIdAlreadyExists'
];
return;
}
$log.warn(JSON.stringify(response));
flashMessages.setError('i18nFormErrors');
$route.reload();
});
};

this.cancel = function() {
$window.history.back();
};
this.cancel = function() {
$window.history.back();
};
}]);
});
2 changes: 1 addition & 1 deletion app/scripts/controllers/courses/CoursesIndexCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ define(['paw','services/Courses','services/Paths'], function(paw) {
var _this = this;
this.filter = {
courseId: $routeParams.courseId,
courseName: $routeParams.courseName
name: $routeParams.courseName
};
this.resetSearch = function() {
this.filter = {};
Expand Down
22 changes: 19 additions & 3 deletions app/scripts/controllers/courses/CoursesNewCtrl.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
'use strict';

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

this.new = function(course) {
// Make API call
_this.errors = [];
Courses.new(course).then(function(response) {
flashMessages.setSuccess('i18nCourseSuccessfullyCreated');
Paths.get().courses().go();
}, function(response) {
if (response.status === 409) { // course id repeated
_this.errors = [
'i18nCourseWithCourseIdAlreadyExists'
];
return;
}
$log.warn(JSON.stringify(response));
flashMessages.setError('i18nFormErrors');
$route.reload();
});
};

this.cancel = function() {
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/courses/CoursesShowCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ define(['paw','services/Courses','services/Paths', 'controllers/modals/DeleteCor

Courses.get(courseId).then(function(course) {
_this.course = course;
Courses.setOnSubSidebar(course);
_this.course.getList('correlatives').then(function(correlatives) {
_this.course.correlatives = correlatives;
});
Expand Down
71 changes: 30 additions & 41 deletions app/scripts/controllers/students/StudentsEditCtrl.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,36 @@
'use strict';

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

var docket = $routeParams.docket;
var docket = $routeParams.docket;

this.student = {
docket: '55019',
firstName: 'Matías',
lastName: 'Mercado',
email: 'mmercado@itba.edu.ar',
genre: 'Masculino',
dni: '38917403',
birthday: '1995-05-04',
address: {
country: 'Argentina',
city: 'Buenos Aires',
neighborhood: 'Almagro',
number: '682',
street: 'Corrientes',
floor: '2',
door: 'A',
telephone: '1544683390',
zipCode: '1100'
}
};
Students.get(docket).then(function(student) {
_this.student = student;
Students.setOnSubSidebar(student);
_this.student.birthday = new Date(_this.student.birthday) || new Date();
// Restangular method to clone the current student object
_this.editedStudent = Students.copy(student);
});

this.editedStudent = angular.copy(this.student);
this.update = function(student) {
var editedStudent = Students.copy(student);
editedStudent.birthday = $filter('date')(student.birthday, 'yyyy-MM-dd');
Students.update(editedStudent).then(function(response) {
flashMessages.setSuccess('i18nStudentSuccessfullyUpdated');
Paths.get().students(_this.student).go();
}, function(response) {
$log.warn(JSON.stringify(response));
flashMessages.setError('i18nFormErrors');
$route.reload();
});
};

this.cancel = function() {
$window.history.back();
};

this.update = function(editedStudent) {
var path = Paths.get().students(_this.student);
$log.info('POST ' + path.absolutePath() + ' ' + JSON.stringify(editedStudent));
path.go();
};
}]);
});
this.cancel = function() {
$window.history.back();
};
}]);
});
16 changes: 11 additions & 5 deletions app/scripts/controllers/students/StudentsIndexCtrl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
define(['paw','services/Students','services/Paths'], function(paw) {
paw.controller('StudentsIndexCtrl', ['$routeParams', 'Students', '$log', 'Paths', function($routeParams, Students, $log, Paths) {
define(['paw','services/Students', 'services/Paths', 'services/navDataService'], function(paw) {
paw.controller('StudentsIndexCtrl',
['$routeParams', 'Students', '$log', 'Paths', 'navDataService',
function($routeParams, Students, $log, Paths, navDataService) {
var _this = this;
this.filter = {
docket: $routeParams.docket,
Expand All @@ -12,13 +14,17 @@ define(['paw','services/Students','services/Paths'], function(paw) {
this.filter = {};
};

var getUserCallback = function() {
_this.user = navDataService.get('user');
};
navDataService.registerObserverCallback('user', getUserCallback);
getUserCallback();

Students.getList().then(function(students) {
_this.students = students;
}, function(response) {
$log.info('Response status: ' + response.status);
if (response.status === 404) {
Paths.get().notFound().go();
}
Paths.get().notFound().go();
});

this.getStudentPath = function(docket) {
Expand Down
Loading

0 comments on commit 9bb30a5

Please sign in to comment.