From 2128d34d500856bd7a8de96289d2392166ad0df7 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Tue, 31 Jan 2017 13:19:02 -0500 Subject: [PATCH] Navigate to Job Template/Workflow Job Template specific resource streams --- .../stream-dropdown-nav.directive.js | 17 ++- .../src/bread-crumb/bread-crumb.directive.js | 5 +- .../src/shared/stateDefinitions.factory.js | 4 +- awx/ui/client/src/templates/main.js | 10 ++ awx/ui/client/src/widgets/Stream.js | 128 +----------------- 5 files changed, 30 insertions(+), 134 deletions(-) diff --git a/awx/ui/client/src/activity-stream/streamDropdownNav/stream-dropdown-nav.directive.js b/awx/ui/client/src/activity-stream/streamDropdownNav/stream-dropdown-nav.directive.js index c8cfc37147..3b3574d93b 100644 --- a/awx/ui/client/src/activity-stream/streamDropdownNav/stream-dropdown-nav.directive.js +++ b/awx/ui/client/src/activity-stream/streamDropdownNav/stream-dropdown-nav.directive.js @@ -12,7 +12,12 @@ export default ['templateUrl', 'i18n', function(templateUrl, i18n) { templateUrl: templateUrl('activity-stream/streamDropdownNav/stream-dropdown-nav'), controller: ['$scope', '$state', '$stateParams','CreateSelect2', function($scope, $state, $stateParams, CreateSelect2) { - $scope.streamTarget = ($state.params && $state.params.target) ? $state.params.target : 'dashboard'; + if($state.params && $state.params.target) { + $scope.streamTarget = ($state.params.target === 'job_template' || $state.params.target === 'workflow_job_template') ? 'template' : $state.params.target; + } + else { + $scope.streamTarget = 'dashboard'; + } $scope.options = [ {label: i18n._('All Activity'), value: 'dashboard'}, @@ -40,12 +45,14 @@ export default ['templateUrl', 'i18n', function(templateUrl, i18n) { $state.go('activityStream', {target: null, activity_search: {page_size:"20", order_by: '-timestamp'}}); } else { - let search = _.merge($stateParams.activity_search, { + let search = { or__object1__in: $scope.streamTarget && $scope.streamTarget === 'template' ? 'job_template,workflow_job_template' : $scope.streamTarget, - or__object2__in: $scope.streamTarget && $scope.streamTarget === 'template' ? 'job_template,workflow_job_template' : $scope.streamTarget - }); + or__object2__in: $scope.streamTarget && $scope.streamTarget === 'template' ? 'job_template,workflow_job_template' : $scope.streamTarget, + page_size: '20', + order_by: '-timestamp' + }; // Attach the taget to the query parameters - $state.go('activityStream', {target: $scope.streamTarget, activity_search: search}); + $state.go('activityStream', {target: $scope.streamTarget, id: null, activity_search: search}); } }; 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 979ebd69d5..a9e4e8bc4e 100644 --- a/awx/ui/client/src/bread-crumb/bread-crumb.directive.js +++ b/awx/ui/client/src/bread-crumb/bread-crumb.directive.js @@ -41,9 +41,10 @@ export default if(streamConfig && streamConfig.activityStream) { if(streamConfig.activityStreamTarget) { stateGoParams.target = streamConfig.activityStreamTarget; + let isTemplateTarget = _.contains(['template', 'job_template', 'workflow_job_template'], 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, + or__object1__in: isTemplateTarget ? 'job_template,workflow_job_template' : streamConfig.activityStreamTarget, + or__object2__in: isTemplateTarget ? 'job_template,workflow_job_template' : streamConfig.activityStreamTarget, order_by: '-timestamp', page_size: '20', }; diff --git a/awx/ui/client/src/shared/stateDefinitions.factory.js b/awx/ui/client/src/shared/stateDefinitions.factory.js index 4ebe121a9b..6ed6517ac7 100644 --- a/awx/ui/client/src/shared/stateDefinitions.factory.js +++ b/awx/ui/client/src/shared/stateDefinitions.factory.js @@ -219,8 +219,8 @@ export default ['$injector', '$stateExtender', '$log', 'i18n', function($injecto }; if (params.data && params.data.activityStreamTarget) { formNodeState.data = {}; - formNodeState.data.activityStreamId = params.data.activityStreamTarget + '_id'; - + formNodeState.data.activityStreamId = params.data.activityStreamId ? params.data.activityStreamId : params.data.activityStreamTarget + '_id'; + formNodeState.data.activityStreamTarget = params.data.activityStreamTarget; } formNode = $stateExtender.buildDefinition(formNodeState); diff --git a/awx/ui/client/src/templates/main.js b/awx/ui/client/src/templates/main.js index df92821c7f..cc18269f34 100644 --- a/awx/ui/client/src/templates/main.js +++ b/awx/ui/client/src/templates/main.js @@ -53,6 +53,11 @@ angular.module('templates', [surveyMaker.name, templatesList.name, jobTemplatesA form: 'JobTemplateForm', controllers: { edit: 'JobTemplateEdit' + }, + data: { + activityStream: true, + activityStreamTarget: 'job_template', + activityStreamId: 'job_template_id' } }); @@ -73,6 +78,11 @@ angular.module('templates', [surveyMaker.name, templatesList.name, jobTemplatesA form: 'WorkflowForm', controllers: { edit: 'WorkflowEdit' + }, + data: { + activityStream: true, + activityStreamTarget: 'workflow_job_template', + activityStreamId: 'workflow_job_template_id' } }); diff --git a/awx/ui/client/src/widgets/Stream.js b/awx/ui/client/src/widgets/Stream.js index a3e033214e..d9b19eeca1 100644 --- a/awx/ui/client/src/widgets/Stream.js +++ b/awx/ui/client/src/widgets/Stream.js @@ -258,138 +258,16 @@ angular.module('StreamWidget', ['RestServices', 'Utilities', 'StreamListDefiniti .factory('Stream', ['$rootScope', '$location', '$state', 'Rest', 'GetBasePath', 'ProcessErrors', 'Wait', 'StreamList', 'generateList', 'FormatDate', 'BuildDescription', - 'ShowDetail', 'i18n', + 'ShowDetail', function ($rootScope, $location, $state, Rest, GetBasePath, ProcessErrors, Wait, StreamList, GenerateList, FormatDate, - BuildDescription, ShowDetail, i18n) { + BuildDescription, ShowDetail) { return function (params) { - var list = _.cloneDeep(StreamList), - defaultUrl = GetBasePath('activity_stream'), - scope = params.scope, - url = (params && params.url) ? params.url : null; + var scope = params.scope; $rootScope.flashMessage = null; - if (url) { - defaultUrl = url; - } else { - - if($state.params && $state.params.target) { - if($state.params.id) { - // We have a type and an ID - defaultUrl += '?' + $state.params.target + '__id=' + $state.params.id; - } - else { - // We just have a type - if ($state.params.target === 'inventory_script') { - defaultUrl += '?or__object1__in=custom_inventory_script&or__object2__in=custom_inventory_script'; - } else if ($state.params.target === 'management_job') { - defaultUrl += '?or__object1__in=job&or__object2__in=job'; - } else if ($state.params.target === 'template') { - defaultUrl += '?or__object1__in=job_template,workflow_job_template&or__object2__in=job_template,workflow_job_template'; - } else { - defaultUrl += '?or__object1__in=' + $state.params.target + '&or__object2__in=' + $state.params.target; - } - } - } - } - - if ($state.params.target === 'credential') { - list.fields.customSearchField = { - label: i18n._('Credential'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'credential', - sourceField: 'name' - }; - } else if ($state.params.target === 'host') { - list.fields.customSearchField = { - label: i18n._('Host'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'host', - sourceField: 'name' - }; - } else if ($state.params.target === 'inventory') { - list.fields.customSearchField = { - label: i18n._('Inventory'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'inventory', - sourceField: 'name' - }; - } else if ($state.params.target === 'inventory_script') { - list.fields.customSearchField = { - label: i18n._('Inventory Script'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'custom_inventory_script', - sourceField: 'name' - }; - } else if ($state.params.target === 'job_template') { - list.fields.customSearchField = { - label: i18n._('Job Template'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'job_template', - sourceField: 'name' - }; - } else if ($state.params.target === 'job') { - list.fields.customSearchField = { - label: i18n._('Job'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'job', - sourceField: 'name' - }; - } else if ($state.params.target === 'organization') { - list.fields.customSearchField = { - label: i18n._('Organization'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'organization', - sourceField: 'name' - }; - } else if ($state.params.target === 'project') { - list.fields.customSearchField = { - label: i18n._('Project'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'project', - sourceField: 'name' - }; - } else if ($state.params.target === 'schedule') { - list.fields.customSearchField = { - label: i18n._('Schedule'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'schedule', - sourceField: 'name' - }; - } else if ($state.params.target === 'team') { - list.fields.customSearchField = { - label: i18n._('Team'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'team', - sourceField: 'name' - }; - } else if ($state.params.target === 'user') { - list.fields.customSearchField = { - label: i18n._('User'), - searchType: 'text', - searchOnly: 'true', - sourceModel: 'user', - sourceField: 'username' - }; - } - - list.basePath = defaultUrl; - - // Generate the list - //view.inject(list, { mode: 'edit', id: 'stream-content', searchSize: 'col-lg-4 col-md-4 col-sm-12 col-xs-12', secondWidget: true, activityStream: true, scope: scope }); - // descriptive title describing what AS is showing scope.streamTitle = (params && params.title) ? params.title : null;