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

View File

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

View File

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

View File

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

View File

@@ -65,12 +65,15 @@ function(i18n) {
type: 'text' type: 'text'
}, },
variables: { variables: {
root: 'host_variables',
label: i18n._('Variables'), label: i18n._('Variables'),
type: 'textarea', type: 'code_mirror',
rows: 6, rows: 6,
variables: 'variables',
class: 'Form-formGroup--fullWidth', class: 'Form-formGroup--fullWidth',
"default": "---", "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" + "JSON:<br />\n" +
"<blockquote>{<br />&emsp;\"somevar\": \"somevalue\",<br />&emsp;\"password\": \"magic\"<br /> }</blockquote>\n" + "<blockquote>{<br />&emsp;\"somevar\": \"somevalue\",<br />&emsp;\"password\": \"magic\"<br /> }</blockquote>\n" +
"YAML:<br />\n" + "YAML:<br />\n" +

View File

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

View File

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

View File

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