Skip to content

Commit

Permalink
Add remaining API integrations & other issues (#119)
Browse files Browse the repository at this point in the history
- Add students delete
- Add admins delete button but no API endpoint found
- Add courses delete
- Add users change password

- Update HomeCtrl to redirect to user's profile
- Update sidebar items opened by default
- Add not found view
- Add server error view && (500 || 503) redirections
- Add footer to index and style it
  • Loading branch information
MatiasComercio authored Feb 5, 2017
1 parent 3d4af22 commit 87c82e8
Show file tree
Hide file tree
Showing 26 changed files with 260 additions and 172 deletions.
13 changes: 6 additions & 7 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@
<!-- ng-view -->
<div ng-view='' class='ng-view-container' autoscroll='true'></div>
<!-- \ng-view -->

<!-- footer -->
<div class='footer'>
<hr />
<p><span class='glyphicon glyphicon-heart'></span> from the Yeoman team</p>
</div>
<!-- \footer -->
</div>
<!-- \content -->

<!-- footer -->
<div class='footer'>
<span translate='i18nFooterCopyright'></span>
</div>
<!-- \footer -->
</div>
<!-- \dynamic content -->

Expand Down
82 changes: 5 additions & 77 deletions app/scripts/controllers/HomeCtrl.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,18 @@
'use strict';

define(['paw',
'services/navDataService',
'services/Students',
'services/Courses'],
'services/navDataService'],
function(paw) {
paw.controller('HomeCtrl',
['navDataService', 'Students', 'Courses', 'Paths',
function(navDataService, Students, Courses, Paths) {
['navDataService', '$location',
function(navDataService, $location) {
var _this = this;

this.fetchCourse = function() {
var course = {
courseId: '123',
name: 'Introducción a la informática y todoestechoclodetextoparaverqueandebien'
};
course.actions = Paths.getCourseActions(course, _this.user);
return course;
};

this.fetchAdmin = function() {
var admin = {
dni: 38457013,
firstName: '[ADMIN] Matías Nicolás',
lastName: 'Comercio Vázquez asdasdasdasdasdasdasdasdadasdasdas'
};
return admin;
};

this.fetchStudent = function() {
var student = {
dni: '38457013',
docket: 5,
firstName: 'Matías Nicolás',
lastName: 'Comercio Vázquez asdasdasdasdasdasdasdasdadasdasdas'
};
return student;
};

function fetchData() {
// this should be called on /admins/:dni views
_this.admin = _this.fetchAdmin();

// should be removed then
var admin = _this.admin;
if (admin) {
admin.fullName = admin.firstName + ' ' + admin.lastName;
}

// this should be called on /students/:docket views
_this.student = _this.fetchStudent();

// should be removed then
var student = _this.student;
if (student) {
student.fullName = student.firstName + ' ' + student.lastName;
}

// this should be called on /courses/:docket views
_this.course = _this.fetchCourse();
};
fetchData();

var getUserCallback = function() {
// get the user
_this.user = navDataService.get('user');
if (!_this.user) {
return; // nothing to set
if (_this.user) {
$location.path(_this.user.locationUrl);
}

var subSidebar = {};

// should be set on /admins/:dni views
subSidebar.admin = _this.admin;
subSidebar.admin.actions = Paths.getAdminActions(_this.admin, _this.user);

// should be set on /admins/:dni views
subSidebar.student = _this.student;
subSidebar.student.actions = Paths.getStudentActions(_this.student, _this.user);

// should be set on /admins/:dni views
subSidebar.course = _this.course;
subSidebar.course.actions = Paths.getCourseActions(_this.course, _this.user);

// register the current sidebar
navDataService.set('subSidebar', subSidebar);
};
navDataService.registerObserverCallback('user', getUserCallback);
getUserCallback();
Expand Down
10 changes: 10 additions & 0 deletions app/scripts/controllers/NotFoundCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

define(['paw', 'services/Paths'],
function(paw) {
paw.controller('NotFoundCtrl',
['Paths',
function(Paths) {
this.indexPath = Paths.get().index().path;
}]);
});
10 changes: 10 additions & 0 deletions app/scripts/controllers/ServerErrorCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

define(['paw', 'services/Paths'],
function(paw) {
paw.controller('ServerErrorCtrl',
['Paths',
function(Paths) {
this.indexPath = Paths.get().index().path;
}]);
});
38 changes: 18 additions & 20 deletions app/scripts/controllers/modals/DeleteCourseController.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
'use strict';

define(['paw', 'services/modalFactory'], function(paw) {
define(['paw', 'services/modalFactory', 'services/Courses',
'services/Paths', 'services/flashMessages'], function(paw) {
paw.controller('DeleteCourseController',
['modalFactory', '$log',
function (modalFactory, $log) {
['modalFactory', '$log', 'Courses', 'Paths', 'flashMessages',
function (modalFactory, $log, Courses, Paths, flashMessages) {
var modalTemplateUrl = 'views/modals/delete_course.html';
var onSuccess = function(url) {
$log.info('POST ' + url);
var onSuccess = function(course) {
Courses.remove(course).then(function() {
flashMessages.setSuccess('i18nCourseSuccessfullyDeleted');
Paths.get().courses().go();
});
};

var onFailure = function(msg) {
$log.info(msg);
};

this.open = function (size, url, id, name) {
var resolve = getResolve(url, id, name);
this.open = function (size, course) {
var resolve = getResolve(course);
modalFactory.create(size, 'DeleteCourseModalInstanceController', modalTemplateUrl, resolve, onSuccess, onFailure);
};
}]);

paw.controller('DeleteCourseModalInstanceController',
function ($uibModalInstance, url, id, name) {
this.id = id;
this.name = name;
function ($uibModalInstance, course) {
this.id = course.courseId;
this.name = course.name;

this.ok = function () {
$uibModalInstance.close(url);
$uibModalInstance.close(course);
};

this.cancel = function () {
$uibModalInstance.dismiss('Delete Course modal dismissed at: ' + new Date());
};
});

function getResolve(url, id, name) {
function getResolve(course) {
return {
url: function () {
return url;
},
id: function () {
return id;
},
name: function () {
return name;
course: function () {
return course;
}
};
};
Expand Down
50 changes: 26 additions & 24 deletions app/scripts/controllers/modals/DeleteUserController.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
'use strict';

define(['paw', 'services/modalFactory'], function(paw) {
define(['paw', 'services/modalFactory',
'services/Students', 'services/Admins', 'services/flashMessages', 'services/Paths'], function(paw) {
paw.controller('DeleteUserController',
['modalFactory', '$log',
function (modalFactory, $log) {
['modalFactory', '$log', 'Students', 'Admins', 'flashMessages', 'Paths',
function (modalFactory, $log, Students, Admins, flashMessages, Paths) {
var modalTemplateUrl = 'views/modals/delete_user.html';
var onSuccess = function(url) {
$log.info('POST ' + url);
var onSuccess = function(user) {
if (user.admin) {
Admins.remove(user).then(function() {
flashMessages.setSuccess('i18nAdminSuccessfullyDeleted');
Paths.get().admins().go();
});
} else {
Students.remove(user).then(function() {
flashMessages.setSuccess('i18nStudentSuccessfullyDeleted');
Paths.get().students().go();
});
}
};

var onFailure = function(msg) {
$log.info(msg);
};

this.open = function (size, url, dni, firstName, lastName) {
var resolve = getResolve(url, dni, firstName, lastName);
this.open = function (size, user) {
var resolve = getResolve(user);
modalFactory.create(size, 'DeleteUserModalInstanceController', modalTemplateUrl, resolve, onSuccess, onFailure);
};
}]);

paw.controller('DeleteUserModalInstanceController',
function($uibModalInstance, url, dni, firstName, lastName) {
this.dni = dni;
this.firstName = firstName;
this.lastName = lastName;
function($uibModalInstance, user) {
this.dni = user.dni;
this.firstName = user.firstName;
this.lastName = user.lastName;

this.ok = function () {
$uibModalInstance.close(url);
$uibModalInstance.close(user);
};

this.cancel = function () {
$uibModalInstance.dismiss('Delete User modal dismissed at: ' + new Date());
};
});

function getResolve(url, dni, firstName, lastName) {
function getResolve(user) {
return {
url: function () {
return url;
},
dni: function () {
return dni;
},
firstName: function () {
return firstName;
},
lastName: function () {
return lastName;
user: function () {
return user;
}
};
};
Expand Down
32 changes: 27 additions & 5 deletions app/scripts/controllers/user/UserChangePasswordCtrl.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
'use strict';

define(['paw'], function(paw) {
paw.controller('UserChangePasswordCtrl', ['$window',function($window) {
define(['paw', 'services/navDataService', 'services/flashMessages', 'services/Users'], function(paw) {
paw.controller('UserChangePasswordCtrl',
['$window', 'navDataService', 'flashMessages', 'Users', '$route',
function($window, navDataService, flashMessages, Users, $route) {
var _this = this;
_this.errors = [];

this.cancel = function() {
$window.history.back();
var getUserCallback = function() {
_this.user = navDataService.get('user');
};
navDataService.registerObserverCallback('user', getUserCallback);
getUserCallback();

this.changePassword = function(passwordForm) {
// Change Password
Users.updatePassword(passwordForm, _this.user.dni).then(function(response) {
flashMessages.setSuccess('i18nPasswordSuccessfullyUpdated');
$route.reload();
}, function(response) {
if (response.status === 409) { // dni repeated
_this.errors = [
'i18nWrongOriginalPassword'
];
return;
}
$log.warn(JSON.stringify(response));
flashMessages.setError('i18nFormErrors');
$route.reload();
});
};

this.cancel = function() {
$window.history.back();
};
}]);
});
1 change: 1 addition & 0 deletions app/scripts/directives/sidebarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ define(['paw'], function(paw) {
transclude: true,
templateUrl: 'views/directives/sidebar_item.html',
link: function(scope, element, attrs) {
scope.opened = true;
scope.select = function() {
scope.opened = !scope.opened;
};
Expand Down
32 changes: 26 additions & 6 deletions app/scripts/i18n/translations.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ define([], function() {
i18nAdminEdit: 'Editar perfil',
i18nAdminResetPassword: 'Resetear contraseña',
i18nAdminEditPassword: 'Cambiar contraseña',
i18nAdminDelete: 'Eliminar',

// Student subSidebar
i18nStudentShow: 'Ver perfil',
Expand Down Expand Up @@ -149,9 +150,9 @@ define([], function() {

// New
i18nCoursesButtonNew: 'Agregar',
i18nCourseWithCourseIdAlreadyExists: 'Ya existe un curso con ese código',
i18nCourseSuccessfullyCreated: 'El curso se ha creado exitosamente',
i18nCourseSuccessfullyUpdated: 'El curso se ha editado exitosamente',
i18nCourseWithCourseIdAlreadyExists: 'Ya existe una materia con ese código',
i18nCourseSuccessfullyCreated: 'La materia se ha creado exitosamente',
i18nCourseSuccessfullyUpdated: 'La materia se ha editado exitosamente',
i18nInvalidBirthday: 'La fecha debe ser anterior a la fecha actual',
i18nInvalidFinalExamDate: 'La fecha del examen debe ser posterior a la fecha actual',

Expand Down Expand Up @@ -187,8 +188,8 @@ define([], function() {

// Modals
i18nModalStudentDocket: 'Legajo del alumno',
i18nModalCourseName: 'Nombre del alumno',
i18nModalCourseId: 'Código del curso',
i18nModalCourseName: 'Nombre de la materia',
i18nModalCourseId: 'Código de la materia',
i18nModalCorrelativeName: 'Nombre de la correlativa',
i18nModalCorrelativeId: 'Código de la correlativa',
i18nModalStudentFullName: 'Nombre del alumno',
Expand All @@ -210,6 +211,25 @@ define([], function() {
i18nPasswordResetSuccess: 'La contraseña ha sido reseteada exitosamente',
i18nInvalidUsernameOrPassword: 'Usuario y/o contraseña incorrecta',
i18nStudentSuccessfullyCreated: 'El alumno se ha creado exitosamente',
i18nStudentSuccessfullyUpdated: 'El alumno se ha editado exitosamente'
i18nStudentSuccessfullyUpdated: 'El alumno se ha editado exitosamente',
i18nStudentSuccessfullyDeleted: 'El alumno se ha eliminado exitosamente',
i18nAdminSuccessfullyDeleted: 'El administrador se ha eliminado exitosamente',
i18nCourseSuccessfullyDeleted: 'La materia se ha eliminado exitosamente',
i18nPasswordSuccessfullyUpdated: 'La contraseña ha sido modificada exitosamente',
i18nWrongOriginalPassword: 'La contraseña actual es incorrecta',

// Not found page
i18nNotFoundPageTitle: 'Página no encontrada',
i18nNotFoundPageDescription: 'Parece que ha ingresado una URL inválida. Por favor, vaya al inicio y comience de nuevo',
i18nGoHome: 'Ir al inicio',

// Server error page
i18nServerErrorPageTitle: 'Ha ocurrido un error',
i18nServerErrorPageDescription: 'Disculpe las molestias ocasionadas. Trabajaremos para arreglar el problema lo antes posible. Vuelva a intentarlo más tarde',

// Footer
i18nFooterText: 'Desarrollado por alumnos de Ingeniería en Informática',
i18nFooterCopyright: 'SGA ITBA © Copyright 2017',
i18nFooterVersion: 'Versión: 2.0.0'
};
});
Loading

0 comments on commit 87c82e8

Please sign in to comment.