Merge pull request #4449 from jaredevantabor/post-processing

Type Labels on lists
This commit is contained in:
Jared Tabor
2016-12-15 15:36:20 -08:00
committed by GitHub
14 changed files with 279 additions and 115 deletions

View File

@@ -36,6 +36,35 @@ export function CredentialsList($scope, $rootScope, $location, $log,
$scope.selected = [];
}
$scope.$on(`${list.iterator}_options`, function(event, data){
$scope.options = data.data.actions.GET;
optionsRequestDataProcessing();
});
$scope.$watchCollection(`${$scope.list.name}`, function() {
optionsRequestDataProcessing();
}
);
// iterate over the list and add fields like type label, after the
// OPTIONS request returns, or the list is sorted/paginated/searched
function optionsRequestDataProcessing(){
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
// Set the item type label
if (list.fields.kind && $scope.options &&
$scope.options.hasOwnProperty('kind')) {
$scope.options.kind.choices.every(function(choice) {
if (choice[0] === item.kind) {
itm.kind_label = choice[1];
return false;
}
return true;
});
}
});
}
$scope.addCredential = function() {
$state.go('credentials.add');
};

View File

@@ -13,7 +13,7 @@
export function JobsListController($state, $rootScope, $log, $scope, $compile, $stateParams,
ClearScope, Find, DeleteJob, RelaunchJob, AllJobsList, ScheduledJobsList, GetBasePath, Dataset, GetChoices) {
ClearScope, Find, DeleteJob, RelaunchJob, AllJobsList, ScheduledJobsList, GetBasePath, Dataset) {
ClearScope();
@@ -28,40 +28,44 @@ export function JobsListController($state, $rootScope, $log, $scope, $compile, $
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
$scope.showJobType = true;
}
$scope.$on(`${list.iterator}_options`, function(event, data){
$scope.options = data.data.actions.GET;
optionsRequestDataProcessing();
});
_.forEach($scope[list.name], buildTooltips);
if ($scope.removeChoicesReady) {
$scope.removeChoicesReady();
$scope.$watchCollection(`${$scope.list.name}`, function() {
optionsRequestDataProcessing();
}
$scope.removeChoicesReady = $scope.$on('choicesReady', function() {
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
if(item.summary_fields && item.summary_fields.source_workflow_job &&
item.summary_fields.source_workflow_job.id){
item.workflow_result_link = `/#/workflows/${item.summary_fields.source_workflow_job.id}`;
}
// Set the item type label
if (list.fields.type) {
$scope.type_choices.every(function(choice) {
if (choice.value === item.type) {
itm.type_label = choice.label;
);
// iterate over the list and add fields like type label, after the
// OPTIONS request returns, or the list is sorted/paginated/searched
function optionsRequestDataProcessing(){
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
if(item.summary_fields && item.summary_fields.source_workflow_job &&
item.summary_fields.source_workflow_job.id){
item.workflow_result_link = `/#/workflows/${item.summary_fields.source_workflow_job.id}`;
}
// Set the item type label
if (list.fields.type && $scope.options &&
$scope.options.hasOwnProperty('type')) {
$scope.options.type.choices.every(function(choice) {
if (choice[0] === item.type) {
itm.type_label = choice[1];
return false;
}
return true;
});
}
});
});
GetChoices({
scope: $scope,
url: GetBasePath('unified_jobs'),
field: 'type',
variable: 'type_choices',
callback: 'choicesReady'
buildTooltips(itm);
});
}
function buildTooltips(job) {
job.status_tip = 'Job ' + job.status + ". Click for details.";
}
@@ -131,5 +135,5 @@ export function JobsListController($state, $rootScope, $log, $scope, $compile, $
}
JobsListController.$inject = ['$state', '$rootScope', '$log', '$scope', '$compile', '$stateParams',
'ClearScope', 'Find', 'DeleteJob', 'RelaunchJob', 'AllJobsList', 'ScheduledJobsList', 'GetBasePath', 'Dataset', 'GetChoices'
'ClearScope', 'Find', 'DeleteJob', 'RelaunchJob', 'AllJobsList', 'ScheduledJobsList', 'GetBasePath', 'Dataset'
];

View File

@@ -38,10 +38,39 @@ export function ProjectsList($scope, $rootScope, $location, $log, $stateParams,
$rootScope.flashMessage = null;
}
$scope.$watch(`${list.name}`, function() {
_.forEach($scope[list.name], buildTooltips);
$scope.$on(`${list.iterator}_options`, function(event, data){
$scope.options = data.data.actions.GET;
optionsRequestDataProcessing();
});
$scope.$watchCollection(`${$scope.list.name}`, function() {
optionsRequestDataProcessing();
}
);
// iterate over the list and add fields like type label, after the
// OPTIONS request returns, or the list is sorted/paginated/searched
function optionsRequestDataProcessing(){
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
// Set the item type label
if (list.fields.scm_type && $scope.options &&
$scope.options.hasOwnProperty('scm_type')) {
$scope.options.scm_type.choices.every(function(choice) {
if (choice[0] === item.scm_type) {
itm.type_label = choice[1];
return false;
}
return true;
});
}
buildTooltips(itm);
});
}
function buildTooltips(project) {
project.statusIcon = GetProjectIcon(project.status);
project.statusTip = GetProjectToolTip(project.status);

View File

@@ -37,6 +37,7 @@ export default
},
kind: {
label: i18n._('Type'),
ngBind: 'credential.kind_label',
excludeModal: true,
nosort: true,
columnClass: 'col-md-2 hidden-sm hidden-xs'

View File

@@ -46,6 +46,7 @@ export default
},
scm_type: {
label: i18n._('Type'),
ngBind: 'project.type_label',
excludeModal: true,
columnClass: 'col-lg-3 col-md-2 col-sm-3 hidden-xs'
},

View File

@@ -31,8 +31,7 @@ export default
name: {
label: i18n._('Name'),
columnClass: 'col-lg-4 col-md-5 col-sm-5 col-xs-7 List-staticColumnAdjacent',
sourceModel: 'unified_job_template',
sourceField: 'name',
ngBind: 'schedule.summary_fields.unified_job_template.name',
ngClick: "editSchedule(schedule)",
awToolTip: "{{ schedule.nameTip | sanitize}}",
dataTipWatch: 'schedule.nameTip',

View File

@@ -29,34 +29,38 @@
$scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
GetChoices({
scope: $scope,
url: defaultUrl,
field: 'notification_type',
variable: 'notification_type_options',
callback: 'choicesReadyNotifierList'
});
}
$scope.removeChoicesHere = $scope.$on('choicesReadyNotifierList', function() {
list.fields.notification_type.searchOptions = $scope.notification_type_options;
if ($rootScope.addedItem) {
$scope.addedItem = $rootScope.addedItem;
delete $rootScope.addedItem;
}
$scope.notification_templates.forEach(function(notification_template, i) {
setStatus(notification_template);
$scope.notification_type_options.forEach(function(type) {
if (type.value === notification_template.notification_type) {
$scope.notification_templates[i].notification_type = type.label;
var recent_notifications = notification_template.summary_fields.recent_notifications;
$scope.notification_templates[i].status = recent_notifications && recent_notifications.length > 0 ? recent_notifications[0].status : "none";
}
});
$scope.$on(`notification_template_options`, function(event, data){
$scope.options = data.data.actions.GET;
optionsRequestDataProcessing();
});
});
$scope.$watchCollection("notification_templates", function() {
optionsRequestDataProcessing();
}
);
// iterate over the list and add fields like type label, after the
// OPTIONS request returns, or the list is sorted/paginated/searched.
function optionsRequestDataProcessing(){
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
// Set the item type label
if (list.fields.notification_type && $scope.options &&
$scope.options.hasOwnProperty('notification_type')) {
$scope.options.notification_type.choices.every(function(choice) {
if (choice[0] === item.notification_type) {
itm.type_label = choice[1];
var recent_notifications = itm.summary_fields.recent_notifications;
itm.status = recent_notifications && recent_notifications.length > 0 ? recent_notifications[0].status : "none";
return false;
}
return true;
});
}
setStatus(itm);
});
}
function setStatus(notification_template) {
var html, recent_notifications = notification_template.summary_fields.recent_notifications;

View File

@@ -36,6 +36,7 @@ export default ['i18n', function(i18n){
},
notification_type: {
label: i18n._('Type'),
ngBind: "notification_template.type_label",
searchType: 'select',
searchOptions: [],
excludeModal: true,

View File

@@ -45,7 +45,19 @@ export default
let path = `${GetBasePath('job_templates')}${$stateParams.id}`;
Rest.setUrl(path);
return Rest.get(path).then((res) => res.data);
}]
}],
UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q',
function(Rest, GetBasePath, $stateParams, $q) {
Rest.setUrl(GetBasePath('unified_jobs'));
var val = $q.defer();
Rest.options()
.then(function(data) {
val.resolve(data.data);
}, function(data) {
val.reject(data);
});
return val.promise;
}]
},
views: {
'@': {
@@ -119,7 +131,19 @@ export default
let path = `${GetBasePath('workflow_job_templates')}${$stateParams.id}`;
Rest.setUrl(path);
return Rest.get(path).then((res) => res.data);
}]
}],
UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q',
function(Rest, GetBasePath, $stateParams, $q) {
Rest.setUrl(GetBasePath('unified_jobs'));
var val = $q.defer();
Rest.options()
.then(function(data) {
val.resolve(data.data);
}, function(data) {
val.reject(data);
});
return val.promise;
}]
},
views: {
'@': {
@@ -190,7 +214,19 @@ export default
let path = `${GetBasePath('projects')}${$stateParams.id}`;
Rest.setUrl(path);
return Rest.get(path).then((res) => res.data);
}]
}],
UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q',
function(Rest, GetBasePath, $stateParams, $q) {
Rest.setUrl(GetBasePath('unified_jobs'));
var val = $q.defer();
Rest.options()
.then(function(data) {
val.resolve(data.data);
}, function(data) {
val.reject(data);
});
return val.promise;
}]
},
views: {
'@': {
@@ -268,6 +304,18 @@ export default
}
],
ParentObject: [() =>{return {endpoint:'/api/v1/schedules'}; }],
UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q',
function(Rest, GetBasePath, $stateParams, $q) {
Rest.setUrl(GetBasePath('unified_jobs'));
var val = $q.defer();
Rest.options()
.then(function(data) {
val.resolve(data.data);
}, function(data) {
val.reject(data);
});
return val.promise;
}]
},
views: {
'list@jobs': {

View File

@@ -14,12 +14,12 @@
export default [
'$scope', '$compile', '$location', '$stateParams', 'SchedulesList', 'Rest',
'ProcessErrors', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'Wait', 'rbacUiControlService',
'Find', 'ToggleSchedule', 'DeleteSchedule', 'GetChoices', '$q', '$state', 'Dataset', 'ParentObject',
'Find', 'ToggleSchedule', 'DeleteSchedule', 'GetChoices', '$q', '$state', 'Dataset', 'ParentObject', 'UnifiedJobsOptions',
function($scope, $compile, $location, $stateParams,
SchedulesList, Rest, ProcessErrors, ReturnToCaller, ClearScope,
GetBasePath, Wait, rbacUiControlService, Find,
ToggleSchedule, DeleteSchedule, GetChoices,
$q, $state, Dataset, ParentObject) {
$q, $state, Dataset, ParentObject, UnifiedJobsOptions) {
ClearScope();
@@ -43,11 +43,45 @@ export default [
$scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
$scope.unified_job_options = UnifiedJobsOptions.actions.GET;
_.forEach($scope[list.name], buildTooltips);
// _.forEach($scope[list.name], buildTooltips);
}
$scope.$on(`${list.iterator}_options`, function(event, data){
$scope.options = data.data.actions.GET;
optionsRequestDataProcessing();
});
$scope.$watchCollection(`${$scope.list.name}`, function() {
optionsRequestDataProcessing();
}
);
// iterate over the list and add fields like type label, after the
// OPTIONS request returns, or the list is sorted/paginated/searched
function optionsRequestDataProcessing(){
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
// Set the item type label
if (list.fields.type && $scope.unified_job_options &&
$scope.unified_job_options.hasOwnProperty('type')) {
$scope.unified_job_options.type.choices.every(function(choice) {
if (choice[0] === itm.summary_fields.unified_job_template.unified_job_type) {
itm.type_label = choice[1];
return false;
}
return true;
});
}
buildTooltips(itm);
});
}
function buildTooltips(schedule) {
var job = schedule.summary_fields.unified_job_template;
if (schedule.enabled) {
schedule.play_tip = 'Schedule is active. Click to stop.';
schedule.status = 'active';
@@ -57,6 +91,18 @@ export default [
schedule.status = 'stopped';
schedule.status_tip = 'Schedule is stopped. Click to activate.';
}
schedule.nameTip = schedule.name;
// include the word schedule if the schedule name does not include the word schedule
if (schedule.name.indexOf("schedule") === -1 && schedule.name.indexOf("Schedule") === -1) {
schedule.nameTip += " schedule";
}
schedule.nameTip += " for ";
if (job.name.indexOf("job") === -1 && job.name.indexOf("Job") === -1) {
schedule.nameTip += "job ";
}
schedule.nameTip += job.name;
schedule.nameTip += ". Click to edit schedule.";
}
$scope.refreshSchedules = function() {
@@ -99,7 +145,7 @@ export default [
name: 'projectSchedules.edit',
params: {
id: schedule.unified_job_template,
schedule_id: schedule.id
schedule_id: schedule.id
}
});
break;
@@ -109,7 +155,7 @@ export default [
name: 'managementJobSchedules.edit',
params: {
id: schedule.unified_job_template,
schedule_id: schedule.id
schedule_id: schedule.id
}
});
break;
@@ -136,7 +182,7 @@ export default [
throw err;
}
});
});
});
}
};
@@ -160,7 +206,7 @@ export default [
};
base = $location.path().replace(/^\//, '').split('/')[0];
if (base === 'management_jobs') {
$scope.base = base = 'system_job_templates';
}
@@ -175,17 +221,5 @@ export default [
$scope.formCancel = function() {
$state.go('^', null, { reload: true });
};
// @issue - believe this is no longer necessary now that parent object is resolved prior to controller initilizing
// Wait('start');
// GetChoices({
// scope: $scope,
// url: GetBasePath('unified_jobs'), //'/static/sample/data/types/data.json'
// field: 'type',
// variable: 'type_choices',
// callback: 'choicesReady'
// });
}
];

View File

@@ -18,13 +18,23 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
// grab a single model from the cache, if present
if (cache.get(path)) {
defer.resolve({[name] : new DjangoSearchModel(name, path, cache.get(path), relations)});
defer.resolve({
models: {
[name] : new DjangoSearchModel(name, path, cache.get(path), relations)
},
options: cache.get(path)
});
} else {
this.url = path;
resolve = this.options(path)
.then((res) => {
base = res.data.actions.GET;
defer.resolve({[name]: new DjangoSearchModel(name, path, base, relations)});
defer.resolve({
models: {
[name]: new DjangoSearchModel(name, path, base, relations)
},
options: res
});
});
}
return defer.promise;
@@ -76,9 +86,9 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear
if (Array.isArray(value)){
return _.map(value, (item) => {
return `${key.split('__').join(':')}:${item}`;
});
});
}
else {
else {
return `${key.split('__').join(':')}:${value}`;
}
},

View File

@@ -15,8 +15,9 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
path = GetBasePath($scope.basePath) || $scope.basePath;
relations = getRelationshipFields($scope.dataset.results);
$scope.searchTags = stripDefaultParams($state.params[`${$scope.iterator}_search`]);
qs.initFieldset(path, $scope.djangoModel, relations).then((models) => {
$scope.models = models;
qs.initFieldset(path, $scope.djangoModel, relations).then((data) => {
$scope.models = data.models;
$scope.$emit(`${$scope.list.iterator}_options`, data.options);
});
}
@@ -102,12 +103,12 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
params.page = '1';
queryset = _.merge(queryset, params, (objectValue, sourceValue, key, object) => {
if (object[key] && object[key] !== sourceValue){
return [object[key], sourceValue];
return [object[key], sourceValue];
}
else {
// // https://lodash.com/docs/3.10.1#merge
// If customizer fn returns undefined merging is handled by default _.merge algorithm
return undefined;
return undefined;
}
});
// https://ui-router.github.io/docs/latest/interfaces/params.paramdeclaration.html#dynamic

View File

@@ -4,10 +4,11 @@
* All Rights Reserved
*************************************************/
export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest', 'Alert',
'TemplateList', 'Prompt', 'ClearScope', 'ProcessErrors', 'GetBasePath',
'InitiatePlaybookRun', 'Wait', '$state', '$filter', 'Dataset', 'rbacUiControlService', 'TemplatesService',
'QuerySet', 'GetChoices', 'TemplateCopyService',
export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest',
'Alert','TemplateList', 'Prompt', 'ClearScope', 'ProcessErrors',
'GetBasePath', 'InitiatePlaybookRun', 'Wait', '$state', '$filter',
'Dataset', 'rbacUiControlService', 'TemplatesService','QuerySet',
'GetChoices', 'TemplateCopyService',
function(
$scope, $rootScope, $location, $stateParams, Rest, Alert,
TemplateList, Prompt, ClearScope, ProcessErrors, GetBasePath,
@@ -36,38 +37,40 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest', 'Al
$scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
$scope.options = {};
$rootScope.flashMessage = null;
}
if ($scope.removeChoicesReady) {
$scope.removeChoicesReady();
$scope.$on(`${list.iterator}_options`, function(event, data){
$scope.options = data.data.actions.GET;
optionsRequestDataProcessing();
});
$scope.$watchCollection('templates', function() {
optionsRequestDataProcessing();
}
$scope.removeChoicesReady = $scope.$on('choicesReady', function() {
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
);
// iterate over the list and add fields like type label, after the
// OPTIONS request returns, or the list is sorted/paginated/searched
function optionsRequestDataProcessing(){
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
// Set the item type label
if (list.fields.type) {
$scope.type_choices.every(function(choice) {
if (choice.value === item.type) {
itm.type_label = choice.label;
return false;
}
return true;
});
}
});
});
GetChoices({
scope: $scope,
url: GetBasePath('unified_job_templates'),
field: 'type',
variable: 'type_choices',
callback: 'choicesReady'
// Set the item type label
if (list.fields.type && $scope.options.hasOwnProperty('type')) {
$scope.options.type.choices.every(function(choice) {
if (choice[0] === item.type) {
itm.type_label = choice[1];
return false;
}
return true;
});
}
});
}
$scope.$on(`ws-jobs`, function () {
// @issue - this is no longer quite as ham-fisted but I'd like for someone else to take a peek
// calling $state.reload(); here was problematic when launching a job because job launch also

View File

@@ -115,7 +115,7 @@ angular.module('templates', [surveyMaker.name, templatesList.name, jobTemplatesA
},
'jobTemplateList@templates.editWorkflowJobTemplate.workflowMaker': {
templateProvider: function(WorkflowMakerJobTemplateList, generateList) {
//debugger;
let html = generateList.build({
list: WorkflowMakerJobTemplateList,
input_type: 'radio',