diff --git a/awx/ui/client/src/controllers/Jobs.js b/awx/ui/client/src/controllers/Jobs.js index c68c6c5826..3ea53d3191 100644 --- a/awx/ui/client/src/controllers/Jobs.js +++ b/awx/ui/client/src/controllers/Jobs.js @@ -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(); @@ -29,39 +29,68 @@ export function JobsListController($state, $rootScope, $log, $scope, $compile, $ $scope.showJobType = true; - _.forEach($scope[list.name], buildTooltips); - if ($scope.removeChoicesReady) { - $scope.removeChoicesReady(); + // _.forEach($scope[list.name], buildTooltips); + // if ($scope.removeChoicesReady) { + // $scope.removeChoicesReady(); + // } + // $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; + // return false; + // } + // return true; + // }); + // } + // }); + // }); + + + } + $scope.$on(`${list.iterator}_options`, function(event, data){ + $scope.options = data.data.actions.GET; + optionsRequestDataProcessing(); + }); + + $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 +160,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' ]; diff --git a/awx/ui/client/src/controllers/Projects.js b/awx/ui/client/src/controllers/Projects.js index 1eb8fbb2df..d0c845a058 100644 --- a/awx/ui/client/src/controllers/Projects.js +++ b/awx/ui/client/src/controllers/Projects.js @@ -37,7 +37,7 @@ export function ProjectsList($scope, $rootScope, $location, $log, $stateParams, _.forEach($scope[list.name], buildTooltips); $rootScope.flashMessage = null; } - + $scope.$on(`${list.iterator}_options`, function(event, data){ $scope.options = data.data.actions.GET; optionsRequestDataProcessing(); @@ -66,13 +66,10 @@ export function ProjectsList($scope, $rootScope, $location, $log, $stateParams, }); } - _.forEach($scope[list.name], buildTooltips); + buildTooltips(itm); }); } - // $scope.$watch(`${list.name}`, function() { - // _.forEach($scope[list.name], buildTooltips); - // }); function buildTooltips(project) { project.statusIcon = GetProjectIcon(project.status);