diff --git a/awx/ui/client/lib/components/code-mirror/code-mirror.directive.js b/awx/ui/client/lib/components/code-mirror/code-mirror.directive.js index 2783f0eaa6..0315485ee4 100644 --- a/awx/ui/client/lib/components/code-mirror/code-mirror.directive.js +++ b/awx/ui/client/lib/components/code-mirror/code-mirror.directive.js @@ -11,21 +11,30 @@ function atCodeMirrorController ( ParseVariableString ) { const vm = this; - const variables = `${$scope.name}_variables`; + const variablesName = `${$scope.name}_variables`; function init (vars, name) { + console.log('init', $scope, vars); if ($scope.disabled === 'true') { $scope.disabled = true; } else if ($scope.disabled === 'false') { $scope.disabled = false; } - $scope[variables] = ParseVariableString(_.cloneDeep(vars)); + $scope.variablesName = variablesName; + // $scope[variablesName] = ParseVariableString(_.cloneDeep(vars)); + $scope.variables = { + value: ParseVariableString(_.cloneDeep(vars)), + }; + $scope.value = $scope.variables.value; $scope.parseType = ParseType; const options = { scope: $scope, - variable: variables, + variable: 'value', // variablesName, parse_variable: ParseVariable, field_id: name, - readOnly: $scope.disabled + readOnly: $scope.disabled, + onChange: (value) => { + console.log('change', value); + }, }; ParseTypeChange(options); } @@ -41,7 +50,7 @@ function atCodeMirrorController ( vm.expanded = false; } - vm.variables = variables; + // vm.variablesName = variablesName; vm.name = $scope.name; vm.modalName = `${vm.name}_modal`; vm.strings = strings; diff --git a/awx/ui/client/lib/components/code-mirror/code-mirror.partial.html b/awx/ui/client/lib/components/code-mirror/code-mirror.partial.html index 7d149af226..97572159f5 100644 --- a/awx/ui/client/lib/components/code-mirror/code-mirror.partial.html +++ b/awx/ui/client/lib/components/code-mirror/code-mirror.partial.html @@ -44,15 +44,15 @@ { + $scope.variables.value = $scope.value; + $scope.closeFn(); + }; if ($scope.init) { $scope.init = init; } angular.element(document).ready(() => { - init($scope.variables, $scope.name); + init($scope.variablesName, $scope.name); }); } @@ -90,7 +95,7 @@ function atCodeMirrorModal () { label: '@', labelClass: '@', tooltip: '@', - variables: '@', + variables: '=', name: '@', closeFn: '&' } diff --git a/awx/ui/client/lib/components/code-mirror/modal/code-mirror-modal.partial.html b/awx/ui/client/lib/components/code-mirror/modal/code-mirror-modal.partial.html index 9785f439f8..57ca4a07be 100644 --- a/awx/ui/client/lib/components/code-mirror/modal/code-mirror-modal.partial.html +++ b/awx/ui/client/lib/components/code-mirror/modal/code-mirror-modal.partial.html @@ -46,13 +46,16 @@ {{ vm.strings.get('label.READONLY')}} - + + {{extra_variables}} + : + {{variables.value}} diff --git a/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/edit/inventory-edit.controller.js b/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/edit/inventory-edit.controller.js index 8f96ae9f6f..6a913598d8 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/edit/inventory-edit.controller.js +++ b/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/edit/inventory-edit.controller.js @@ -40,12 +40,12 @@ function InventoriesEdit($scope, $location, $scope.instance_groups = InstanceGroupsData; $scope.canRemediate = CanRemediate; - ParseTypeChange({ - scope: $scope, - variable: 'inventory_variables', - parse_variable: 'parseType', - field_id: 'inventory_inventory_variables' - }); + // ParseTypeChange({ + // scope: $scope, + // variable: 'inventory_variables', + // parse_variable: 'parseType', + // field_id: 'inventory_inventory_variables' + // }); OrgAdminLookup.checkForRoleLevelAdminAccess(inventoryData.organization, 'inventory_admin_role') .then(function(canEditOrg){ diff --git a/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/inventory.form.js b/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/inventory.form.js index 7e8083bf48..87011f936c 100644 --- a/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/inventory.form.js +++ b/awx/ui/client/src/inventories-hosts/inventories/standard-inventory/inventory.form.js @@ -66,13 +66,27 @@ function(i18n) { dataContainer: 'body', control: '', }, + // inventory_variables: { + // realName: 'variables', + // label: i18n._('Variables'), + // type: 'textarea', + // class: 'Form-formGroup--fullWidth', + // rows: 6, + // "default": "---", + // awPopOver: i18n._('Enter inventory variables using either JSON or YAML syntax. Use the radio button to toggle between the two. Refer to the Ansible Tower documentation for example syntax.'), + // dataTitle: i18n._('Variables'), + // dataPlacement: 'right', + // dataContainer: 'body', + // ngDisabled: '!(inventory_obj.summary_fields.user_capabilities.edit || canAdd)' // TODO: get working + // }, inventory_variables: { realName: 'variables', label: i18n._('Variables'), - type: 'textarea', + type: 'code_mirror', class: 'Form-formGroup--fullWidth', rows: 6, "default": "---", + variables: 'inventory_variables', awPopOver: i18n._('Enter inventory variables using either JSON or YAML syntax. Use the radio button to toggle between the two. Refer to the Ansible Tower documentation for example syntax.'), dataTitle: i18n._('Variables'), dataPlacement: 'right', diff --git a/awx/ui/client/src/shared/form-generator.js b/awx/ui/client/src/shared/form-generator.js index c1b4d7f35f..108c7c3930 100644 --- a/awx/ui/client/src/shared/form-generator.js +++ b/awx/ui/client/src/shared/form-generator.js @@ -1364,6 +1364,17 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat html += "\n"; } + if (field.type === 'code_mirror') { + html += ''; + } + if (field.type === 'custom') { let labelOptions = {}; @@ -1475,7 +1486,7 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat } else { relatedTabSelected = this.form.activeEditState ? `$state.includes('${this.form.activeEditState}.${itm}') || $state.includes('${this.form.stateTree}.edit.${itm}')` : `$state.includes('${this.form.stateTree}.edit.${itm}')`; } - + html += `ng-class="{'is-selected' : ${relatedTabSelected}` ; if(this.form.related[itm].disabled){ html += `, 'Form-tab--disabled' : ${this.form.related[itm].disabled }`; diff --git a/awx/ui/client/src/shared/parse/parse-type-change.factory.js b/awx/ui/client/src/shared/parse/parse-type-change.factory.js index d54af36dcf..218dfbbe9a 100644 --- a/awx/ui/client/src/shared/parse/parse-type-change.factory.js +++ b/awx/ui/client/src/shared/parse/parse-type-change.factory.js @@ -94,7 +94,7 @@ export default // convert json to yaml try { removeField(fld); - + json_obj = JSON.parse(scope[fld]); if ($.isEmptyObject(json_obj)) { scope[fld] = '---';