Added subtitle to the activity stream

This commit is contained in:
Michael Abashian 2016-02-04 11:32:57 -05:00
parent 068b32b1b4
commit f2d6d84ed2
8 changed files with 229 additions and 6 deletions

View File

@ -275,6 +275,22 @@ table, tbody {
margin-bottom: 20px;
}
.List-titleLockup {
margin-left: 4px;
margin-right: 6px;
display: inline-block;
margin-top: 0px;
padding-bottom: 2px;
vertical-align: bottom;
}
.List-titleLockup:before {
content: "\007C";
color: #d7d7d7;
display: block;
font-size: 13px;
}
.List-staticColumn--smallStatus {
width: 25px;
padding-right: 0px!important;

View File

@ -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];

View File

@ -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;
}
}
]
}
};

View File

@ -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/')

View File

@ -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
};

View File

@ -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;
};
}
]);

View File

@ -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;
};
}
]);

View File

@ -12,7 +12,7 @@ export default
name: 'activities',
iterator: 'activity',
editTitle: 'Activity Stream',
listTitle: 'Activity Stream',
listTitle: 'Activity Stream<span ng-show="streamSubTitle"><div class="List-titleLockup"></div>{{streamSubTitle}}<span>',
listTitleBadge: false,
selectInstructions: '',
index: false,