From 6e3f4a7a6e1b928f38af2039e47000364b499987 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Thu, 5 Oct 2017 10:55:30 -0400 Subject: [PATCH] fixing issues w/ lazyloaded states --- awx/ui/client/src/app.js | 39 +++++++++---------- awx/ui/client/src/credential-types/main.js | 2 +- awx/ui/client/src/instance-groups/main.js | 2 +- .../src/inventories-hosts/hosts/main.js | 2 +- .../src/inventories-hosts/inventories/main.js | 2 +- awx/ui/client/src/inventory-scripts/main.js | 2 +- awx/ui/client/src/notifications/main.js | 2 +- awx/ui/client/src/organizations/main.js | 2 +- awx/ui/client/src/projects/main.js | 2 +- awx/ui/client/src/teams/main.js | 2 +- awx/ui/client/src/templates/main.js | 2 +- awx/ui/client/src/users/main.js | 2 +- 12 files changed, 30 insertions(+), 31 deletions(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index fcb1457adf..61b194b8be 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -175,12 +175,12 @@ angular 'CheckLicense', '$location', 'Authorization', 'LoadBasePaths', 'Timer', 'LoadConfig', 'Store', 'pendoService', 'Prompt', 'Rest', 'Wait', 'ProcessErrors', '$state', 'GetBasePath', 'ConfigService', - 'FeaturesService', '$filter', 'SocketService', 'AppStrings', + 'FeaturesService', '$filter', 'SocketService', 'AppStrings', '$transitions', function($stateExtender, $q, $compile, $cookies, $rootScope, $log, $stateParams, CheckLicense, $location, Authorization, LoadBasePaths, Timer, LoadConfig, Store, pendoService, Prompt, Rest, Wait, ProcessErrors, $state, GetBasePath, ConfigService, FeaturesService, - $filter, SocketService, AppStrings) { + $filter, SocketService, AppStrings, $transitions) { $rootScope.$state = $state; $rootScope.$state.matches = function(stateName) { @@ -243,9 +243,7 @@ angular $rootScope.crumbCache = []; - $rootScope.$on("$stateChangeStart", function (event, next) { - // let current_title = $rootScope.$state.current.ncyBreadcrumbLabel || ""; - // $rootScope.tabTitle = `Ansible ${$rootScope.BRAND_NAME} ${current_title}`; + $transitions.onStart({}, function(trans) { // Remove any lingering intervals // except on jobResults.* states var jobResultStates = [ @@ -256,10 +254,10 @@ angular 'jobResult.host-events', 'jobResult.host-event.stdout' ]; - if ($rootScope.jobResultInterval && !_.includes(jobResultStates, next.name) ) { + if ($rootScope.jobResultInterval && !_.includes(jobResultStates, trans.to().name) ) { window.clearInterval($rootScope.jobResultInterval); } - if ($rootScope.jobStdOutInterval && !_.includes(jobResultStates, next.name) ) { + if ($rootScope.jobStdOutInterval && !_.includes(jobResultStates, trans.to().name) ) { window.clearInterval($rootScope.jobStdOutInterval); } @@ -298,19 +296,19 @@ angular } if (Authorization.isUserLoggedIn() === false) { - if (next.name !== "signIn") { + if (trans.to().name !== "signIn") { $state.go('signIn'); } } else if ($rootScope && $rootScope.sessionTimer && $rootScope.sessionTimer.isExpired()) { // gets here on timeout - if (next.name !== "signIn") { + if (trans.to().name !== "signIn") { $state.go('signIn'); } } else { 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 (trans.to().name && (trans.to().name !== "signIn" && trans.to().name !== "signOut" && trans.to().name !== "license")) { ConfigService.getConfig().then(function() { // if not headed to /login or /logout, then check the license CheckLicense.test(event); @@ -320,20 +318,21 @@ angular activateTab(); }); - $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) { + // $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) { + $transitions.onSuccess({}, function(trans) { - if(toState === fromState) { + if(trans.to() === trans.from()) { // check to see if something other than a search param has changed let toParamsWithoutSearchKeys = {}; let fromParamsWithoutSearchKeys = {}; - for (let key in toParams) { - if (toParams.hasOwnProperty(key) && !/_search/.test(key)) { - toParamsWithoutSearchKeys[key] = toParams[key]; + for (let key in trans.$to().params) { + if (trans.$to().params.hasOwnProperty(key) && !/_search/.test(key)) { + toParamsWithoutSearchKeys[key] = trans.$to().params[key]; } } - for (let key in fromParams) { - if (fromParams.hasOwnProperty(key) && !/_search/.test(key)) { - fromParamsWithoutSearchKeys[key] = fromParams[key]; + for (let key in trans.$from().params) { + if (trans.$from().params.hasOwnProperty(key) && !/_search/.test(key)) { + fromParamsWithoutSearchKeys[key] = trans.$from().params[key]; } } @@ -345,8 +344,8 @@ angular document.body.scrollTop = document.documentElement.scrollTop = 0; } - if (fromState.name === 'license' && toParams.hasOwnProperty('licenseMissing')) { - $rootScope.licenseMissing = toParams.licenseMissing; + if (trans.from().name === 'license' && trans.$to().params.hasOwnProperty('licenseMissing')) { + $rootScope.licenseMissing = trans.$to().params.licenseMissing; } var list, id; // broadcast event change if editing crud object diff --git a/awx/ui/client/src/credential-types/main.js b/awx/ui/client/src/credential-types/main.js index cb88c2e023..be36639928 100644 --- a/awx/ui/client/src/credential-types/main.js +++ b/awx/ui/client/src/credential-types/main.js @@ -24,7 +24,7 @@ angular.module('credentialTypes', [ let stateDefinitions = stateDefinitionsProvider.$get(); $stateProvider.state({ - name: 'credentialTypes', + name: 'credentialTypes.**', url: '/credential_type', lazyLoad: () => stateDefinitions.generateTree({ parent: 'credentialTypes', diff --git a/awx/ui/client/src/instance-groups/main.js b/awx/ui/client/src/instance-groups/main.js index 024444c7d1..4f9410f0e0 100644 --- a/awx/ui/client/src/instance-groups/main.js +++ b/awx/ui/client/src/instance-groups/main.js @@ -51,7 +51,7 @@ angular.module('instanceGroups', [CapacityBar.name]) } $stateProvider.state({ - name: 'instanceGroups', + name: 'instanceGroups.**', url: '/instance_groups', lazyLoad: () => generateInstanceGroupsStates() }); diff --git a/awx/ui/client/src/inventories-hosts/hosts/main.js b/awx/ui/client/src/inventories-hosts/hosts/main.js index 09a368a825..c2675c2fda 100644 --- a/awx/ui/client/src/inventories-hosts/hosts/main.js +++ b/awx/ui/client/src/inventories-hosts/hosts/main.js @@ -104,7 +104,7 @@ angular.module('host', [ }; $stateProvider.state({ - name: 'hosts', + name: 'hosts.**', url: '/hosts', lazyLoad: () => generateHostStates() }); diff --git a/awx/ui/client/src/inventories-hosts/inventories/main.js b/awx/ui/client/src/inventories-hosts/inventories/main.js index c22d0ab5c5..aec6e86e20 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/main.js +++ b/awx/ui/client/src/inventories-hosts/inventories/main.js @@ -349,7 +349,7 @@ angular.module('inventory', [ } $stateProvider.state({ - name: 'inventories', + name: 'inventories.**', url: '/inventories', lazyLoad: () => generateInventoryStates() }); diff --git a/awx/ui/client/src/inventory-scripts/main.js b/awx/ui/client/src/inventory-scripts/main.js index 460d727661..ec7d3e9a94 100644 --- a/awx/ui/client/src/inventory-scripts/main.js +++ b/awx/ui/client/src/inventory-scripts/main.js @@ -24,7 +24,7 @@ angular.module('inventoryScripts', [ let stateDefinitions = stateDefinitionsProvider.$get(); $stateProvider.state({ - name: 'inventoryScripts', + name: 'inventoryScripts.**', url: '/inventory_script', lazyLoad: () => stateDefinitions.generateTree({ parent: 'inventoryScripts', diff --git a/awx/ui/client/src/notifications/main.js b/awx/ui/client/src/notifications/main.js index 8ca7309b14..c1a2a559be 100644 --- a/awx/ui/client/src/notifications/main.js +++ b/awx/ui/client/src/notifications/main.js @@ -36,7 +36,7 @@ angular.module('notifications', [ // lazily generate a tree of substates which will replace this node in ui-router's stateRegistry // see: stateDefinition.factory for usage documentation $stateProvider.state({ - name: 'notifications', + name: 'notifications.**', url: '/notification_templates', ncyBreadcrumb: { label: N_("NOTIFICATIONS") diff --git a/awx/ui/client/src/organizations/main.js b/awx/ui/client/src/organizations/main.js index 7d715b40e7..128676263d 100644 --- a/awx/ui/client/src/organizations/main.js +++ b/awx/ui/client/src/organizations/main.js @@ -32,7 +32,7 @@ angular.module('Organizations', [ // lazily generate a tree of substates which will replace this node in ui-router's stateRegistry // see: stateDefinition.factory for usage documentation $stateProvider.state({ - name: 'organizations', + name: 'organizations.**', url: '/organizations', lazyLoad: () => stateDefinitions.generateTree({ parent: 'organizations', // top-most node in the generated tree diff --git a/awx/ui/client/src/projects/main.js b/awx/ui/client/src/projects/main.js index 778cfab07a..37461d3d0a 100644 --- a/awx/ui/client/src/projects/main.js +++ b/awx/ui/client/src/projects/main.js @@ -48,7 +48,7 @@ angular.module('Projects', []) // lazily generate a tree of substates which will replace this node in ui-router's stateRegistry // see: stateDefinition.factory for usage documentation $stateProvider.state({ - name: 'projects', + name: 'projects.**', url: '/projects', lazyLoad: () => stateDefinitions.generateTree({ parent: 'projects', // top-most node in the generated tree (will replace this state definition) diff --git a/awx/ui/client/src/teams/main.js b/awx/ui/client/src/teams/main.js index b5bf9c8e86..f0ac982c7f 100644 --- a/awx/ui/client/src/teams/main.js +++ b/awx/ui/client/src/teams/main.js @@ -25,7 +25,7 @@ angular.module('Teams', []) // lazily generate a tree of substates which will replace this node in ui-router's stateRegistry // see: stateDefinition.factory for usage documentation $stateProvider.state({ - name: 'teams', + name: 'teams.**', url: '/teams', lazyLoad: () => stateDefinitions.generateTree({ parent: 'teams', diff --git a/awx/ui/client/src/templates/main.js b/awx/ui/client/src/templates/main.js index 55ca52f908..2db04961a2 100644 --- a/awx/ui/client/src/templates/main.js +++ b/awx/ui/client/src/templates/main.js @@ -892,7 +892,7 @@ angular.module('templates', [surveyMaker.name, templatesList.name, jobTemplates. } stateTree = { - name: 'templates', + name: 'templates.**', url: '/templates', lazyLoad: () => generateStateTree() }; diff --git a/awx/ui/client/src/users/main.js b/awx/ui/client/src/users/main.js index 32b3168590..aa883c7001 100644 --- a/awx/ui/client/src/users/main.js +++ b/awx/ui/client/src/users/main.js @@ -25,7 +25,7 @@ angular.module('Users', []) // lazily generate a tree of substates which will replace this node in ui-router's stateRegistry // see: stateDefinition.factory for usage documentation $stateProvider.state({ - name: 'users', + name: 'users.**', url: '/users', lazyLoad: () => stateDefinitions.generateTree({ parent: 'users',