Skip to content

Commit

Permalink
Add front end Paths Service (#72)
Browse files Browse the repository at this point in the history
- Apply Paths service usage on sidebar
- Migrate SidebarActions to Paths Service
- Add go() Paths method wrapping $location.path
- Refactor all string paths on the app to use the Paths Service
- Add navbar brand & logout ng-href using Paths service

Notes
- Paths Service is written so as to be able to run it when
  configuring the app's module
  • Loading branch information
MatiasComercio committed Feb 1, 2017
1 parent 2fc027d commit 873ce2b
Show file tree
Hide file tree
Showing 17 changed files with 557 additions and 240 deletions.
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html class='no-js'>
<head>
<meta charset='utf-8'>
<title>paw</title>
<title translate='i18nWebAbbreviation'></title>
<meta name='description' content=''>

<!-- build:css(.tmp) styles/main.css -->
Expand Down
96 changes: 21 additions & 75 deletions app/scripts/controllers/HomeCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ define(['paw',
'services/Courses'],
function(paw) {
paw.controller('HomeCtrl',
['navDataService', 'Students', 'Courses',
function(navDataService, Students, Courses) {
['navDataService', 'Students', 'Courses', 'Paths',
function(navDataService, Students, Courses, Paths) {
this.courses = [];
this.students = [];

Expand Down Expand Up @@ -46,96 +46,42 @@ function(paw) {
};

this.fetchCourse = function() {
return {
id: '123',
name: 'Introducción a la informática y todoestechoclodetextoparaverqueandebien',
actions: {
show: {
path: '/courses/123'
},
edit: {
path: '/courses/123/edit'
},
students: {
path: '/courses/123/students'
},
approved: {
path: '/courses/123/approved'
},
addCorrelative: {
path: '/courses/123/correlatives/new'
},
delete: {
path: '/courses/123/delete'
}
}
var course = {
courseId: '123',
name: 'Introducción a la informática y todoestechoclodetextoparaverqueandebien'
};
course.actions = Paths.getCourseActions(course);
return course;
};

this.fetchAdmin = function() {
return {
var admin = {
dni: '38457013',
firstName: '[ADMIN] Matías Nicolás',
lastName: 'Comercio Vázquez asdasdasdasdasdasdasdasdadasdasdas',
actions: {
show: {
path: '/admins/123'
},
edit: {
path: '/admins/123/edit'
},
resetPassword: {
path: '/admins/123/resetPassword'
},
updatePassword: {
path: '/admins/123/updatePassword'
}
}
lastName: 'Comercio Vázquez asdasdasdasdasdasdasdasdadasdasdas'
};
admin.actions = Paths.getAdminActions(admin);
return admin;
};

this.fetchStudent = function() {
return {
var student = {
dni: '38457013',
docket: '55',
firstName: 'Matías Nicolás',
lastName: 'Comercio Vázquez asdasdasdasdasdasdasdasdadasdasdas',
actions: {
show: {
path: '/students/123'
},
edit: {
path: '/students/123/edit'
},
resetPassword: {
path: '/students/123/resetPassword'
},
updatePassword: {
path: '/students/123/updatePassword'
},
courses: {
path: '/students/123/courses'
},
grades: {
path: '/students/123/grades'
},
inscriptions: {
path: '/students/123/inscriptions'
},
finals: {
path: '/students/123/finals'
},
delete: {
path: '/users/123/delete'
}
}
lastName: 'Comercio Vázquez asdasdasdasdasdasdasdasdadasdasdas'
};
student.actions = Paths.getStudentActions(student);
return student;
};



function fetchData() {
return {
// admin: _this.fetchAdmin()
student: _this.fetchStudent()
// course: _this.fetchCourse()
admin: _this.fetchAdmin(),
student: _this.fetchStudent(),
course: _this.fetchCourse()
};
};

Expand Down
8 changes: 4 additions & 4 deletions app/scripts/controllers/LoginCtrl.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';

define(['paw', 'restangular', 'services/Authentication'], function(paw) {
paw.controller('LoginCtrl', ['$location', '$log', 'Authentication',
function($location, $log, Authentication) {
define(['paw', 'restangular', 'services/Authentication', 'services/Paths'], function(paw) {
paw.controller('LoginCtrl', ['Paths', '$log', 'Authentication',
function(Paths, $log, Authentication) {
var _this = this;

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) {
Authentication.setToken(authToken);
$location.path('/');
Paths.get().index().go();
}, function(response) {
// here we should handle any issue and show a nice error message
$log.info('Response status: ' + response.status);
Expand Down
12 changes: 6 additions & 6 deletions app/scripts/controllers/students/StudentsEditCtrl.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';

define(['paw'], function(paw) {
define(['paw', 'services/Paths'], function(paw) {
paw.controller('StudentsEditCtrl', [
'$routeParams',
'$log',
'$window',
'$location',
function($routeParams, $log, $window, $location) {

'Paths',
function($routeParams, $log, $window, Paths) {
var _this = this;

var docket = $routeParams.docket;
Expand Down Expand Up @@ -40,8 +39,9 @@ define(['paw'], function(paw) {
};

this.update = function(editedStudent) {
$log.info('POST /students/' + docket + ' ' + JSON.stringify(editedStudent));
$location.path('/students/' + docket);
var path = Paths.get().students(_this.student);
$log.info('POST ' + path.absolutePath() + ' ' + JSON.stringify(editedStudent));
path.go();
};
}]);
});
9 changes: 7 additions & 2 deletions app/scripts/directives/navbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

define(['paw', 'services/navDataService'], function(paw) {
paw.directive('xnavbar', ['navDataService',function(navDataService) {
define(['paw', 'services/navDataService', 'services/Paths'], function(paw) {
paw.directive('xnavbar', ['navDataService', 'Paths', function(navDataService, Paths) {
function controller() {
this.user = {
fullName: 'Matías Nicolás Comercio Vázquez asdasdasdasdasdasdasdasdadasdasdas',
Expand All @@ -24,6 +24,11 @@ define(['paw', 'services/navDataService'], function(paw) {
scope: {},
bindToController: true,
link: function(scope, element, attributes) {
scope.paths = {
index: Paths.get().index().path,
logout: Paths.get().logout().path
};

scope.sidebarOpen = function() {
navDataService.set('sidebarOpen', !navDataService.get('sidebarOpen'));
};
Expand Down
84 changes: 43 additions & 41 deletions app/scripts/directives/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ define(
['paw',
'services/navDataService',
'services/windowSize',
'services/Paths',
'directives/sidebarItem',
'directives/preventScroll',
'directives/backdrop',
Expand All @@ -12,8 +13,8 @@ define(
'controllers/modals/DeleteUserController',
'controllers/modals/DeleteCourseController'],
function(paw) {
paw.directive('xsidebar', ['navDataService', 'windowSize',
function(navDataService, windowSize) {
paw.directive('xsidebar', ['navDataService', 'windowSize', 'Paths',
function(navDataService, windowSize, Paths) {
function controller(navDataService) {
this.sidebar = {};

Expand Down Expand Up @@ -41,7 +42,7 @@ define(
var inscriptionsEnabledCallback = function() {
if (_this.sidebar.admins) {
_this.sidebar.admins.actions.inscriptions.enabled =
navDataService.get('inscriptionsEnabled');
navDataService.get('inscriptionsEnabled');
}
};
navDataService.registerObserverCallback('inscriptionsEnabled', inscriptionsEnabledCallback);
Expand Down Expand Up @@ -87,50 +88,51 @@ define(
};
}
};
}]);

function sidebarAdmins() {
return {
actions: {
index: {
path: '/admins'
},
new: {
path: '/admins/new'
},
inscriptions: {
enabled: true,
path: '/courses/inscriptions'
function sidebarAdmins() {
return {
actions: {
index: {
path: Paths.get().admins().path
},
new: {
path: Paths.get().admins().new().path
},
inscriptions: {
enabled: true,
// +++xremove
path: '/courses/inscriptions'
}
}
}
};
}
};
}

function sidebarStudents() {
return {
actions: {
index: {
path: '/students'
},
new: {
path: '/students/new'
function sidebarStudents() {
return {
actions: {
index: {
path: Paths.get().students().path
},
new: {
path: Paths.get().students().new().path
}
}
}
};
}
};
}


function sidebarCourses() {
return {
actions: {
index: {
path: '/courses'
},
new: {
path: '/courses/new'
function sidebarCourses() {
return {
actions: {
index: {
path: Paths.get().courses().path
},
new: {
path: Paths.get().courses().new().path
}
}
}
};
}
};
}
}]);
}
);
4 changes: 2 additions & 2 deletions app/scripts/i18n/translations.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ define([], function() {
i18nAdminShow: 'Ver perfil',
i18nAdminEdit: 'Editar perfil',
i18nAdminResetPassword: 'Resetear contraseña',
i18nAdminUpdatePassword: 'Cambiar contraseña',
i18nAdminEditPassword: 'Cambiar contraseña',

// Student subSidebar
i18nStudentShow: 'Ver perfil',
i18nStudentEdit: 'Editar perfil',
i18nStudentResetPassword: 'Resetear contraseña',
i18nResetPasswordModalTitle: 'Resetear contraseña',
i18nStudentUpdatePassword: 'Cambiar contraseña',
i18nStudentEditPassword: 'Cambiar contraseña',
i18nStudentCourses: 'Materias en progreso',
i18nStudentGrades: 'Analítico de notas',
i18nStudentInscriptions: 'Matriculaciones',
Expand Down
Loading

0 comments on commit 873ce2b

Please sign in to comment.