add use code-mirror directive for host variables; fix multiple code-mirrors on page at once

This commit is contained in:
Keith Grant 2019-03-18 11:48:21 -04:00
parent bed63b3690
commit 5d3e39beac
9 changed files with 55 additions and 46 deletions

View File

@ -350,7 +350,7 @@
<at-code-mirror
class="JobResults-resultRow"
ng-if="vm.extraVars"
variables="{{ vm.extraVars.value }}"
variables="vm.extraVars.value"
tooltip="{{ vm.extraVars.tooltip }}"
label="{{ vm.extraVars.label }}"
name="{{ vm.extraVars.name }}"
@ -361,7 +361,7 @@
<at-code-mirror
class="JobResults-resultRow"
ng-if="vm.artifacts"
variables="{{ vm.artifacts.value }}"
variables="vm.artifacts.value"
tooltip="{{ vm.artifacts.tooltip }}"
label="{{ vm.artifacts.label }}"
name="{{ vm.artifacts.name }}"

View File

@ -9,18 +9,19 @@ function atCodeMirrorController (
ParseTypeChange
) {
const vm = this;
const variablesName = `${$scope.name}_variables`;
function init () {
if ($scope.disabled === 'true') {
$scope.disabled = true;
} else if ($scope.disabled === 'false') {
$scope.disabled = false;
}
$scope.value = $scope.variables.value;
$scope.parseType = ParseType;
$scope[variablesName] = $scope.variables;
ParseTypeChange({
scope: $scope,
variable: 'variables',
variable: variablesName,
parse_variable: 'parseType',
field_id: `${$scope.name}_variables`,
readOnly: $scope.disabled
@ -37,10 +38,11 @@ function atCodeMirrorController (
// user changes the format from yaml to json in the
// modal but CM in the form is set to YAML
$scope.variables = varsFromModal;
$scope[variablesName] = $scope.variables;
// New set of variables from the modal, reinit codemirror
ParseTypeChange({
scope: $scope,
variable: 'variables',
variable: variablesName,
parse_variable: 'parseType',
field_id: `${$scope.name}_variables`,
readOnly: $scope.disabled
@ -56,6 +58,7 @@ function atCodeMirrorController (
vm.expanded = false;
vm.close = close;
vm.expand = expand;
vm.variablesName = variablesName;
if ($scope.init) {
$scope.init = init;
}

View File

@ -23,7 +23,7 @@
type="radio"
value="yaml"
ng-model="parseType"
ng-change="parseTypeChange('parseType', 'variables')"
ng-change="parseTypeChange('parseType', vm.variablesName)"
class="ng-pristine ng-untouched ng-valid ng-not-empty">
{{ vm.strings.get('label.YAML')}}
</label>
@ -32,7 +32,7 @@
type="radio"
value="json"
ng-model="parseType"
ng-change="parseTypeChange('parseType', 'variables')"
ng-change="parseTypeChange('parseType', vm.variablesName)"
class="ng-pristine ng-untouched ng-valid ng-not-empty">
{{ vm.strings.get('label.JSON')}}
</label>

View File

@ -13,7 +13,7 @@ function atCodeMirrorModalController (
ParseTypeChange
) {
const vm = this;
const variablesName = `${$scope.name}_variables`;
// const variablesName = `${$scope.name}_variables`;
function resize () {
if ($scope.disabled === 'true') {
$scope.disabled = true;
@ -53,8 +53,6 @@ function atCodeMirrorModalController (
minWidth: 600
});
$(`${CodeMirrorModalID} .modal-dialog`).on('resize', resize);
$scope.foovars = 'testing';
}
vm.strings = strings;

View File

@ -65,12 +65,15 @@ function(i18n) {
type: 'text'
},
variables: {
root: 'host_variables',
label: i18n._('Variables'),
type: 'textarea',
type: 'code_mirror',
rows: 6,
variables: 'variables',
class: 'Form-formGroup--fullWidth',
"default": "---",
awPopOver: "<p>" + i18n._("Enter inventory variables using either JSON or YAML syntax. Use the radio button to toggle between the two.") + "</p>" +
awPopOver: i18n._('Enter inventory variables using either JSON or YAML syntax. Use the radio button to toggle between the two.'),
_awPopOver: "<p>" + i18n._("Enter inventory variables using either JSON or YAML syntax. Use the radio button to toggle between the two.") + "</p>" +
"JSON:<br />\n" +
"<blockquote>{<br />&emsp;\"somevar\": \"somevalue\",<br />&emsp;\"password\": \"magic\"<br /> }</blockquote>\n" +
"YAML:<br />\n" +

View File

@ -40,11 +40,11 @@
$rootScope.breadcrumb.host_name = host.name;
$scope.description = host.description;
$scope.host_variables = getVars(host.variables);
ParseTypeChange({
scope: $scope,
field_id: 'host_host_variables',
variable: 'host_variables',
});
// ParseTypeChange({
// scope: $scope,
// field_id: 'host_host_variables',
// variable: 'host_variables',
// });
};
// Adding this function b/c sometimes extra vars are returned to the

View File

@ -66,17 +66,35 @@ function(i18n) {
},
host_variables: {
label: i18n._('Variables'),
type: 'textarea',
type: 'code_mirror',
root: 'host_variables',
rows: 6,
class: 'Form-formGroup--fullWidth',
"default": "---",
awPopOver: "<p>" + i18n._("Enter inventory variables using either JSON or YAML syntax. Use the radio button to toggle between the two.") + "</p>" +
"JSON:<br />\n" +
"<blockquote>{<br />&emsp;\"somevar\": \"somevalue\",<br />&emsp;\"password\": \"magic\"<br /> }</blockquote>\n" +
"YAML:<br />\n" +
"<blockquote>---<br />somevar: somevalue<br />password: magic<br /></blockquote>\n" +
'<p>' + i18n.sprintf(i18n._('View JSON examples at %s'), '<a href="http://www.json.org" target="_blank">www.json.org</a>') + '</p>' +
'<p>' + i18n.sprintf(i18n._('View YAML examples at %s'), '<a href="http://docs.ansible.com/YAMLSyntax.html" target="_blank">docs.ansible.com</a>') + '</p>',
variables: 'host_variables',
awPopOver: `<p>${i18n._("Enter inventory variables using either JSON or YAML syntax. Use the radio button to toggle between the two.")}</p>
JSON:<br />
<blockquote>
{<br />&emsp;&quot;somevar&quot;: &quot;somevalue&quot;,<br />&emsp;&quot;password&quot;: &quot;magic&quot;<br /> }
</blockquote>
YAML:<br />
<blockquote>
---<br />
somevar: somevalue<br />
password: magic<br />
</blockquote>
<p>${i18n.sprintf(i18n._(
'View JSON examples at %s'),
'<a href=&quot;http://www.json.org&quot; target=&quot;_blank&quot;>www.json.org</a>'
)}</p>
<p>${i18n.sprintf(i18n._('View YAML examples at %s'), '<a href=&quot;http://docs.ansible.com/YAMLSyntax.html&quot; target=&quot;_blank&quot;>docs.ansible.com</a>')}</p>`,
// _awPopOver: "<p>" + i18n._("Enter inventory variables using either JSON or YAML syntax. Use the radio button to toggle between the two.") + "</p>" +
// "JSON:<br />\n" +
// "<blockquote>{<br />&emsp;\"somevar\": \"somevalue\",<br />&emsp;\"password\": \"magic\"<br /> }</blockquote>\n" +
// "YAML:<br />\n" +
// "<blockquote>---<br />somevar: somevalue<br />password: magic<br /></blockquote>\n", // +
// '<p>' + i18n.sprintf(i18n._('View JSON examples at %s'), '<a href="http://www.json.org" target="_blank">www.json.org</a>') + '</p>' +
// '<p>' + i18n.sprintf(i18n._('View YAML examples at %s'), '<a href="http://docs.ansible.com/YAMLSyntax.html" target="_blank">docs.ansible.com</a>') + '</p>',
dataTitle: i18n._('Host Variables'),
dataPlacement: 'right',
dataContainer: 'body',

View File

@ -66,33 +66,20 @@ function(i18n) {
dataContainer: 'body',
control: '<instance-groups-multiselect instance-groups="instance_groups" field-is-disabled="!(inventory_obj.summary_fields.user_capabilities.edit || canAdd)"></instance-groups-multiselect>',
},
// 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',
// realName: 'variables',
root: 'inventory',
label: i18n._('Variables'),
type: 'code_mirror',
class: 'Form-formGroup--fullWidth',
rows: 6,
"default": "---",
// 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',
dataContainer: 'body',
ngDisabled: '!(inventory_obj.summary_fields.user_capabilities.edit || canAdd)' // TODO: get working
// dataTitle: i18n._('Variables'),
// dataPlacement: 'right',
// dataContainer: 'body',
// ngDisabled: '!(inventory_obj.summary_fields.user_capabilities.edit || canAdd)' // TODO: get working
}
},

View File

@ -1370,7 +1370,7 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
html += `class="${field.class}" `;
html += `label="${field.label}" `;
html += `tooltip="${field.awPopOver}" `;
html += `name="${field.root}" `;
html += `name="${fld}" `;
html += `variables="${field.variables}" `;
html += '></at-code-mirror>';
}