From 40abf57b4a4368c1f26ba974bd70696e3636d61b Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Wed, 1 Jun 2016 19:39:33 -0700 Subject: [PATCH] Improvements to feature service timing for AS button --- awx/ui/client/src/app.js | 4 +++ .../src/bread-crumb/bread-crumb.directive.js | 19 ++++------- .../src/license/checkLicense.factory.js | 5 ++- .../src/shared/features/features.service.js | 32 +++++++------------ .../src/shared/stateExtender.provider.js | 25 ++------------- 5 files changed, 26 insertions(+), 59 deletions(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 857497c493..2be0d724ca 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -920,6 +920,10 @@ var tower = angular.module('Tower', [ // create a promise that will resolve state $AnsibleConfig is loaded $rootScope.loginConfig = $q.defer(); } + if (!$rootScope.featuresConfigured) { + // create a promise that will resolve state $AnsibleConfig is loaded + $rootScope.featuresConfigured = $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. diff --git a/awx/ui/client/src/bread-crumb/bread-crumb.directive.js b/awx/ui/client/src/bread-crumb/bread-crumb.directive.js index e96a6e96c7..c45321c7e5 100644 --- a/awx/ui/client/src/bread-crumb/bread-crumb.directive.js +++ b/awx/ui/client/src/bread-crumb/bread-crumb.directive.js @@ -52,22 +52,15 @@ export default } }); - $rootScope.$on('featuresLoaded', function(){ - FeaturesService.get() - .then(function() { + // scope.$on('featuresLoaded', function(){ + $rootScope.featuresConfigured.promise.then(function(features){ + // var features = FeaturesService.get(); + if(features){ scope.loadingLicense = false; scope.activityStreamActive = ($state.name === 'activityStream') ? true : false; - scope.showActivityStreamButton = (FeaturesService.featureEnabled('activity_streams') || $state.name === 'activityStream') ? true : false; - }) - .catch(function (response) { - ProcessErrors(null, response.data, response.status, null, { - hdr: 'Error!', - msg: 'Failed to get feature info. GET returned status: ' + - response.status - }); - }); + scope.showActivityStreamButton = (FeaturesService.featureEnabled('activity_streams') || $state.name ==='activityStream') ? true : false; + } }); - } }; }]; diff --git a/awx/ui/client/src/license/checkLicense.factory.js b/awx/ui/client/src/license/checkLicense.factory.js index 985b8dbe8c..cd0f7fd27e 100644 --- a/awx/ui/client/src/license/checkLicense.factory.js +++ b/awx/ui/client/src/license/checkLicense.factory.js @@ -29,9 +29,7 @@ export default msg: 'Call to '+ defaultUrl + ' failed. Return status: '+ status}); }); }, - // Checks current license validity - // Intended to for runtime or pre-state checks - // Returns false if invalid + valid: function(license) { if (!license.valid_key){ return false; @@ -45,6 +43,7 @@ export default } return true; }, + test: function(event){ var //deferred = $q.defer(), license = this.get(); diff --git a/awx/ui/client/src/shared/features/features.service.js b/awx/ui/client/src/shared/features/features.service.js index 9d4df28281..7743d9bbe6 100644 --- a/awx/ui/client/src/shared/features/features.service.js +++ b/awx/ui/client/src/shared/features/features.service.js @@ -8,31 +8,23 @@ export default ['$rootScope', 'Rest', 'GetBasePath', 'ProcessErrors', '$http', '$q', 'ConfigService', function ($rootScope, Rest, GetBasePath, ProcessErrors, $http, $q, ConfigService) { - var license_info; - return { - getFeatures: function(){ - var config = ConfigService.get(); - if(config){ - license_info = config.license_info; - $rootScope.features = config.license_info.features; - $rootScope.$emit('featuresLoaded'); + get: function(){ + if (_.isEmpty($rootScope.features)) { + var config = ConfigService.get(); + if(config){ + $rootScope.features = config.license_info.features; + if($rootScope.featuresConfigured){ + $rootScope.featuresConfigured.resolve($rootScope.features); + } + return $rootScope.features; + } + } + else{ return $rootScope.features; } - else { - return {}; - } }, - get: function(){ - if(_.isEmpty($rootScope.features)){ - return this.getFeatures(); - } else { - // $q.when will ensure that the result is returned - // as a resovled promise. - return $q.when($rootScope.features); - } - }, featureEnabled: function(feature) { if($rootScope.features && $rootScope.features[feature] && $rootScope.features[feature] === true) { return true; diff --git a/awx/ui/client/src/shared/stateExtender.provider.js b/awx/ui/client/src/shared/stateExtender.provider.js index 341c21f98f..89f6ff97ba 100644 --- a/awx/ui/client/src/shared/stateExtender.provider.js +++ b/awx/ui/client/src/shared/stateExtender.provider.js @@ -1,36 +1,15 @@ export default function($stateProvider) { this.$get = function() { return { - getResolves: function(state){ - var resolve = state.resolve || {}, - routes = ["signIn", "signOut"]; - if(_.indexOf(routes, state.name)>-1){ - return; - } - else{ - // resolve.features = ['FeaturesService', function(FeaturesService) { - // return FeaturesService.get(); - // }]; - // resolve.features = ['CheckLicense', 'Store', '$state', - // function(CheckLicense, Store, $state) { - // var license = Store('license'); - // if(CheckLicense.valid(license)=== false){ - // $state.go('license'); - // } - // }]; - return resolve; - } - }, addState: function(state) { - var route = state.route || state.url, - resolve = this.getResolves(state); + var route = state.route || state.url; $stateProvider.state(state.name, { url: route, controller: state.controller, templateUrl: state.templateUrl, - resolve: resolve, + resolve: state.resolve, params: state.params, data: state.data, ncyBreadcrumb: state.ncyBreadcrumb,