From 695a5e9a5db016d13f87d8fca969a5c98e797e07 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Mon, 20 Feb 2017 13:41:51 -0500 Subject: [PATCH 1/7] fixing CTiT select2 dropdowns for when the user hits the RESET button --- .../configuration-auth.controller.js | 29 ++++++------ .../configuration/configuration.controller.js | 8 ++-- .../configuration-jobs.controller.js | 3 +- .../configuration-system.controller.js | 26 ++++++----- .../ui-form/configuration-ui.controller.js | 46 ++++++++++++++----- 5 files changed, 72 insertions(+), 40 deletions(-) diff --git a/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js b/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js index ec50d2a3b3..fe85f071ea 100644 --- a/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js +++ b/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js @@ -227,16 +227,15 @@ export default [ // Flag to avoid re-rendering and breaking Select2 dropdowns on tab switching var dropdownRendered = false; - $scope.$on('populated', function() { - startCodeMirrors(); - // Create Select2 fields - var opts = []; + + function populateLDAPGroupType(flag){ if($scope.$parent.AUTH_LDAP_GROUP_TYPE !== null) { - opts.push({ - id: $scope.$parent.AUTH_LDAP_GROUP_TYPE, - text: $scope.$parent.AUTH_LDAP_GROUP_TYPE - }); + $scope.$parent.AUTH_LDAP_GROUP_TYPE = _.find($scope.$parent.AUTH_LDAP_GROUP_TYPE_options, { value: $scope.$parent.AUTH_LDAP_GROUP_TYPE }); + } + + if(flag !== undefined){ + dropdownRendered = flag; } if(!dropdownRendered) { @@ -245,15 +244,17 @@ export default [ element: '#configuration_ldap_template_AUTH_LDAP_GROUP_TYPE', multiple: false, placeholder: i18n._('Select group types'), - opts: opts }); - // Fix for bug where adding selected opts causes form to be $dirty and triggering modal - // TODO Find better solution for this bug - $timeout(function(){ - $scope.$parent.configuration_ldap_template_form.$setPristine(); - }, 1000); } + } + $scope.$on('AUTH_LDAP_GROUP_TYPE_populated', function(e, data, flag) { + populateLDAPGroupType(flag); + }); + + $scope.$on('populated', function() { + startCodeMirrors(); + populateLDAPGroupType(); }); angular.extend(authVm, { diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index 78b9b228d3..8a3c110838 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -295,9 +295,11 @@ export default [ ConfigurationService.patchConfiguration(payload) .then(function() { $scope[key] = $scope.configDataResolve[key].default; - if(key === "AD_HOC_COMMANDS"){ - $scope.AD_HOC_COMMANDS = $scope.AD_HOC_COMMANDS.toString(); - $scope.$broadcast('adhoc_populated', null, false); + if($scope[key + '_field'].type === "select"){ + // We need to re-instantiate the Select2 element + // after resetting the value. Example: + // `$scope.$broadcast(AD_HOC_COMMANDS_populated)` + $scope.$broadcast(key+'_populated', null, false); } loginUpdate(); }) diff --git a/awx/ui/client/src/configuration/jobs-form/configuration-jobs.controller.js b/awx/ui/client/src/configuration/jobs-form/configuration-jobs.controller.js index 89bf46d458..6a177ae0c1 100644 --- a/awx/ui/client/src/configuration/jobs-form/configuration-jobs.controller.js +++ b/awx/ui/client/src/configuration/jobs-form/configuration-jobs.controller.js @@ -77,6 +77,7 @@ export default [ function populateAdhocCommand(flag){ + $scope.$parent.AD_HOC_COMMANDS = $scope.$parent.AD_HOC_COMMANDS.toString(); var ad_hoc_commands = $scope.$parent.AD_HOC_COMMANDS.split(','); $scope.$parent.AD_HOC_COMMANDS = _.map(ad_hoc_commands, (item) => _.find($scope.$parent.AD_HOC_COMMANDS_options, { value: item })); @@ -94,7 +95,7 @@ export default [ } } - $scope.$on('adhoc_populated', function(e, data, flag) { + $scope.$on('AD_HOC_COMMANDS_populated', function(e, data, flag) { populateAdhocCommand(flag); }); diff --git a/awx/ui/client/src/configuration/system-form/configuration-system.controller.js b/awx/ui/client/src/configuration/system-form/configuration-system.controller.js index c227e0dc92..10ac4b74ef 100644 --- a/awx/ui/client/src/configuration/system-form/configuration-system.controller.js +++ b/awx/ui/client/src/configuration/system-form/configuration-system.controller.js @@ -152,16 +152,21 @@ export default [ var dropdownRendered = false; - $scope.$on('populated', function() { + $scope.$on('populated', function(e, data, flag) { + populateLogAggregator(flag); + }); - var opts = []; + $scope.$on('LOG_AGGREGATOR_TYPE_populated', function(e, data, flag) { + populateLogAggregator(flag); + }); + + function populateLogAggregator(flag){ if($scope.$parent.LOG_AGGREGATOR_TYPE !== null) { - _.each(ConfigurationUtils.listToArray($scope.$parent.LOG_AGGREGATOR_TYPE), function(type) { - opts.push({ - id: type, - text: type - }); - }); + $scope.$parent.LOG_AGGREGATOR_TYPE = _.find($scope.$parent.LOG_AGGREGATOR_TYPE_options, { value: $scope.$parent.LOG_AGGREGATOR_TYPE }); + } + + if(flag !== undefined){ + dropdownRendered = flag; } if(!dropdownRendered) { @@ -170,11 +175,10 @@ export default [ element: '#configuration_logging_template_LOG_AGGREGATOR_TYPE', multiple: false, placeholder: i18n._('Select types'), - opts: opts }); + $scope.$parent.configuration_logging_template_form.LOG_AGGREGATOR_TYPE.$setPristine(); } - - }); + } // Fix for bug where adding selected opts causes form to be $dirty and triggering modal // TODO Find better solution for this bug diff --git a/awx/ui/client/src/configuration/ui-form/configuration-ui.controller.js b/awx/ui/client/src/configuration/ui-form/configuration-ui.controller.js index cea17ca4f0..43cf4d6c98 100644 --- a/awx/ui/client/src/configuration/ui-form/configuration-ui.controller.js +++ b/awx/ui/client/src/configuration/ui-form/configuration-ui.controller.js @@ -78,24 +78,48 @@ // Flag to avoid re-rendering and breaking Select2 dropdowns on tab switching var dropdownRendered = false; - $scope.$on('populated', function(){ + function populatePendoTrackingState(flag){ + if($scope.$parent.PENDO_TRACKING_STATE !== null) { + $scope.$parent.PENDO_TRACKING_STATE = _.find($scope.$parent.PENDO_TRACKING_STATE_options, { value: $scope.$parent.PENDO_TRACKING_STATE }); + } + + if(flag !== undefined){ + dropdownRendered = flag; + } + if(!dropdownRendered) { dropdownRendered = true; CreateSelect2({ element: '#configuration_ui_template_PENDO_TRACKING_STATE', multiple: false, - placeholder: i18n._('Select commands'), - opts: [{ - id: $scope.$parent.PENDO_TRACKING_STATE, - text: $scope.$parent.PENDO_TRACKING_STATE - }] + placeholder: i18n._('Select commands') }); - // Fix for bug where adding selected opts causes form to be $dirty and triggering modal - // TODO Find better solution for this bug - $timeout(function(){ - $scope.$parent.configuration_ui_template_form.$setPristine(); - }, 1000); } + } + + $scope.$on('PENDO_TRACKING_STATE_populated', function(e, data, flag) { + populatePendoTrackingState(flag); + }); + + $scope.$on('populated', function(e, data, flag){ + populatePendoTrackingState(flag); + // if(!dropdownRendered) { + // dropdownRendered = true; + // CreateSelect2({ + // element: '#configuration_ui_template_PENDO_TRACKING_STATE', + // multiple: false, + // placeholder: i18n._('Select commands'), + // opts: [{ + // id: $scope.$parent.PENDO_TRACKING_STATE, + // text: $scope.$parent.PENDO_TRACKING_STATE + // }] + // }); + // // Fix for bug where adding selected opts causes form to be $dirty and triggering modal + // // TODO Find better solution for this bug + // $timeout(function(){ + // $scope.$parent.configuration_ui_template_form.$setPristine(); + // }, 1000); + // } }); angular.extend(uiVm, { From 578988f2e4dba5db7ddbc0201d4a2958e03cbef1 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 21 Feb 2017 14:08:23 -0800 Subject: [PATCH 2/7] changing "RESET" to "REVERT" --- .../ui-form/configuration-ui.controller.js | 17 ----------------- awx/ui/client/src/shared/form-generator.js | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/awx/ui/client/src/configuration/ui-form/configuration-ui.controller.js b/awx/ui/client/src/configuration/ui-form/configuration-ui.controller.js index 43cf4d6c98..e5ee604091 100644 --- a/awx/ui/client/src/configuration/ui-form/configuration-ui.controller.js +++ b/awx/ui/client/src/configuration/ui-form/configuration-ui.controller.js @@ -103,23 +103,6 @@ $scope.$on('populated', function(e, data, flag){ populatePendoTrackingState(flag); - // if(!dropdownRendered) { - // dropdownRendered = true; - // CreateSelect2({ - // element: '#configuration_ui_template_PENDO_TRACKING_STATE', - // multiple: false, - // placeholder: i18n._('Select commands'), - // opts: [{ - // id: $scope.$parent.PENDO_TRACKING_STATE, - // text: $scope.$parent.PENDO_TRACKING_STATE - // }] - // }); - // // Fix for bug where adding selected opts causes form to be $dirty and triggering modal - // // TODO Find better solution for this bug - // $timeout(function(){ - // $scope.$parent.configuration_ui_template_form.$setPristine(); - // }, 1000); - // } }); angular.extend(uiVm, { diff --git a/awx/ui/client/src/shared/form-generator.js b/awx/ui/client/src/shared/form-generator.js index 90abc6c119..f5b6a8b243 100644 --- a/awx/ui/client/src/shared/form-generator.js +++ b/awx/ui/client/src/shared/form-generator.js @@ -678,7 +678,7 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat if(field.reset && !field.disabled) { var resetValue = "'" + field.reset+ "'"; - var resetMessage = i18n._('Reset'); + var resetMessage = i18n._('Revert'); html+= `${resetMessage}`; } From 198fa2740a3a41caa65e6ddfe79bf954f8afe2d4 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 21 Feb 2017 16:30:45 -0800 Subject: [PATCH 3/7] reverting custom logo --- .../src/configuration/configuration.controller.js | 6 ++++-- awx/ui/client/src/shared/directives.js | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index 8a3c110838..bcfcb14a6a 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -297,10 +297,12 @@ export default [ $scope[key] = $scope.configDataResolve[key].default; if($scope[key + '_field'].type === "select"){ // We need to re-instantiate the Select2 element - // after resetting the value. Example: - // `$scope.$broadcast(AD_HOC_COMMANDS_populated)` + // after resetting the value. Example: $scope.$broadcast(key+'_populated', null, false); } + if($scope[key + '_field'].reset === "CUSTOM_LOGO"){ + $scope.$broadcast(key+'_reverted'); + } loginUpdate(); }) .catch(function(error) { diff --git a/awx/ui/client/src/shared/directives.js b/awx/ui/client/src/shared/directives.js index ad8a44b374..d41ef32eb4 100644 --- a/awx/ui/client/src/shared/directives.js +++ b/awx/ui/client/src/shared/directives.js @@ -168,12 +168,18 @@ function(ConfigurationUtils, i18n, $rootScope) { scope.imageData = $rootScope.custom_logo; }); - scope.update = function(e) { - if(scope.$parent[fieldKey]) { + scope.$on(fieldKey+'_reverted', function(e) { + scope.update(e, true); + }); + + scope.update = function(e, flag) { + if(scope.$parent[fieldKey] || flag ) { e.preventDefault(); scope.$parent[fieldKey] = ''; filePickerButton.html(browseText); filePickerText.val(''); + filePicker.value = ""; + scope.imagePresent = false; } else { // Nothing exists so open file picker From aa1481b9317e6195901072ae0dc131cab0a3370f Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 21 Feb 2017 17:09:45 -0800 Subject: [PATCH 4/7] fix for jshint --- awx/ui/client/src/configuration/configuration.controller.js | 2 +- awx/ui/client/src/shared/directives.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index bcfcb14a6a..39943cd942 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -71,7 +71,7 @@ export default [ // we want the options w/o a space, and // the ConfigurationUtils.arrayToList() // does a string.split(', ') w/ an extra space - // behind the comma. + // behind the comma. if(key === "AD_HOC_COMMANDS"){ $scope[key] = data[key].toString(); } diff --git a/awx/ui/client/src/shared/directives.js b/awx/ui/client/src/shared/directives.js index d41ef32eb4..3f368b0c28 100644 --- a/awx/ui/client/src/shared/directives.js +++ b/awx/ui/client/src/shared/directives.js @@ -159,6 +159,7 @@ function(ConfigurationUtils, i18n, $rootScope) { var filePickerText = angular.element(document.getElementById('filePickerText')); var filePickerError = angular.element(document.getElementById('filePickerError')); var filePickerButton = angular.element(document.getElementById('filePickerButton')); + var filePicker = angular.element(document.getElementById('filePicker')); scope.imagePresent = global.$AnsibleConfig.custom_logo || false; scope.imageData = $rootScope.custom_logo; From 331be6c803ee7500fb52037777c2da3109dcd3bb Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 21 Feb 2017 17:10:01 -0800 Subject: [PATCH 5/7] fix for reverting regular textareas --- awx/ui/client/src/configuration/configuration.controller.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index 39943cd942..d02dd41eef 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -303,6 +303,9 @@ export default [ if($scope[key + '_field'].reset === "CUSTOM_LOGO"){ $scope.$broadcast(key+'_reverted'); } + if($scope[key + '_field'].type === "textarea" && _.isArray($scope.configDataResolve[key].default)){ + $scope[key] = ConfigurationUtils.arrayToList($scope[key], key); + } loginUpdate(); }) .catch(function(error) { From 63f27a120fdd1d8d43715a7a42faa3ac3097b371 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 21 Feb 2017 17:51:10 -0800 Subject: [PATCH 6/7] fixing reset for CodeMirror instances --- .../configuration-auth.controller.js | 49 ++++++++++++------- .../configuration/configuration.controller.js | 8 ++- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js b/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js index fe85f071ea..325d77e611 100644 --- a/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js +++ b/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js @@ -171,26 +171,37 @@ export default [ form.buttons.save.disabled = $rootScope.user_is_system_auditor; }); - function startCodeMirrors(){ - // Attach codemirror to fields that need it + function startCodeMirrors(key){ + + function createIt(name){ + ParseTypeChange({ + scope: $scope.$parent, + variable: name, + parse_variable: 'parseType', + field_id: form.formDef.name + '_' + name + }); + $scope.parseTypeChange('parseType', name); + } + let form = _.find(authForms, function(form){ return form.name === $scope.authVm.activeAuthForm; }); - _.each(form.formDef.fields, function(field) { - // Codemirror balks at empty values so give it one - if($scope.$parent[field.name] === null && field.codeMirror) { - $scope.$parent[field.name] = '{}'; - } - if(field.codeMirror) { - ParseTypeChange({ - scope: $scope.$parent, - variable: field.name, - parse_variable: 'parseType', - field_id: form.formDef.name + '_' + field.name - }); - $scope.parseTypeChange('parseType', field.name); - } - }); + + if(!key){ + // Attach codemirror to fields that need it + _.each(form.formDef.fields, function(field) { + // Codemirror balks at empty values so give it one + if($scope.$parent[field.name] === null && field.codeMirror) { + $scope.$parent[field.name] = '{}'; + } + if(field.codeMirror) { + createIt(field.name) + } + }); + } + else if(key){ + createIt(key); + } } function addFieldInfo(form, key) { @@ -252,6 +263,10 @@ export default [ populateLDAPGroupType(flag); }); + $scope.$on('codeMirror_populated', function(e, key) { + startCodeMirrors(key); + }); + $scope.$on('populated', function() { startCodeMirrors(); populateLDAPGroupType(); diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index d02dd41eef..49a5f2ad99 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -300,12 +300,16 @@ export default [ // after resetting the value. Example: $scope.$broadcast(key+'_populated', null, false); } - if($scope[key + '_field'].reset === "CUSTOM_LOGO"){ + else if($scope[key + '_field'].reset === "CUSTOM_LOGO"){ $scope.$broadcast(key+'_reverted'); } - if($scope[key + '_field'].type === "textarea" && _.isArray($scope.configDataResolve[key].default)){ + else if($scope[key + '_field'].type === "textarea" && _.isArray($scope.configDataResolve[key].default)){ $scope[key] = ConfigurationUtils.arrayToList($scope[key], key); } + else if($scope[key + '_field'].hasOwnProperty('codeMirror')){ + $scope[key] = '{}'; + $scope.$broadcast('codeMirror_populated', key); + } loginUpdate(); }) .catch(function(error) { From b9c2346d570055d512c82b010e4cf9abd2ce486c Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Wed, 22 Feb 2017 10:43:42 -0800 Subject: [PATCH 7/7] fixing jshint error --- .../configuration-auth.controller.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js b/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js index 325d77e611..7b7ecf84bb 100644 --- a/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js +++ b/awx/ui/client/src/configuration/auth-form/configuration-auth.controller.js @@ -172,19 +172,8 @@ export default [ }); function startCodeMirrors(key){ - - function createIt(name){ - ParseTypeChange({ - scope: $scope.$parent, - variable: name, - parse_variable: 'parseType', - field_id: form.formDef.name + '_' + name - }); - $scope.parseTypeChange('parseType', name); - } - - let form = _.find(authForms, function(form){ - return form.name === $scope.authVm.activeAuthForm; + var form = _.find(authForms, function(f){ + return f.name === $scope.authVm.activeAuthForm; }); if(!key){ @@ -195,13 +184,23 @@ export default [ $scope.$parent[field.name] = '{}'; } if(field.codeMirror) { - createIt(field.name) + createIt(field.name); } }); } else if(key){ createIt(key); } + + function createIt(name){ + ParseTypeChange({ + scope: $scope.$parent, + variable: name, + parse_variable: 'parseType', + field_id: form.formDef.name + '_' + name + }); + $scope.parseTypeChange('parseType', name); + } } function addFieldInfo(form, key) {