diff --git a/awx/ui/client/src/activity-stream/activitystream.controller.js b/awx/ui/client/src/activity-stream/activitystream.controller.js index 13d2ccecce..0c16f304b7 100644 --- a/awx/ui/client/src/activity-stream/activitystream.controller.js +++ b/awx/ui/client/src/activity-stream/activitystream.controller.js @@ -9,13 +9,21 @@ * @name controllers.function:Activity Stream * @description This controller controls the activity stream. */ -function activityStreamController($scope, Stream) { +function activityStreamController($scope, $state, subTitle, Stream, GetTargetTitle) { + + // subTitle is passed in via a resolve on the route. If there is no subtitle + // generated in the resolve then we go get the targets generic title. + + // Get the streams sub-title based on the target. This scope variable is leveraged + // when we define the activity stream list. Specifically it is included in the list + // title. + $scope.streamSubTitle = subTitle ? subTitle : GetTargetTitle($state.params.target); // Open the stream Stream({ scope: $scope }); - + } -export default ['$scope', 'Stream', activityStreamController]; +export default ['$scope', '$state', 'subTitle', 'Stream', 'GetTargetTitle', activityStreamController]; diff --git a/awx/ui/client/src/activity-stream/activitystream.route.js b/awx/ui/client/src/activity-stream/activitystream.route.js index e334363e9c..74151e32df 100644 --- a/awx/ui/client/src/activity-stream/activitystream.route.js +++ b/awx/ui/client/src/activity-stream/activitystream.route.js @@ -14,4 +14,39 @@ export default { ncyBreadcrumb: { label: "ACTIVITY STREAM" }, + resolve: { + subTitle: + [ '$stateParams', + 'Rest', + 'ModelToPlural', + 'GetBasePath', + 'ProcessErrors', + function($stateParams, rest, ModelToPlural, getBasePath, ProcessErrors) { + // If we have a target and an ID then we want to go grab the name of the object + // that we're examining with the activity stream. This name will be used in the + // subtitle. + if ($stateParams.target && $stateParams.id) { + var target = $stateParams.target; + var id = $stateParams.id; + + var url = getBasePath(ModelToPlural(target)) + id + '/'; + rest.setUrl(url); + return rest.get() + .then(function(data) { + // Return the name or the username depending on which is available. + return (data.data.name || data.data.username); + }).catch(function (response) { + ProcessErrors(null, response.data, response.status, null, { + hdr: 'Error!', + msg: 'Failed to get title info. GET returned status: ' + + response.status + }); + }); + } + else { + return null; + } + } + ] + } }; diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 00b19eda61..4bcb2f8e10 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -185,7 +185,9 @@ var tower = angular.module('Tower', [ 'pendolytics', 'ui.router', 'ncy-angular-breadcrumb', - 'scheduler' + 'scheduler', + 'ApiModelHelper', + 'ActivityStreamHelper' ]) .constant('AngularScheduler.partials', urlPrefix + 'lib/angular-scheduler/lib/') diff --git a/awx/ui/client/src/helpers.js b/awx/ui/client/src/helpers.js index be09e70be5..4a277970da 100644 --- a/awx/ui/client/src/helpers.js +++ b/awx/ui/client/src/helpers.js @@ -41,6 +41,8 @@ import RelatedSearch from "./helpers/related-search"; import Search from "./helpers/search"; import Teams from "./helpers/teams"; import AdhocHelper from "./helpers/Adhoc"; +import ApiModelHelper from "./helpers/ApiModel"; +import ActivityStreamHelper from "./helpers/ActivityStream"; export { AboutAnsible, @@ -76,5 +78,7 @@ export RelatedSearch, Search, Teams, - AdhocHelper + AdhocHelper, + ApiModelHelper, + ActivityStreamHelper }; diff --git a/awx/ui/client/src/helpers/ActivityStream.js b/awx/ui/client/src/helpers/ActivityStream.js new file mode 100644 index 0000000000..6a59bee789 --- /dev/null +++ b/awx/ui/client/src/helpers/ActivityStream.js @@ -0,0 +1,58 @@ +/************************************************* + * Copyright (c) 2016 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + + /** + * @ngdoc function + * @name helpers.function:ActivityStream + * @description Helper functions for the activity stream +*/ + +export default + angular.module('ActivityStreamHelper', ['Utilities']) + .factory('GetTargetTitle', [ + function () { + return function (target) { + + var rtnTitle = 'DASHBOARD'; + + switch(target) { + case 'project': + rtnTitle = 'PROJECTS'; + break; + case 'inventory': + rtnTitle = 'INVENTORIES'; + break; + case 'job_template': + rtnTitle = 'JOB TEMPLATES'; + break; + case 'credential': + rtnTitle = 'CREDENTIALS'; + break; + case 'user': + rtnTitle = 'USERS'; + break; + case 'team': + rtnTitle = 'TEAMS'; + break; + case 'organization': + rtnTitle = 'ORGANIZATIONS'; + break; + case 'management_job': + rtnTitle = 'MANAGEMENT JOBS'; + break; + case 'inventory_script': + rtnTitle = 'INVENTORY SCRIPTS'; + break; + case 'schedule': + rtnTitle = 'SCHEDULES'; + break; + } + + return rtnTitle; + + }; + } + ]); diff --git a/awx/ui/client/src/helpers/ApiModel.js b/awx/ui/client/src/helpers/ApiModel.js new file mode 100644 index 0000000000..6a63d24583 --- /dev/null +++ b/awx/ui/client/src/helpers/ApiModel.js @@ -0,0 +1,100 @@ +/************************************************* + * Copyright (c) 2016 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + + /** + * @ngdoc function + * @name helpers.function:ApiModel + * @description Helper functions to convert singular/plural versions of our models to the opposite +*/ + +export default + angular.module('ApiModelHelper', ['Utilities']) + .factory('ModelToSingular', [ + function () { + return function (model) { + // This function takes in the plural model string and spits out the singular + // version. + + var singularModel; + + switch(model) { + case 'projects': + singularModel = 'project'; + break; + case 'inventories': + singularModel = 'inventory'; + break; + case 'job_templates': + singularModel = 'job_template'; + break; + case 'credentials': + singularModel = 'credential'; + break; + case 'users': + singularModel = 'user'; + break; + case 'teams': + singularModel = 'team'; + break; + case 'organizations': + singularModel = 'organization'; + break; + case 'management_jobs': + singularModel = 'management_job'; + break; + case 'inventory_scripts': + singularModel = 'inventory_script'; + break; + } + + return singularModel; + + }; + } + ]) + .factory('ModelToPlural', [ + function () { + return function (model) { + // This function takes in the singular model string and spits out the plural + // version. + + var pluralModel; + + switch(model) { + case 'project': + pluralModel = 'projects'; + break; + case 'inventory': + pluralModel = 'inventories'; + break; + case 'job_template': + pluralModel = 'job_templates'; + break; + case 'credential': + pluralModel = 'credentials'; + break; + case 'user': + pluralModel = 'users'; + break; + case 'team': + pluralModel = 'teams'; + break; + case 'organization': + pluralModel = 'organizations'; + break; + case 'management_job': + pluralModel = 'management_jobs'; + break; + case 'inventory_script': + pluralModel = 'inventory_scripts'; + break; + } + + return pluralModel; + + }; + } + ]); diff --git a/awx/ui/client/src/lists/Streams.js b/awx/ui/client/src/lists/Streams.js index 9aa718a77b..1cc99c4d7c 100644 --- a/awx/ui/client/src/lists/Streams.js +++ b/awx/ui/client/src/lists/Streams.js @@ -12,7 +12,7 @@ export default name: 'activities', iterator: 'activity', editTitle: 'Activity Stream', - listTitle: 'Activity Stream', + listTitle: 'Activity Stream
{{streamSubTitle}}', listTitleBadge: false, selectInstructions: '', index: false,