From c69644db6556af443dd2cd640edd740c8ff02909 Mon Sep 17 00:00:00 2001 From: Pierre Brisorgueil Date: Thu, 10 Aug 2017 07:47:01 +0200 Subject: [PATCH] feat(core): Enhancement page title directive (#1686) * fix(users): test for usernameOrEmail * Add comment to remind change for mongo replicaset connection * clean comment .. * Generic pageTitle concept * Revert "Generic pageTitle concept" This reverts commit ff00ec950f085ca3b6d1abb564eab1965ab0a56e. * align on meanjs state * fix atom beautify newline * align to mean indent * pageTitle directive automatic pageTitle directive fix loads add .. clean lodash dependencies clean code clean code & indent clean lodash * pageTitle directive automatic pageTitle directive fix loads add .. clean lodash dependencies clean code clean code & indent clean lodash --- .../client/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 | 14 +++++++++----- .../client/config/users-admin.client.routes.js | 9 +++------ 6 files changed, 20 insertions(+), 25 deletions(-) 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..a2d05f2de9 100644 --- a/modules/core/client/directives/page-title.client.directive.js +++ b/modules/core/client/directives/page-title.client.directive.js @@ -19,13 +19,17 @@ function listener(event, toState) { var applicationCoreTitle = 'MEAN.js', - separeteBy = ' - '; + separator = ' - ', + stateTitle = applicationCoreTitle + separator; + + toState.name.split('.').forEach(function(value, index) { + stateTitle = stateTitle + value.charAt(0).toUpperCase() + value.slice(1) + separator; + }); 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 + separator)(($state.$current.locals.globals)); } + stateTitle = stateTitle.slice(0, 0 - separator.length); + element.text(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 }}' } });