Files
awx/awx/ui/client/src/bread-crumb/bread-crumb.directive.js
Chris Meyers a58433ed9b activity stream, display name of resource as title
related to #4185

* When activity stream is gone to from a resource edit view, it should:
  * only show activity for the particular object
  * display the name of the resource as a title

This commit patch half-ass does those two things. So what's missing?
That questions is best answered by looking at how the feature behaves in
tower 3.0.3. You'll notice that you are "locked" on the resource you are
viewing the activity stream for. With this commit:
* You aren't locked
* The removal of the resource-id filter (smart-search) is borked.

So what do we need to do?:
* Lock the view to the resource being viewed

How do we need to do it?:
* router params.activity_search.values is a "static" thing. It is used
to tell smart-search to not generate search tags. This is what we want
to do. However, this is a contructor-only parameter. Further, the value
"value" gets passed around to all sorts of other UI contructors that are
hard to get access to when they are needed to try and dynamically set
smart-search ignore search-tags.
2017-01-16 08:57:37 -05:00

132 lines
6.8 KiB
JavaScript

export default
['templateUrl', '$state', 'FeaturesService', 'ProcessErrors','$rootScope', 'Store', 'Empty', '$window', 'BreadCrumbService',
function(templateUrl, $state, FeaturesService, ProcessErrors, $rootScope, Store, Empty, $window, BreadCrumbService) {
return {
restrict: 'E',
templateUrl: templateUrl('bread-crumb/bread-crumb'),
link: function(scope) {
var streamConfig = {}, originalRoute;
function init() {
scope.showActivityStreamButton = false;
scope.showRefreshButton = false;
scope.loadingLicense = true;
function onResize(){
BreadCrumbService.truncateCrumbs();
}
function cleanUp() {
angular.element($window).off('resize', onResize);
}
angular.element($window).on('resize', onResize);
scope.$on('$destroy', cleanUp);
}
init();
scope.refresh = function() {
$state.go($state.current, {}, {reload: true});
};
scope.toggleActivityStream = 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;
stateGoParams.activity_search = {
or__object1__in: streamConfig.activityStreamTarget === 'template' ? 'job_template,workflow_job_template' : streamConfig.activityStreamTarget,
or__object2__in: streamConfig.activityStreamTarget === 'template' ? 'job_template,workflow_job_template' : streamConfig.activityStreamTarget,
order_by: '-timestamp',
page_size: '20',
};
if (streamConfig.activityStreamTarget && streamConfig.activityStreamId) {
stateGoParams.activity_search[streamConfig.activityStreamTarget] = $state.params[streamConfig.activityStreamId];
}
}
else {
stateGoParams.activity_search = {
order_by: '-timestamp',
page_size: '20',
};
}
if(streamConfig.activityStreamId) {
stateGoParams.id = $state.params[streamConfig.activityStreamId];
}
}
originalRoute = $state.current;
$state.go('activityStream', stateGoParams);
}
// The user is navigating away from the activity stream - take them back from whence they came
else {
if(originalRoute) {
$state.go(originalRoute.name, originalRoute.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);
}
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.activityStreamTooltip = (toState.name === 'activityStream') ? 'Hide Activity Stream' : 'View Activity Stream';
scope.showActivityStreamButton = (FeaturesService.featureEnabled('activity_streams') || toState.name ==='activityStream') ? true : false;
}
}
else {
scope.showActivityStreamButton = false;
}
scope.showRefreshButton = (streamConfig && streamConfig.refreshButton) ? true : false;
});
// scope.$on('featuresLoaded', function(){
$rootScope.featuresConfigured.promise.then(function(features){
// var features = FeaturesService.get();
if(features){
scope.loadingLicense = 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;
}
});
}
};
}];