From 802fed2a7646e0218bafa9f112c0e0e609c28e02 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Mon, 20 Apr 2015 20:03:06 -0400 Subject: [PATCH 1/3] migrated job templates to use new verbosity format --- awx/ui/static/js/controllers/JobTemplates.js | 92 ++++++++++++-------- awx/ui/static/js/forms/JobTemplates.js | 2 +- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index 3ae8461e61..efe76aa1ac 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -249,7 +249,7 @@ JobTemplatesList.$inject = ['$scope', '$rootScope', '$location', '$log', '$route export function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, GetBasePath, InventoryList, CredentialList, ProjectList, LookUpInit, md5Setup, ParseTypeChange, Wait, Empty, ToJSON, - CallbackHelpInit, SurveyControllerInit, Prompt) { + CallbackHelpInit, SurveyControllerInit, Prompt, GetChoices) { ClearScope(); @@ -280,12 +280,6 @@ export function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $ { value: 'scan' , label: 'Scan'} ]; - $scope.verbosity_options = [ - { value: 0, label: 'Default' }, - { value: 1, label: 'Verbose' }, - { value: 3, label: 'Debug' } - ]; - $scope.playbook_options = []; $scope.allow_callbacks = 'false'; @@ -315,34 +309,55 @@ export function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $ CloudCredentialList.name = 'cloudcredentials'; CloudCredentialList.iterator = 'cloudcredential'; - LookUpInit({ - url: GetBasePath('credentials') + '?cloud=true', - scope: $scope, - form: form, - current_item: null, - list: CloudCredentialList, - field: 'cloud_credential', - hdr: 'Select Cloud Credential', - input_type: 'radio' - }); - - LookUpInit({ - url: GetBasePath('credentials') + '?kind=ssh', - scope: $scope, - form: form, - current_item: null, - list: CredentialList, - field: 'credential', - hdr: 'Select Machine Credential', - input_type: "radio" - }); - SurveyControllerInit({ scope: $scope, parent_scope: $scope }); + if ($scope.removeLookUpInitialize) { + $scope.removeLookUpInitialize(); + } + $scope.removeLookUpInitialize = $scope.$on('lookUpInitialize', function () { + LookUpInit({ + url: GetBasePath('credentials') + '?cloud=true', + scope: $scope, + form: form, + current_item: null, + list: CloudCredentialList, + field: 'cloud_credential', + hdr: 'Select Cloud Credential', + input_type: 'radio' + }); + LookUpInit({ + url: GetBasePath('credentials') + '?kind=ssh', + scope: $scope, + form: form, + current_item: null, + list: CredentialList, + field: 'credential', + hdr: 'Select Machine Credential', + input_type: "radio" + }); + }); + + if ($scope.removeChoicesReady) { + $scope.removeChoicesReady(); + } + $scope.removeChoicesReady = $scope.$on('choicesReadyVerbosity', function () { + // this sets the default option as specified by the controller. + $scope.verbosity = $scope.verbosity_options[$scope.verbosity_field.default]; + $scope.$emit('lookUpInitialize'); + }); + + // setup verbosity options lookup + GetChoices({ + scope: $scope, + url: defaultUrl, + field: 'verbosity', + variable: 'verbosity_options', + callback: 'choicesReadyVerbosity' + }); // Update playbook select whenever project value changes selectPlaybook = function (oldValue, newValue) { @@ -621,7 +636,7 @@ export function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $ JobTemplatesAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit', - 'md5Setup', 'ParseTypeChange', 'Wait', 'Empty', 'ToJSON', 'CallbackHelpInit', 'SurveyControllerInit', 'Prompt' + 'md5Setup', 'ParseTypeChange', 'Wait', 'Empty', 'ToJSON', 'CallbackHelpInit', 'SurveyControllerInit', 'Prompt', 'GetChoices' ]; @@ -660,12 +675,6 @@ export function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, { value: 'scan', label: 'Scan'} ]; - $scope.verbosity_options = [ - { value: 0, label: 'Default' }, - { value: 1, label: 'Verbose' }, - { value: 3, label: 'Debug' } - ]; - SurveyControllerInit({ scope: $scope, parent_scope: $scope, @@ -963,7 +972,7 @@ export function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, } $scope.removeChoicesReady = $scope.$on('choicesReady', function() { choicesCount++; - if (choicesCount === 2) { + if (choicesCount === 3) { $scope.$emit('LoadJobs'); } }); @@ -984,6 +993,15 @@ export function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, callback: 'choicesReady' }); + // setup verbosity options lookup + GetChoices({ + scope: $scope, + url: defaultUrl, + field: 'verbosity', + variable: 'verbosity_options', + callback: 'choicesReady' + }); + function saveCompleted() { setTimeout(function() { $scope.$apply(function() { diff --git a/awx/ui/static/js/forms/JobTemplates.js b/awx/ui/static/js/forms/JobTemplates.js index a87c88e5b9..be05435de3 100644 --- a/awx/ui/static/js/forms/JobTemplates.js +++ b/awx/ui/static/js/forms/JobTemplates.js @@ -199,7 +199,7 @@ export default label: 'Verbosity', type: 'select', ngOptions: 'v.label for v in verbosity_options track by v.value', - "default": 0, + "default": 1, addRequired: true, editRequired: true, column: 1, From bcd57b18c20b1f47e504d4e12f21f889c631aded Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Tue, 21 Apr 2015 13:31:08 -0400 Subject: [PATCH 2/3] migrated job type select to using api options as well --- awx/ui/static/js/controllers/JobTemplates.js | 49 ++++++++++++-------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index efe76aa1ac..5ea22e9998 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -272,13 +272,7 @@ export function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $ }; $scope.mode = "add"; $scope.parseType = 'yaml'; - ParseTypeChange({ scope: $scope, field_id: 'job_templates_variables', onChange: callback }); - - $scope.job_type_options = [ - { value: 'run', label: 'Run' }, - { value: 'check', label: 'Check' }, - { value: 'scan' , label: 'Scan'} - ]; + ParseTypeChange({ scope: $scope, field_id: 'job_templates_variables', onChange: callback }) $scope.playbook_options = []; $scope.allow_callbacks = 'false'; @@ -341,16 +335,22 @@ export function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $ }); }); + var selectCount = 0; + if ($scope.removeChoicesReady) { $scope.removeChoicesReady(); } $scope.removeChoicesReady = $scope.$on('choicesReadyVerbosity', function () { - // this sets the default option as specified by the controller. - $scope.verbosity = $scope.verbosity_options[$scope.verbosity_field.default]; - $scope.$emit('lookUpInitialize'); + selectCount++; + if (selectCount === 2) { + // this sets the default options for the selects as specified by the controller. + $scope.verbosity = $scope.verbosity_options[$scope.verbosity_field.default]; + $scope.job_type = $scope.job_type_options[$scope.job_type_field.default]; + $scope.$emit('lookUpInitialize'); + } }); - // setup verbosity options lookup + // setup verbosity options select GetChoices({ scope: $scope, url: defaultUrl, @@ -359,6 +359,15 @@ export function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $ callback: 'choicesReadyVerbosity' }); + // setup job type options select + GetChoices({ + scope: $scope, + url: defaultUrl, + field: 'job_type', + variable: 'job_type_options', + callback: 'choicesReadyVerbosity' + }); + // Update playbook select whenever project value changes selectPlaybook = function (oldValue, newValue) { var url; @@ -668,13 +677,6 @@ export function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $scope.parseType = 'yaml'; $scope.showJobType = false; - // Our job type options - $scope.job_type_options = [ - { value: 'run', label: 'Run' }, - { value: 'check', label: 'Check' }, - { value: 'scan', label: 'Scan'} - ]; - SurveyControllerInit({ scope: $scope, parent_scope: $scope, @@ -972,7 +974,7 @@ export function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, } $scope.removeChoicesReady = $scope.$on('choicesReady', function() { choicesCount++; - if (choicesCount === 3) { + if (choicesCount === 4) { $scope.$emit('LoadJobs'); } }); @@ -1002,6 +1004,15 @@ export function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, callback: 'choicesReady' }); + // setup job type options lookup + GetChoices({ + scope: $scope, + url: defaultUrl, + field: 'job_type', + variable: 'job_type_options', + callback: 'choicesReady' + }); + function saveCompleted() { setTimeout(function() { $scope.$apply(function() { From ef3c18e0712c64e35bdb2d1c5aea75f0ea6429c5 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Tue, 21 Apr 2015 13:33:06 -0400 Subject: [PATCH 3/3] fix jshint error --- awx/ui/static/js/controllers/JobTemplates.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index 5ea22e9998..7563b987c4 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -272,7 +272,7 @@ export function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $ }; $scope.mode = "add"; $scope.parseType = 'yaml'; - ParseTypeChange({ scope: $scope, field_id: 'job_templates_variables', onChange: callback }) + ParseTypeChange({ scope: $scope, field_id: 'job_templates_variables', onChange: callback }); $scope.playbook_options = []; $scope.allow_callbacks = 'false';