Adds dynamic page title.
Project: http://git-wip-us.apache.org/repos/asf/rave/repo Commit: http://git-wip-us.apache.org/repos/asf/rave/commit/87988b66 Tree: http://git-wip-us.apache.org/repos/asf/rave/tree/87988b66 Diff: http://git-wip-us.apache.org/repos/asf/rave/diff/87988b66 Branch: refs/heads/angular Commit: 87988b6606e8c27fd305121ca2bf0c2e31a43633 Parents: 6f11570 Author: Jmeas <[email protected]> Authored: Thu Aug 14 23:46:07 2014 -0400 Committer: Jmeas <[email protected]> Committed: Thu Aug 14 23:52:33 2014 -0400 ---------------------------------------------------------------------- rave-portal-ng/src/index.html | 2 +- .../src/providers/page-title/page-title.js | 54 ++++++++++++++++++++ rave-portal-ng/src/rave.js | 8 +-- .../preferences/controllers/preferences.js | 5 +- .../preferences/templates/preferences.html | 2 +- rave-portal-ng/src/subapps/admin/routes.js | 5 +- .../src/subapps/auth/create-account/routes.js | 5 +- .../src/subapps/auth/forgot-password/routes.js | 5 +- .../src/subapps/auth/forgot-username/routes.js | 5 +- rave-portal-ng/src/subapps/auth/login/routes.js | 5 +- rave-portal-ng/src/subapps/home/routes.js | 5 +- rave-portal-ng/src/subapps/profile/routes.js | 5 +- .../src/subapps/widget-store/routes.js | 5 +- 13 files changed, 96 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/index.html ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/index.html b/rave-portal-ng/src/index.html index cf21a69..2b44c5b 100644 --- a/rave-portal-ng/src/index.html +++ b/rave-portal-ng/src/index.html @@ -4,7 +4,7 @@ <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"> - <title>Apache Rave</title> + <title update-title>Apache Rave</title> <link rel="stylesheet" href="/style.css"> <link href="http://fonts.googleapis.com/css"> </head> http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/providers/page-title/page-title.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/providers/page-title/page-title.js b/rave-portal-ng/src/providers/page-title/page-title.js new file mode 100644 index 0000000..ea2204e --- /dev/null +++ b/rave-portal-ng/src/providers/page-title/page-title.js @@ -0,0 +1,54 @@ +/* + * pageTitle + * A directive that updates our page title. + * + * The title is made up of two parts: the base comes from the ui-router + * states, and the suffix comes from the configuration specified by the + * user. + * + */ + +define(function(require) { + var ng = require('angular'); + + var pageTitle = ng.module('pageTitle', []); + + pageTitle.directive('updateTitle', [ + '$rootScope', '$state', + function($rootScope, $state) { + + // We set our default values here. + var suffix = ''; + var defaultTitle = ''; + + // Generate our base title based on the ui-router. + var titleBase = function() { + var currentState = $state.current; + var data = currentState.data ? currentState.data : {}; + return data.title ? data.title : defaultTitle; + }; + + return { + link: function(scope, element) { + + // Listen to changes in the preferences. This can happen when + // the user updates the preferences from the admin panel, + // or during the initial page load. When that happens, we + // update the suffix, then the page title itself. + scope.$watch('preferences', function(newValue, oldValue) { + suffix = newValue.titleSuffix || ''; + element.text(titleBase() + suffix); + }); + + // Anytime the route change is successful we update our page + // title based on the + $rootScope.$on('$stateChangeSuccess', function() { + element.text(titleBase() + suffix); + }); + } + }; + } + ]); + + return pageTitle; +}); http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/rave.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/rave.js b/rave-portal-ng/src/rave.js index e78d00c..1f0fdac 100644 --- a/rave-portal-ng/src/rave.js +++ b/rave-portal-ng/src/rave.js @@ -21,6 +21,7 @@ define(function(require) { var widgetStore = require('./subapps/widget-store/widget-store'); var admin = require('./subapps/admin/admin'); var auth = require('./subapps/auth/auth'); + var pageTitle = require('./providers/page-title/page-title'); // Create an array out of our dependencies for Angular's DI var raveDependencies = [ @@ -32,6 +33,7 @@ define(function(require) { profile.name, auth.name, admin.name, + pageTitle.name, 'filters' ]; @@ -40,12 +42,12 @@ define(function(require) { // Some fake data until the mock API adds the Bootstrap route. rave.controller('appData', [ - '$scope', '$state', '$stateParams', - function($scope, $state, $stateParams) { + '$scope', '$state', '$stateParams', '$rootScope', + function($scope, $state, $stateParams, $rootScope) { $scope.nav = window._initialData.nav; $scope.loginNav = window._initialData.loginNav; - $scope.preferences = window.initialData.preferences; + $rootScope.preferences = window.initialData.preferences; // The ui-router doesn't do everything, unfortunately. So we need to // store our state data so we can make new directives for it. http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/subapps/admin/preferences/controllers/preferences.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/subapps/admin/preferences/controllers/preferences.js b/rave-portal-ng/src/subapps/admin/preferences/controllers/preferences.js index a71bdad..84b67b5 100644 --- a/rave-portal-ng/src/subapps/admin/preferences/controllers/preferences.js +++ b/rave-portal-ng/src/subapps/admin/preferences/controllers/preferences.js @@ -20,8 +20,8 @@ define(function(require) { 'javascriptDebugMode' ]; - return ['$scope', 'preferencesResource', 'preferences', 'preferencesMessages', - function($scope, preferencesResource, preferences, preferencesMessages) { + return ['$scope', 'preferencesResource', 'preferences', 'preferencesMessages', '$rootScope', + function($scope, preferencesResource, preferences, preferencesMessages, $rootScope) { $scope.messages = preferencesMessages; @@ -47,6 +47,7 @@ define(function(require) { ); updatedPreferences.$promise .then(function(res) { + $rootScope.preferences = res; preferencesMessages.showSuccess(); }) .catch(function(err) { http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/subapps/admin/preferences/templates/preferences.html ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/subapps/admin/preferences/templates/preferences.html b/rave-portal-ng/src/subapps/admin/preferences/templates/preferences.html index c706195..532d609 100644 --- a/rave-portal-ng/src/subapps/admin/preferences/templates/preferences.html +++ b/rave-portal-ng/src/subapps/admin/preferences/templates/preferences.html @@ -10,7 +10,7 @@ Page title suffix </label> <div class="controls"> - <input id="titleSuffix.value" name="titleSuffix.value" type="text" ng-model="preferences.titleSuffix"> + <input id="titleSuffix.value" name="titleSuffix.value" type="text" ng-model="preferences.titleSuffix" ng-trim="false"> </div> </div> <div class="control-group"> http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/subapps/admin/routes.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/subapps/admin/routes.js b/rave-portal-ng/src/subapps/admin/routes.js index 22f7d1f..65f8c3a 100644 --- a/rave-portal-ng/src/subapps/admin/routes.js +++ b/rave-portal-ng/src/subapps/admin/routes.js @@ -14,7 +14,10 @@ define(function(require) { $stateProvider.state('portal.admin', { url: '/app/admin', templateUrl: '/subapps/admin/templates/admin.html', - authenticate: true + authenticate: true, + data: { + title: 'Admin' + } }); } ]; http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/subapps/auth/create-account/routes.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/subapps/auth/create-account/routes.js b/rave-portal-ng/src/subapps/auth/create-account/routes.js index f5a81c4..59339ad 100644 --- a/rave-portal-ng/src/subapps/auth/create-account/routes.js +++ b/rave-portal-ng/src/subapps/auth/create-account/routes.js @@ -10,7 +10,10 @@ define(function(require) { $stateProvider.state('portal.createAccount', { url: '/create-account', templateUrl: '/subapps/auth/create-account/templates/create-account.html', - authenticate: 'no' + authenticate: 'no', + data: { + title: 'Create Account' + } }); } ]; http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/subapps/auth/forgot-password/routes.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/subapps/auth/forgot-password/routes.js b/rave-portal-ng/src/subapps/auth/forgot-password/routes.js index ef344b8..4d634f3 100644 --- a/rave-portal-ng/src/subapps/auth/forgot-password/routes.js +++ b/rave-portal-ng/src/subapps/auth/forgot-password/routes.js @@ -10,7 +10,10 @@ define(function(require) { $stateProvider.state('portal.forgotPassword', { url: '/forgot-password', templateUrl: '/subapps/auth/forgot-password/templates/forgot-password.html', - authenticate: 'no' + authenticate: 'no', + data: { + title: 'Forgot Password' + } }); } ]; http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/subapps/auth/forgot-username/routes.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/subapps/auth/forgot-username/routes.js b/rave-portal-ng/src/subapps/auth/forgot-username/routes.js index dc94207..865f8e9 100644 --- a/rave-portal-ng/src/subapps/auth/forgot-username/routes.js +++ b/rave-portal-ng/src/subapps/auth/forgot-username/routes.js @@ -10,7 +10,10 @@ define(function(require) { $stateProvider.state('portal.forgotUsername', { url: '/forgot-username', templateUrl: '/subapps/auth/forgot-username/templates/forgot-username.html', - authenticate: 'no' + authenticate: 'no', + data: { + title: 'Forgot Username' + } }); } ]; http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/subapps/auth/login/routes.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/subapps/auth/login/routes.js b/rave-portal-ng/src/subapps/auth/login/routes.js index b01d099..0adfe27 100644 --- a/rave-portal-ng/src/subapps/auth/login/routes.js +++ b/rave-portal-ng/src/subapps/auth/login/routes.js @@ -14,7 +14,10 @@ define(function(require) { $stateProvider.state('portal.login', { url: '/login', templateUrl: '/subapps/auth/login/templates/login.html', - authenticate: 'no' + authenticate: 'no', + data: { + title: 'Login' + } }); } ]; http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/subapps/home/routes.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/subapps/home/routes.js b/rave-portal-ng/src/subapps/home/routes.js index f97994d..d49ce63 100644 --- a/rave-portal-ng/src/subapps/home/routes.js +++ b/rave-portal-ng/src/subapps/home/routes.js @@ -19,7 +19,10 @@ define(function(require) { $stateProvider.state('portal.home', { url: '/home', templateUrl: '/subapps/home/templates/home.html', - authenticate: true + authenticate: true, + data: { + title: 'Home' + } }); } ]; http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/subapps/profile/routes.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/subapps/profile/routes.js b/rave-portal-ng/src/subapps/profile/routes.js index 0e91abf..c98c050 100644 --- a/rave-portal-ng/src/subapps/profile/routes.js +++ b/rave-portal-ng/src/subapps/profile/routes.js @@ -14,7 +14,10 @@ define(function(require) { $stateProvider.state('portal.profile', { url: '/profile', templateUrl: '/subapps/profile/templates/profile.html', - authenticate: true + authenticate: true, + data: { + title: 'Profile' + } }); } ]; http://git-wip-us.apache.org/repos/asf/rave/blob/87988b66/rave-portal-ng/src/subapps/widget-store/routes.js ---------------------------------------------------------------------- diff --git a/rave-portal-ng/src/subapps/widget-store/routes.js b/rave-portal-ng/src/subapps/widget-store/routes.js index 442b9b0..3794bb6 100644 --- a/rave-portal-ng/src/subapps/widget-store/routes.js +++ b/rave-portal-ng/src/subapps/widget-store/routes.js @@ -14,7 +14,10 @@ define(function(require) { $stateProvider.state('portal.widgetStore', { url: '/app/widget-store', templateUrl: '/subapps/widget-store/templates/widget-store.html', - authenticate: true + authenticate: true, + data: { + title: 'Widget Store' + } }); } ];
