From a36ce01537e5b4ff9408d9846f010beb025e9554 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 14 Feb 2017 10:56:09 -0500 Subject: [PATCH 1/2] adding options callback for project type labels --- .../rbac-multiselect-list.directive.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/awx/ui/client/src/access/rbac-multiselect/rbac-multiselect-list.directive.js b/awx/ui/client/src/access/rbac-multiselect/rbac-multiselect-list.directive.js index aebe4c94bb..c03e7fb275 100644 --- a/awx/ui/client/src/access/rbac-multiselect/rbac-multiselect-list.directive.js +++ b/awx/ui/client/src/access/rbac-multiselect/rbac-multiselect-list.directive.js @@ -123,6 +123,36 @@ export default ['addPermissionsTeamsList', 'addPermissionsUsersList', 'TemplateL _.forEach(scope[`${list.name}`], isSelected); }); + scope.$on(`${list.iterator}_options`, function(event, data){ + scope.options = data.data.actions.GET; + 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(){ + if(scope.list.name === 'projects'){ + if (scope[list.name] !== undefined) { + 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; + }); + } + + }); + } + } + } + function isSelected(item){ if(_.find(scope.allSelected, {id: item.id, type: item.type})){ item.isSelected = true; From 576984922d52ef26c7460dd3dca52add28dad26a Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 14 Feb 2017 14:36:19 -0500 Subject: [PATCH 2/2] auditing .every() and replacing with .forEach() --- .../rbac-multiselect-list.directive.js | 10 ++++------ awx/ui/client/src/controllers/Credentials.js | 6 ++---- awx/ui/client/src/controllers/Projects.js | 8 ++------ awx/ui/client/src/helpers/Jobs.js | 8 ++------ awx/ui/client/src/jobs/jobs-list.controller.js | 4 +--- .../notification-templates-list/list.controller.js | 4 +--- .../organizations-job-templates.controller.js | 4 +--- .../controllers/organizations-projects.controller.js | 8 ++------ .../src/templates/list/templates-list.controller.js | 4 +--- 9 files changed, 16 insertions(+), 40 deletions(-) diff --git a/awx/ui/client/src/access/rbac-multiselect/rbac-multiselect-list.directive.js b/awx/ui/client/src/access/rbac-multiselect/rbac-multiselect-list.directive.js index c03e7fb275..16594c01a9 100644 --- a/awx/ui/client/src/access/rbac-multiselect/rbac-multiselect-list.directive.js +++ b/awx/ui/client/src/access/rbac-multiselect/rbac-multiselect-list.directive.js @@ -138,15 +138,13 @@ export default ['addPermissionsTeamsList', 'addPermissionsUsersList', 'TemplateL // 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) { + scope.options.hasOwnProperty('scm_type')) { + scope.options.scm_type.choices.forEach(function(choice) { + if (choice[0] === item.scm_type) { itm.type_label = choice[1]; - return false; } - return true; }); - } + } }); } diff --git a/awx/ui/client/src/controllers/Credentials.js b/awx/ui/client/src/controllers/Credentials.js index 3c06b69182..93b0e5909c 100644 --- a/awx/ui/client/src/controllers/Credentials.js +++ b/awx/ui/client/src/controllers/Credentials.js @@ -56,12 +56,10 @@ export function CredentialsList($scope, $rootScope, $location, $log, // Set the item type label if (list.fields.kind && $scope.options && $scope.options.hasOwnProperty('kind')) { - $scope.options.kind.choices.every(function(choice) { + $scope.options.kind.choices.forEach(function(choice) { if (choice[0] === item.kind) { itm.kind_label = choice[1]; - return false; } - return true; }); } }); @@ -462,7 +460,7 @@ export function CredentialsEdit($scope, $rootScope, $compile, $location, $log, form: form, reset: false }); - + master.kind = $scope.kind; CreateSelect2({ diff --git a/awx/ui/client/src/controllers/Projects.js b/awx/ui/client/src/controllers/Projects.js index 4b4ef05c19..e97194c1b1 100644 --- a/awx/ui/client/src/controllers/Projects.js +++ b/awx/ui/client/src/controllers/Projects.js @@ -58,12 +58,10 @@ export function ProjectsList($scope, $rootScope, $location, $log, $stateParams, // 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) { + $scope.options.scm_type.choices.forEach(function(choice) { if (choice[0] === item.scm_type) { itm.type_label = choice[1]; - return false; } - return true; }); } @@ -275,7 +273,7 @@ export function ProjectsList($scope, $rootScope, $location, $log, $stateParams, } catch (e) { // ignore } - $scope.projects.every(function(project) { + $scope.projects.forEach(function(project) { if (project.id === project_id) { if (project.scm_type === "Manual" || Empty(project.scm_type)) { // Do not respond. Button appears greyed out as if it is disabled. Not disabled though, because we need mouse over event @@ -286,9 +284,7 @@ export function ProjectsList($scope, $rootScope, $location, $log, $stateParams, } else { ProjectUpdate({ scope: $scope, project_id: project.id }); } - return false; } - return true; }); }; diff --git a/awx/ui/client/src/helpers/Jobs.js b/awx/ui/client/src/helpers/Jobs.js index 13a0198bb7..ff5cdfead1 100644 --- a/awx/ui/client/src/helpers/Jobs.js +++ b/awx/ui/client/src/helpers/Jobs.js @@ -88,21 +88,17 @@ export default // Set the item type label if (list.fields.type) { - parent_scope.type_choices.every(function(choice) { + parent_scope.type_choices.forEach(function(choice) { if (choice.value === item.type) { itm.type_label = choice.label; - return false; } - return true; }); } // Set the job status label - parent_scope.status_choices.every(function(status) { + parent_scope.status_choices.forEach(function(status) { if (status.value === item.status) { itm.status_label = status.label; - return false; } - return true; }); if (list.name === 'completed_jobs' || list.name === 'running_jobs') { diff --git a/awx/ui/client/src/jobs/jobs-list.controller.js b/awx/ui/client/src/jobs/jobs-list.controller.js index d590cf7e17..ac1ef684cd 100644 --- a/awx/ui/client/src/jobs/jobs-list.controller.js +++ b/awx/ui/client/src/jobs/jobs-list.controller.js @@ -58,12 +58,10 @@ // Set the item type label if (list.fields.type && $scope.options && $scope.options.hasOwnProperty('type')) { - $scope.options.type.choices.every(function(choice) { + $scope.options.type.choices.forEach(function(choice) { if (choice[0] === item.type) { itm.type_label = choice[1]; - return false; } - return true; }); } buildTooltips(itm); diff --git a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js index d3aec68845..867c0ad914 100644 --- a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js +++ b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js @@ -50,14 +50,12 @@ // 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) { + $scope.options.notification_type.choices.forEach(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); diff --git a/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js b/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js index e42d67659d..3f81b1550b 100644 --- a/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js +++ b/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js @@ -60,12 +60,10 @@ export default ['$scope', '$rootScope', '$location', '$log', // Set the item type label if (list.fields.type && $scope.options && $scope.options.hasOwnProperty('type')) { - $scope.options.type.choices.every(function(choice) { + $scope.options.type.choices.forEach(function(choice) { if (choice[0] === item.type) { itm.type_label = choice[1]; - return false; } - return true; }); } }); diff --git a/awx/ui/client/src/organizations/linkout/controllers/organizations-projects.controller.js b/awx/ui/client/src/organizations/linkout/controllers/organizations-projects.controller.js index c43e50aa15..7032ef5f81 100644 --- a/awx/ui/client/src/organizations/linkout/controllers/organizations-projects.controller.js +++ b/awx/ui/client/src/organizations/linkout/controllers/organizations-projects.controller.js @@ -85,12 +85,10 @@ export default ['$scope', '$rootScope', '$location', '$log', // 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) { + $scope.options.scm_type.choices.forEach(function(choice) { if (choice[0] === item.scm_type) { itm.type_label = choice[1]; - return false; } - return true; }); } @@ -301,7 +299,7 @@ export default ['$scope', '$rootScope', '$location', '$log', } catch (e) { // ignore } - $scope.projects.every(function(project) { + $scope.projects.forEach(function(project) { if (project.id === project_id) { if (project.scm_type === "Manual" || Empty(project.scm_type)) { // Do not respond. Button appears greyed out as if it is disabled. Not disabled though, because we need mouse over event @@ -312,9 +310,7 @@ export default ['$scope', '$rootScope', '$location', '$log', } else { ProjectUpdate({ scope: $scope, project_id: project.id }); } - return false; } - return true; }); }; diff --git a/awx/ui/client/src/templates/list/templates-list.controller.js b/awx/ui/client/src/templates/list/templates-list.controller.js index d3e07c6fda..5fc6695ca2 100644 --- a/awx/ui/client/src/templates/list/templates-list.controller.js +++ b/awx/ui/client/src/templates/list/templates-list.controller.js @@ -59,12 +59,10 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest', // Set the item type label if (list.fields.type && $scope.options.hasOwnProperty('type')) { - $scope.options.type.choices.every(function(choice) { + $scope.options.type.choices.forEach(function(choice) { if (choice[0] === item.type) { itm.type_label = choice[1]; - return false; } - return true; }); } });