From e8a39685fcb42c477a7295a1707e8bb17dede2a3 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Wed, 8 Jun 2016 19:35:59 -0400 Subject: [PATCH] Turned the activity stream button into a toggle and added a conditional tooltip for show/hide --- .../src/bread-crumb/bread-crumb.directive.js | 60 ++++++++++++++----- .../src/bread-crumb/bread-crumb.partial.html | 3 +- 2 files changed, 47 insertions(+), 16 deletions(-) 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 c45321c7e5..3331a10736 100644 --- a/awx/ui/client/src/bread-crumb/bread-crumb.directive.js +++ b/awx/ui/client/src/bread-crumb/bread-crumb.directive.js @@ -1,6 +1,6 @@ export default - ['templateUrl', '$state', 'FeaturesService', 'ProcessErrors','$rootScope', - function(templateUrl, $state, FeaturesService, ProcessErrors, $rootScope) { + ['templateUrl', '$state', 'FeaturesService', 'ProcessErrors','$rootScope', 'Store', 'Empty', + function(templateUrl, $state, FeaturesService, ProcessErrors, $rootScope, Store, Empty) { return { restrict: 'E', templateUrl: templateUrl('bread-crumb/bread-crumb'), @@ -13,22 +13,50 @@ export default scope.toggleActivityStream = function() { - var stateGoParams = {}; + // 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 && streamConfig.activityStream) { + if(streamConfig.activityStreamTarget) { + stateGoParams.target = streamConfig.activityStreamTarget; + } + if(streamConfig.activityStreamId) { + stateGoParams.id = $state.params[streamConfig.activityStreamId]; + } + } + + $state.go('activityStream', stateGoParams); } - if(streamConfig.activityStreamId) { - stateGoParams.id = $state.params[streamConfig.activityStreamId]; + // 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("$stateChangeStart", 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); } - $state.go('activityStream', stateGoParams); - }; - - scope.$on("$stateChangeStart", function updateActivityStreamButton(event, toState) { - streamConfig = (toState && toState.data) ? toState.data : {}; if(streamConfig && streamConfig.activityStream) { @@ -42,6 +70,7 @@ export default if(features){ scope.loadingLicense = false; scope.activityStreamActive = (toState.name === 'activityStream') ? true : false; + scope.activityStreamTooltip = (toState.name === 'activityStream') ? 'Hide Activity Stream' : 'View Activity Stream'; scope.showActivityStreamButton = (FeaturesService.featureEnabled('activity_streams') || toState.name ==='activityStream') ? true : false; } } @@ -57,8 +86,9 @@ export default // 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; + scope.activityStreamActive = ($state.current.name === 'activityStream') ? true : false; + scope.activityStreamTooltip = ($state.current.name === 'activityStream') ? 'Hide Activity Stream' : 'View Activity Stream'; + scope.showActivityStreamButton = (FeaturesService.featureEnabled('activity_streams') || $state.current.name ==='activityStream') ? true : false; } }); } 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 734de68414..94018460b8 100644 --- a/awx/ui/client/src/bread-crumb/bread-crumb.partial.html +++ b/awx/ui/client/src/bread-crumb/bread-crumb.partial.html @@ -2,7 +2,8 @@