From 8b271c4caf4f334e595475a188e1fbeafdf01ca6 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Mon, 16 May 2016 09:24:49 -0400 Subject: [PATCH 01/14] Promise-ify the call to /config and reduce number of calls to 1 per session. We'll also pull the config/license info from memory instead of local storage --- awx/ui/client/src/app.js | 57 +++-- .../src/bread-crumb/bread-crumb.partial.html | 2 +- .../src/license/checkLicense.factory.js | 66 +++--- .../src/license/checkLicense2.factory.js | 201 ++++++++++++++++++ awx/ui/client/src/license/license.block.less | 1 - .../client/src/license/license.controller.js | 11 +- .../client/src/license/license.partial.html | 2 +- awx/ui/client/src/license/main.js | 2 +- .../authentication.service.js | 3 +- .../authenticationServices/pendo.service.js | 6 +- .../src/main-menu/main-menu.partial.html | 24 +-- .../src/shared/config/config.service.js | 52 +++++ awx/ui/client/src/shared/config/main.js | 11 + .../src/shared/features/features.service.js | 41 ++-- .../src/shared/stateExtender.provider.js | 9 +- 15 files changed, 388 insertions(+), 100 deletions(-) create mode 100644 awx/ui/client/src/license/checkLicense2.factory.js create mode 100644 awx/ui/client/src/shared/config/config.service.js create mode 100644 awx/ui/client/src/shared/config/main.js diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 4fd0f98fc4..9eba128abb 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -68,6 +68,7 @@ import './shared/directives'; import './shared/filters'; import './shared/Socket'; import './shared/features/main'; +import config from './shared/config/main'; import './login/authenticationServices/pendo/ng-pendo'; import footer from './footer/main'; import scheduler from './scheduler/main'; @@ -109,6 +110,7 @@ var tower = angular.module('Tower', [ JobTemplates.name, portalMode.name, search.name, + config.name, 'ngToast', 'templates', 'Utilities', @@ -514,10 +516,15 @@ var tower = angular.module('Tower', [ }]); }]) - .run(['$q', '$compile', '$cookieStore', '$rootScope', '$log', 'CheckLicense', '$location', 'Authorization', 'LoadBasePaths', 'Timer', 'ClearScope', 'Socket', - 'LoadConfig', 'Store', 'ShowSocketHelp', 'pendoService', 'Prompt', 'Rest', 'Wait', 'ProcessErrors', '$state', 'GetBasePath', - function ($q, $compile, $cookieStore, $rootScope, $log, CheckLicense, $location, Authorization, LoadBasePaths, Timer, ClearScope, Socket, - LoadConfig, Store, ShowSocketHelp, pendoService, Prompt, Rest, Wait, ProcessErrors, $state, GetBasePath) { + .run(['$q', '$compile', '$cookieStore', '$rootScope', '$log', + 'CheckLicense', '$location', 'Authorization', 'LoadBasePaths', 'Timer', + 'ClearScope', 'Socket', 'LoadConfig', 'Store', + 'ShowSocketHelp', 'pendoService', 'Prompt', 'Rest', 'Wait', + 'ProcessErrors', '$state', 'GetBasePath', 'ConfigService', + function ($q, $compile, $cookieStore, $rootScope, $log, CheckLicense, + $location, Authorization, LoadBasePaths, Timer, ClearScope, Socket, + LoadConfig, Store, ShowSocketHelp, pendoService, Prompt, Rest, Wait, + ProcessErrors, $state, GetBasePath, ConfigService) { var sock; $rootScope.addPermission = function (scope) { $compile("")(scope); @@ -585,11 +592,11 @@ var tower = angular.module('Tower', [ Prompt({ hdr: `Remove role`, body: ` -
- Confirm the removal of the ${roleType} - ${roleName} - role associated with ${userName}. -
+
+ Confirm the removal of the ${roleType} + ${roleName} + role associated with ${userName}. +
`, action: action, actionText: 'REMOVE' @@ -615,11 +622,11 @@ var tower = angular.module('Tower', [ Prompt({ hdr: `Remove role`, body: ` -
- Confirm the removal of the ${roleType} - ${roleName} - role associated with the ${teamName} team. -
+
+ Confirm the removal of the ${roleType} + ${roleName} + role associated with the ${teamName} team. +
`, action: action, actionText: 'REMOVE' @@ -760,9 +767,7 @@ var tower = angular.module('Tower', [ $rootScope.$on("$stateChangeStart", function (event, next, nextParams, prev) { - if (next.name !== 'signOut'){ - CheckLicense.notify(); - } + $rootScope.$broadcast("closePermissionsModal"); $rootScope.$broadcast("closeUsersModal"); // this line removes the query params attached to a route @@ -813,15 +818,19 @@ var tower = angular.module('Tower', [ if ($rootScope.current_user === undefined || $rootScope.current_user === null) { Authorization.restoreUserInfo(); //user must have hit browser refresh } + if (next && (next.name !== "signIn" && next.name !== "signOut" && next.name !== "license")) { + // if not headed to /login or /logout, then check the license + CheckLicense.test(event); + } } activateTab(); }); $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState) { // catch license expiration notifications immediately after user logs in, redirect - if (fromState.name === 'signIn'){ - CheckLicense.notify(); - } + // if (fromState.name === 'signIn'){ + // CheckLicense.notify(); + // } if(fromState.name === 'license' && toParams.hasOwnProperty('licenseMissing')){ $rootScope.licenseMissing = toParams.licenseMissing; @@ -868,8 +877,10 @@ var tower = angular.module('Tower', [ Timer.init().then(function(timer){ $rootScope.sessionTimer = timer; $rootScope.$emit('OpenSocket'); - pendoService.issuePendoIdentity(); - CheckLicense.notify(); + ConfigService.getConfig().then(function(){ + pendoService.issuePendoIdentity(); + CheckLicense.test(event); + }); }); } } @@ -904,7 +915,7 @@ var tower = angular.module('Tower', [ // create a promise that will resolve state $AnsibleConfig is loaded $rootScope.loginConfig = $q.defer(); } - + $rootScope.licenseMissing = true; //the authorization controller redirects to the home page automatcially if there is no last path defined. in order to override // this, set the last path to /portal for instances where portal is visited for the first time. $rootScope.lastPath = ($location.path() === "/portal") ? 'portal' : undefined; diff --git a/awx/ui/client/src/bread-crumb/bread-crumb.partial.html b/awx/ui/client/src/bread-crumb/bread-crumb.partial.html index 4d51219070..5520af9f3a 100644 --- a/awx/ui/client/src/bread-crumb/bread-crumb.partial.html +++ b/awx/ui/client/src/bread-crumb/bread-crumb.partial.html @@ -1,5 +1,5 @@