From ff00ec950f085ca3b6d1abb564eab1965ab0a56e Mon Sep 17 00:00:00 2001 From: Pierre Date: Thu, 22 Dec 2016 08:02:54 +0100 Subject: [PATCH] Generic pageTitle concept --- bower.json | 3 ++- config/assets/default.js | 1 + config/assets/production.js | 1 + .../config/articles-admin.client.routes.js | 3 ++- .../client/config/articles.client.routes.js | 7 ++----- modules/chat/client/config/chat.client.routes.js | 3 +-- modules/core/client/config/core.client.routes.js | 9 +++------ .../directives/page-title.client.directive.js | 16 ++++++++++------ .../client/config/users-admin.client.routes.js | 9 +++------ 9 files changed, 25 insertions(+), 27 deletions(-) diff --git a/bower.json b/bower.json index 8a37c98b53..ec6b1a1764 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,8 @@ "angular-ui-router": "~0.2.18", "bootstrap": "~3.3.6", "ng-file-upload": "~12.1.0", - "owasp-password-strength-test": "~1.3.0" + "owasp-password-strength-test": "~1.3.0", + "lodash": "^4.6.1" }, "overrides": { "bootstrap": { diff --git a/config/assets/default.js b/config/assets/default.js index 8f38f70b99..14906f2d60 100644 --- a/config/assets/default.js +++ b/config/assets/default.js @@ -24,6 +24,7 @@ module.exports = { 'public/lib/angular-ui-notification/dist/angular-ui-notification.js', 'public/lib/angular-ui-router/release/angular-ui-router.js', 'public/lib/owasp-password-strength-test/owasp-password-strength-test.js', + 'public/lib/lodash/dist/lodash.js', // endbower ], tests: ['public/lib/angular-mocks/angular-mocks.js'] diff --git a/config/assets/production.js b/config/assets/production.js index 7f02f499b4..9d2018b8b6 100644 --- a/config/assets/production.js +++ b/config/assets/production.js @@ -24,6 +24,7 @@ module.exports = { 'public/lib/angular-ui-router/release/angular-ui-router.min.js', 'public/lib/ng-file-upload/ng-file-upload.min.js', 'public/lib/owasp-password-strength-test/owasp-password-strength-test.js', + 'public/lib/lodash/dist/lodash.min.js', // endbower ] }, diff --git a/modules/articles/client/config/articles-admin.client.routes.js b/modules/articles/client/config/articles-admin.client.routes.js index b493d0e0c4..877aeadb86 100644 --- a/modules/articles/client/config/articles-admin.client.routes.js +++ b/modules/articles/client/config/articles-admin.client.routes.js @@ -41,7 +41,8 @@ controller: 'ArticlesAdminController', controllerAs: 'vm', data: { - roles: ['admin'] + roles: ['admin'], + pageTitle: '{{ articleResolve.title }}' }, resolve: { articleResolve: getArticle diff --git a/modules/articles/client/config/articles.client.routes.js b/modules/articles/client/config/articles.client.routes.js index 4a94fa2e88..2638234d88 100644 --- a/modules/articles/client/config/articles.client.routes.js +++ b/modules/articles/client/config/articles.client.routes.js @@ -18,10 +18,7 @@ url: '', templateUrl: '/modules/articles/client/views/list-articles.client.view.html', controller: 'ArticlesListController', - controllerAs: 'vm', - data: { - pageTitle: 'Articles List' - } + controllerAs: 'vm' }) .state('articles.view', { url: '/:articleId', @@ -32,7 +29,7 @@ articleResolve: getArticle }, data: { - pageTitle: 'Article {{ articleResolve.title }}' + pageTitle: '{{ articleResolve.title }}' } }); } diff --git a/modules/chat/client/config/chat.client.routes.js b/modules/chat/client/config/chat.client.routes.js index f69aff6108..e141805448 100644 --- a/modules/chat/client/config/chat.client.routes.js +++ b/modules/chat/client/config/chat.client.routes.js @@ -15,8 +15,7 @@ controller: 'ChatController', controllerAs: 'vm', data: { - roles: ['user', 'admin'], - pageTitle: 'Chat' + roles: ['user', 'admin'] } }); } diff --git a/modules/core/client/config/core.client.routes.js b/modules/core/client/config/core.client.routes.js index c00f8807e0..0df4c89f8f 100644 --- a/modules/core/client/config/core.client.routes.js +++ b/modules/core/client/config/core.client.routes.js @@ -44,8 +44,7 @@ } }, data: { - ignoreState: true, - pageTitle: 'Not Found' + ignoreState: true } }) .state('bad-request', { @@ -59,16 +58,14 @@ } }, data: { - ignoreState: true, - pageTitle: 'Bad Request' + ignoreState: true } }) .state('forbidden', { url: '/forbidden', templateUrl: '/modules/core/client/views/403.client.view.html', data: { - ignoreState: true, - pageTitle: 'Forbidden' + ignoreState: true } }); } diff --git a/modules/core/client/directives/page-title.client.directive.js b/modules/core/client/directives/page-title.client.directive.js index 857d0b3603..29fcd8c034 100644 --- a/modules/core/client/directives/page-title.client.directive.js +++ b/modules/core/client/directives/page-title.client.directive.js @@ -1,4 +1,4 @@ -(function () { +(function() { 'use strict'; angular.module('core') @@ -19,13 +19,17 @@ function listener(event, toState) { var applicationCoreTitle = 'MEAN.js', - separeteBy = ' - '; + separeteBy = ' - ', + stateTitle = applicationCoreTitle + separeteBy; + + _.forEach(toState.name.split('.'), function(value, index) { + stateTitle = stateTitle + _.capitalize(value) + separeteBy; + }); if (toState.data && toState.data.pageTitle) { - var stateTitle = $interpolate(toState.data.pageTitle)($state.$current.locals.globals); - element.html(applicationCoreTitle + separeteBy + stateTitle); - } else { - element.html(applicationCoreTitle); + stateTitle = $interpolate(stateTitle + toState.data.pageTitle + separeteBy)(($state.$current.locals.globals)); } + stateTitle = stateTitle.slice(0, -3); + element.html(stateTitle); } } } diff --git a/modules/users/client/config/users-admin.client.routes.js b/modules/users/client/config/users-admin.client.routes.js index b978469589..cc509c0376 100644 --- a/modules/users/client/config/users-admin.client.routes.js +++ b/modules/users/client/config/users-admin.client.routes.js @@ -14,10 +14,7 @@ url: '/users', templateUrl: '/modules/users/client/views/admin/list-users.client.view.html', controller: 'UserListController', - controllerAs: 'vm', - data: { - pageTitle: 'Users List' - } + controllerAs: 'vm' }) .state('admin.user', { url: '/users/:userId', @@ -28,7 +25,7 @@ userResolve: getUser }, data: { - pageTitle: 'Edit {{ userResolve.displayName }}' + pageTitle: '{{ userResolve.displayName }}' } }) .state('admin.user-edit', { @@ -40,7 +37,7 @@ userResolve: getUser }, data: { - pageTitle: 'Edit User {{ userResolve.displayName }}' + pageTitle: '{{ userResolve.displayName }}' } });