From 7c68f18060ba4421eba4691c4298730c2d99c9fb Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Thu, 26 May 2016 10:15:06 -0700 Subject: [PATCH] fixing issue where first route was empty on refresh --- awx/ui/client/src/app.js | 27 ++-- .../src/bread-crumb/bread-crumb.directive.js | 135 +++++++----------- .../dashboard/hosts/dashboard-hosts.route.js | 3 - .../inventories/edit/inventory-edit.route.js | 5 - .../list/job-templates-list.route.js | 5 - .../src/license/checkLicense.factory.js | 34 ++--- .../client/src/notifications/add/add.route.js | 5 - .../add/organizations-add.route.js | 5 - .../src/permissions/add/user-add.route.js | 7 +- .../src/permissions/edit/user-edit.route.js | 7 +- .../src/portal-mode/portal-mode.route.js | 5 - .../src/shared/config/config.service.js | 6 +- .../src/shared/features/features.service.js | 23 +-- .../src/shared/stateExtender.provider.js | 6 +- 14 files changed, 100 insertions(+), 173 deletions(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index ef11461b7b..e58f1ee924 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -214,8 +214,10 @@ var tower = angular.module('Tower', [ timeout: 4000 }); }]) - .config(['$stateProvider', '$urlRouterProvider', '$breadcrumbProvider', '$urlMatcherFactoryProvider', - function ($stateProvider, $urlRouterProvider, $breadcrumbProvider, $urlMatcherFactoryProvider) { + .config(['$stateProvider', '$urlRouterProvider', '$breadcrumbProvider', + '$urlMatcherFactoryProvider', + function ($stateProvider, $urlRouterProvider, $breadcrumbProvider, + $urlMatcherFactoryProvider) { $urlMatcherFactoryProvider.strictMode(false); $breadcrumbProvider.setOptions({ templateUrl: urlPrefix + 'partials/breadcrumb.html' @@ -246,7 +248,7 @@ var tower = angular.module('Tower', [ graphData: ['$q', 'jobStatusGraphData', 'FeaturesService', function($q, jobStatusGraphData, FeaturesService) { return $q.all({ jobStatus: jobStatusGraphData.get("month", "all"), - features: FeaturesService.get() + // features: FeaturesService.get() }); }] } @@ -521,10 +523,11 @@ var tower = angular.module('Tower', [ 'ClearScope', 'Socket', 'LoadConfig', 'Store', 'ShowSocketHelp', 'pendoService', 'Prompt', 'Rest', 'Wait', 'ProcessErrors', '$state', 'GetBasePath', 'ConfigService', + 'FeaturesService', function ($q, $compile, $cookieStore, $rootScope, $log, CheckLicense, $location, Authorization, LoadBasePaths, Timer, ClearScope, Socket, LoadConfig, Store, ShowSocketHelp, pendoService, Prompt, Rest, Wait, - ProcessErrors, $state, GetBasePath, ConfigService) { + ProcessErrors, $state, GetBasePath, ConfigService, FeaturesService) { var sock; $rootScope.addPermission = function (scope) { $compile("")(scope); @@ -879,14 +882,14 @@ var tower = angular.module('Tower', [ $rootScope.$emit('OpenSocket'); ConfigService.getConfig().then(function(){ pendoService.issuePendoIdentity(); - CheckLicense.test().then(function(){ - // $state.go(next); - return; - }) - .catch(function(){ - event.preventDefault(); - $state.go('license'); - }); + CheckLicense.test(); + FeaturesService.get(); + if($location.$$path === "/home" && $state.current && $state.current.name === ""){ + $state.go('dashboard'); + } + else if($location.$$path === "/portal" && $state.current && $state.current.name === ""){ + $state.go('portalMode'); + } }); }); } 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 e74ccfaaf3..3b3f0a0080 100644 --- a/awx/ui/client/src/bread-crumb/bread-crumb.directive.js +++ b/awx/ui/client/src/bread-crumb/bread-crumb.directive.js @@ -1,5 +1,6 @@ export default - [ 'templateUrl', '$state', 'FeaturesService', 'ProcessErrors', 'Store', 'Empty', '$log', function(templateUrl, $state, FeaturesService, ProcessErrors, Store, Empty, $log) { + ['templateUrl', '$state', 'FeaturesService', 'ProcessErrors', '$rootScope', + function(templateUrl, $state, FeaturesService, ProcessErrors, $rootScope) { return { restrict: 'E', templateUrl: templateUrl('bread-crumb/bread-crumb'), @@ -10,90 +11,62 @@ export default scope.showActivityStreamButton = false; scope.loadingLicense = true; - scope.toggleActivityStream = function() { + scope.openActivityStream = function() { - // If the user is not already on the activity stream then they want to navigate to it - if(!scope.activityStreamActive) { - var stateGoParams = {}; - - if(streamConfig && streamConfig.activityStream) { - if(streamConfig.activityStreamTarget) { - stateGoParams.target = streamConfig.activityStreamTarget; - } - if(streamConfig.activityStreamId) { - stateGoParams.id = $state.params[streamConfig.activityStreamId]; - } - } - - $state.go('activityStream', stateGoParams); - } - // The user is navigating away from the activity stream - take them back from whence they came - else { - // Pull the previous state out of local storage - var previousState = Store('previous_state'); - - if(previousState && !Empty(previousState.name)) { - $state.go(previousState.name, previousState.fromParams); - } - else { - // If for some reason something went wrong (like local storage was wiped, etc) take the - // user back to the dashboard - $state.go('dashboard'); - } - - } - - }; - - scope.$on("$stateChangeSuccess", function updateActivityStreamButton(event, toState, toParams, fromState, fromParams) { - - if(fromState && !Empty(fromState.name)) { - // Go ahead and attach the from params to the state object so that it can all be stored together - fromState.fromParams = fromParams ? fromParams : {}; - - // Store the state that we're coming from in local storage to be accessed when navigating away from the - // activity stream - Store('previous_state', fromState); - } - - streamConfig = (toState && toState.data) ? toState.data : {}; + var stateGoParams = {}; if(streamConfig && streamConfig.activityStream) { - - // Check to see if activity_streams is an enabled feature. $stateChangeSuccess fires - // after the resolve on the state declaration so features should be available at this - // point. We use the get() function call here just in case the features aren't available. - // The get() function will only fire off the server call if the features aren't already - // attached to the $rootScope. - - FeaturesService.get() - .then(function() { - scope.loadingLicense = false; - scope.activityStreamActive = (toState.name === 'activityStream') ? true : false; - scope.showActivityStreamButton = (FeaturesService.featureEnabled('activity_streams') || toState.name === 'activityStream') ? true : false; - var licenseInfo = FeaturesService.getLicenseInfo(); - scope.licenseType = licenseInfo ? licenseInfo.license_type : null; - if (!licenseInfo) { - console.warn("License info not loaded correctly"); // jshint ignore:line - $log.error("License info not loaded correctly"); - } - }) - .catch(function (response) { - ProcessErrors(null, response.data, response.status, null, { - hdr: 'Error!', - msg: 'Failed to get feature info. GET returned status: ' + - response.status - }); - }); - + if(streamConfig.activityStreamTarget) { + stateGoParams.target = streamConfig.activityStreamTarget; + } + if(streamConfig.activityStreamId) { + stateGoParams.id = $state.params[streamConfig.activityStreamId]; + } } - else { - scope.showActivityStreamButton = false; + $state.go('activityStream', stateGoParams); + }; - } - }); + scope.$on("$stateChangeStart", function updateActivityStreamButton(event, toState) { - } - }; - }]; + streamConfig = (toState && toState.data) ? toState.data : {}; + + if(streamConfig && streamConfig.activityStream) { + + // Check to see if activity_streams is an enabled feature. $stateChangeSuccess fires + // after the resolve on the state declaration so features should be available at this + // point. We use the get() function call here just in case the features aren't available. + // The get() function will only fire off the server call if the features aren't already + // attached to the $rootScope. + var features = FeaturesService.get(); + if(features){ + scope.loadingLicense = false; + scope.activityStreamActive = (toState.name === 'activityStream') ? true : false; + scope.showActivityStreamButton = (FeaturesService.featureEnabled('activity_streams') || toState.name ==='activityStream') ? true : false; + } + } + else { + scope.showActivityStreamButton = false; + + } + }); + + $rootScope.$on('featuresLoaded', function(){ + FeaturesService.get() + .then(function() { + 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 + }); + }); + }); + + } + }; + }]; diff --git a/awx/ui/client/src/dashboard/hosts/dashboard-hosts.route.js b/awx/ui/client/src/dashboard/hosts/dashboard-hosts.route.js index 1d1f0fde4c..4af54c92bb 100644 --- a/awx/ui/client/src/dashboard/hosts/dashboard-hosts.route.js +++ b/awx/ui/client/src/dashboard/hosts/dashboard-hosts.route.js @@ -22,9 +22,6 @@ var dashboardHostsList = { label: "HOSTS" }, resolve: { - features: ['FeaturesService', function(FeaturesService) { - return FeaturesService.get(); - }], hosts: ['Rest', 'GetBasePath', '$stateParams', function(Rest, GetBasePath, $stateParams){ var defaultUrl = GetBasePath('hosts') + '?page_size=10' + ($stateParams['active-failures'] ? '&has_active_failures=true' : '' ); Rest.setUrl(defaultUrl); diff --git a/awx/ui/client/src/inventories/edit/inventory-edit.route.js b/awx/ui/client/src/inventories/edit/inventory-edit.route.js index d721ba92a4..da03f39823 100644 --- a/awx/ui/client/src/inventories/edit/inventory-edit.route.js +++ b/awx/ui/client/src/inventories/edit/inventory-edit.route.js @@ -17,10 +17,5 @@ export default { }, ncyBreadcrumb: { label: "INVENTORY EDIT" - }, - resolve: { - features: ['FeaturesService', function(FeaturesService) { - return FeaturesService.get(); - }] } }; diff --git a/awx/ui/client/src/job-templates/list/job-templates-list.route.js b/awx/ui/client/src/job-templates/list/job-templates-list.route.js index 2d3832d8a6..deeb1982bd 100644 --- a/awx/ui/client/src/job-templates/list/job-templates-list.route.js +++ b/awx/ui/client/src/job-templates/list/job-templates-list.route.js @@ -17,10 +17,5 @@ export default { }, ncyBreadcrumb: { label: "JOB TEMPLATES" - }, - resolve: { - features: ['FeaturesService', function(FeaturesService) { - return FeaturesService.get(); - }] } }; diff --git a/awx/ui/client/src/license/checkLicense.factory.js b/awx/ui/client/src/license/checkLicense.factory.js index 2791bfaafe..985b8dbe8c 100644 --- a/awx/ui/client/src/license/checkLicense.factory.js +++ b/awx/ui/client/src/license/checkLicense.factory.js @@ -33,20 +33,20 @@ export default // Intended to for runtime or pre-state checks // Returns false if invalid valid: function(license) { - if (!license.valid_key){ - return false; - } - else if (license.free_instances <= 0){ - return false; - } - // notify if less than 15 days remaining - else if (license.time_remaining / 1000 / 60 / 60 / 24 > 15){ - return false; - } - return true; + if (!license.valid_key){ + return false; + } + else if (license.free_instances <= 0){ + return false; + } + // notify if less than 15 days remaining + else if (license.time_remaining / 1000 / 60 / 60 / 24 > 15){ + return false; + } + return true; }, test: function(event){ - var deferred = $q.defer(), + var //deferred = $q.defer(), license = this.get(); if(license === null || !$rootScope.license_tested){ if(this.valid(license) === false) { @@ -55,11 +55,11 @@ export default event.preventDefault(); } $state.go('license'); - deferred.reject(); + // deferred.reject(); } else { $rootScope.licenseMissing = false; - deferred.resolve(); + // deferred.resolve(); } } else if(this.valid(license) === false) { @@ -68,13 +68,13 @@ export default if(event){ event.preventDefault(); } - deferred.reject(license); + // deferred.reject(license); } else { $rootScope.licenseMissing = false; - deferred.resolve(license); + // deferred.resolve(license); } - return deferred.promise; + return;// deferred.promise; } }; diff --git a/awx/ui/client/src/notifications/add/add.route.js b/awx/ui/client/src/notifications/add/add.route.js index a6270d5412..6672b9cb9c 100644 --- a/awx/ui/client/src/notifications/add/add.route.js +++ b/awx/ui/client/src/notifications/add/add.route.js @@ -11,11 +11,6 @@ export default { route: '/add', templateUrl: templateUrl('notifications/add/add'), controller: 'notificationsAddController', - resolve: { - features: ['FeaturesService', function(FeaturesService) { - return FeaturesService.get(); - }] - }, ncyBreadcrumb: { parent: 'notifications', label: 'Create Notification Template' diff --git a/awx/ui/client/src/organizations/add/organizations-add.route.js b/awx/ui/client/src/organizations/add/organizations-add.route.js index 9deab323b7..7c33ae5454 100644 --- a/awx/ui/client/src/organizations/add/organizations-add.route.js +++ b/awx/ui/client/src/organizations/add/organizations-add.route.js @@ -15,10 +15,5 @@ export default { ncyBreadcrumb: { parent: "organizations", label: "CREATE ORGANIZATION" - }, - resolve: { - features: ['FeaturesService', function(FeaturesService) { - return FeaturesService.get(); - }] } }; diff --git a/awx/ui/client/src/permissions/add/user-add.route.js b/awx/ui/client/src/permissions/add/user-add.route.js index 07365fb9af..8d656c0960 100644 --- a/awx/ui/client/src/permissions/add/user-add.route.js +++ b/awx/ui/client/src/permissions/add/user-add.route.js @@ -10,10 +10,5 @@ export default { name: 'userPermissionsAdd', route: '/users/:user_id/permissions/add', templateUrl: templateUrl('permissions/shared/user-permissions'), - controller: 'permissionsAddController', - resolve: { - features: ['FeaturesService', function(FeaturesService) { - return FeaturesService.get(); - }] - } + controller: 'permissionsAddController' }; diff --git a/awx/ui/client/src/permissions/edit/user-edit.route.js b/awx/ui/client/src/permissions/edit/user-edit.route.js index 3d42d5827e..ccc9ef58c1 100644 --- a/awx/ui/client/src/permissions/edit/user-edit.route.js +++ b/awx/ui/client/src/permissions/edit/user-edit.route.js @@ -10,10 +10,5 @@ export default { name: 'userPermissionsEdit', route: '/users/:user_id/permissions/:permission_id', templateUrl: templateUrl('permissions/shared/user-permissions'), - controller: 'permissionsEditController', - resolve: { - features: ['FeaturesService', function(FeaturesService) { - return FeaturesService.get(); - }] - } + controller: 'permissionsEditController' }; diff --git a/awx/ui/client/src/portal-mode/portal-mode.route.js b/awx/ui/client/src/portal-mode/portal-mode.route.js index 2247577f42..c0f7e5f3fb 100644 --- a/awx/ui/client/src/portal-mode/portal-mode.route.js +++ b/awx/ui/client/src/portal-mode/portal-mode.route.js @@ -10,11 +10,6 @@ export default { ncyBreadcrumb: { label: "MY VIEW" }, - resolve: { - features: ['FeaturesService', function(FeaturesService) { - return FeaturesService.get(); - }] - }, views: { // the empty parent ui-view "" : { diff --git a/awx/ui/client/src/shared/config/config.service.js b/awx/ui/client/src/shared/config/config.service.js index 95d1a0f86a..3e405983e8 100644 --- a/awx/ui/client/src/shared/config/config.service.js +++ b/awx/ui/client/src/shared/config/config.service.js @@ -6,8 +6,8 @@ export default - ['GetBasePath', 'ProcessErrors', '$q', 'Rest', '$rootScope', - function (GetBasePath, ProcessErrors, $q, Rest, $rootScope) { + ['GetBasePath', 'ProcessErrors', '$q', 'Rest', '$rootScope', '$state', + function (GetBasePath, ProcessErrors, $q, Rest, $rootScope, $state) { return { get: function(){ return this.config; @@ -20,7 +20,7 @@ export default delete: function(){ delete(this.config); }, - + getConfig: function () { var config = this.get(), that = this, diff --git a/awx/ui/client/src/shared/features/features.service.js b/awx/ui/client/src/shared/features/features.service.js index 00e1df3d09..16ad2e7130 100644 --- a/awx/ui/client/src/shared/features/features.service.js +++ b/awx/ui/client/src/shared/features/features.service.js @@ -13,23 +13,12 @@ function ($rootScope, Rest, GetBasePath, ProcessErrors, $http, $q, return { getFeatures: function(){ var config = ConfigService.get(); - license_info = config.license_info; - $rootScope.features = config.license_info.features; - return $rootScope.features; - // var promise; - // Rest.setUrl(GetBasePath('config')); - // promise = Rest.get(); - // return promise.then(function (data) { - // license_info = data.data.license_info; - // $rootScope.features = data.data.license_info.features; - // return $rootScope.features; - // }).catch(function (response) { - // ProcessErrors($rootScope, response.data, response.status, null, { - // hdr: 'Error!', - // msg: 'Failed to get license info. GET returned status: ' + - // response.status - // }); - // }); + if(config){ + license_info = config.license_info; + $rootScope.features = config.license_info.features; + return $rootScope.features; + } + return {}; }, get: function(){ if(_.isEmpty($rootScope.features)){ diff --git a/awx/ui/client/src/shared/stateExtender.provider.js b/awx/ui/client/src/shared/stateExtender.provider.js index d647e5caf7..341c21f98f 100644 --- a/awx/ui/client/src/shared/stateExtender.provider.js +++ b/awx/ui/client/src/shared/stateExtender.provider.js @@ -8,9 +8,9 @@ export default function($stateProvider) { return; } else{ - resolve.features = ['FeaturesService', function(FeaturesService) { - return FeaturesService.get(); - }]; + // resolve.features = ['FeaturesService', function(FeaturesService) { + // return FeaturesService.get(); + // }]; // resolve.features = ['CheckLicense', 'Store', '$state', // function(CheckLicense, Store, $state) { // var license = Store('license');