Variable data for hosts/groups/inventory now defaults to YAML. Data received from the API is converted to YAML. Changed job_template extra_vars to use the variable editor approach -user will now enter extra vars as either YAML or JSON with the default being YAML.

This commit is contained in:
chouseknecht
2013-06-28 07:40:36 -04:00
parent 15dd0039c7
commit 202d295fc0
14 changed files with 128 additions and 67 deletions
Vendored
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -60,7 +60,7 @@
} }
.navbar .brand img { .navbar .brand img {
width: 243px; width: 292px;
} }
.navbar .nav { .navbar .nav {
+7 -7
View File
@@ -175,7 +175,7 @@ function InventoriesAdd ($scope, $rootScope, $compile, $location, $log, $routePa
var form = InventoryForm; var form = InventoryForm;
var generator = GenerateForm; var generator = GenerateForm;
var scope = generator.inject(form, {mode: 'add', related: false}); var scope = generator.inject(form, {mode: 'add', related: false});
scope.parseType = 'json'; scope.parseType = 'yaml';
generator.reset(); generator.reset();
LoadBreadCrumbs(); LoadBreadCrumbs();
@@ -239,7 +239,7 @@ function InventoriesAdd ($scope, $rootScope, $compile, $location, $log, $routePa
}); });
} }
catch(err) { catch(err) {
Alert("Error", "Error parsing inventory variables. Parser returned " + err); Alert("Error", "Error parsing inventory variables. Parser returned: " + err);
} }
}; };
@@ -275,7 +275,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
ParseTypeChange(scope); ParseTypeChange(scope);
scope.parseType = 'json'; scope.parseType = 'yaml';
scope['inventory_id'] = id; scope['inventory_id'] = id;
// Retrieve each related set and any lookups // Retrieve each related set and any lookups
@@ -300,10 +300,10 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
Rest.get() Rest.get()
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
if ($.isEmptyObject(data)) { if ($.isEmptyObject(data)) {
scope.variables = "\{\}"; scope.variables = "---";
} }
else { else {
scope.variables = JSON.stringify(data, null, " "); scope.variables = jsyaml.safeDump(data);
} }
}) })
.error( function(data, status, headers, config) { .error( function(data, status, headers, config) {
@@ -313,7 +313,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
}); });
} }
else { else {
scope.variables = "\{\}"; scope.variables = "---";
} }
}); });
@@ -371,7 +371,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
}); });
} }
catch(err) { catch(err) {
Alert("Error", "Error parsing inventory variables. Parser returned " + err); Alert("Error", "Error parsing inventory variables. Parser returned: " + err);
} }
}; };
+62 -9
View File
@@ -159,7 +159,7 @@ JobTemplatesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$rout
function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
GetBasePath, InventoryList, CredentialList, ProjectList, LookUpInit, md5Setup) GetBasePath, InventoryList, CredentialList, ProjectList, LookUpInit, md5Setup, ParseTypeChange)
{ {
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope. //scope.
@@ -171,6 +171,9 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP
var scope = generator.inject(form, {mode: 'add', related: false}); var scope = generator.inject(form, {mode: 'add', related: false});
var master = {}; var master = {};
scope.parseType = 'yaml';
ParseTypeChange(scope);
scope.job_type_options = [{ value: 'run', label: 'Run' }, { value: 'check', label: 'Check' }]; scope.job_type_options = [{ value: 'run', label: 'Run' }, { value: 'check', label: 'Check' }];
scope.verbosity_options = [ scope.verbosity_options = [
{ value: '0', label: 'Default' }, { value: '0', label: 'Default' },
@@ -243,16 +246,29 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP
// Save // Save
scope.formSave = function() { scope.formSave = function() {
Rest.setUrl(defaultUrl);
var data = {} var data = {}
try {
// Make sure we have valid variable data
if (scope.parseType == 'json') {
var myjson = JSON.parse(scope.variables); //make sure JSON parses
var json_data = scope.variables;
}
else {
var json_data = jsyaml.load(scope.variables); //parse yaml
}
for (var fld in form.fields) { for (var fld in form.fields) {
if (form.fields[fld].type == 'select' && fld != 'playbook') { if (form.fields[fld].type == 'select' && fld != 'playbook') {
data[fld] = scope[fld].value; data[fld] = scope[fld].value;
} }
else { else {
if (fld != 'variables') {
data[fld] = scope[fld]; data[fld] = scope[fld];
} }
} }
}
data.extra_vars = json_data;
Rest.setUrl(defaultUrl);
Rest.post(data) Rest.post(data)
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
var base = $location.path().replace(/^\//,'').split('/')[0]; var base = $location.path().replace(/^\//,'').split('/')[0];
@@ -260,8 +276,13 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP
}) })
.error( function(data, status, headers, config) { .error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form, ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to add new project. POST returned status: ' + status }); { hdr: 'Error!', msg: 'Failed to add new job template. POST returned status: ' + status });
}); });
}
catch(err) {
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
}
}; };
// Reset // Reset
@@ -277,13 +298,13 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP
JobTemplatesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm', JobTemplatesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope',
'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit', 'md5Setup' ]; 'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit', 'md5Setup', 'ParseTypeChange' ];
function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, CredentialList, RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, CredentialList,
ProjectList, LookUpInit, PromptPasswords, GetBasePath, md5Setup) ProjectList, LookUpInit, PromptPasswords, GetBasePath, md5Setup, ParseTypeChange)
{ {
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope. //scope.
@@ -293,6 +314,9 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
var form = JobTemplateForm; var form = JobTemplateForm;
var scope = generator.inject(form, {mode: 'edit', related: true}); var scope = generator.inject(form, {mode: 'edit', related: true});
scope.parseType = 'yaml';
ParseTypeChange(scope);
// Our job type options // Our job type options
scope.job_type_options = [{ value: 'run', label: 'Run' }, { value: 'check', label: 'Check' }]; scope.job_type_options = [{ value: 'run', label: 'Run' }, { value: 'check', label: 'Check' }];
scope.verbosity_options = [ scope.verbosity_options = [
@@ -365,7 +389,7 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
LoadBreadCrumbs({ path: '/job_templates/' + id, title: data.name }); LoadBreadCrumbs({ path: '/job_templates/' + id, title: data.name });
for (var fld in form.fields) { for (var fld in form.fields) {
if (data[fld] !== null && data[fld] !== undefined) { if (fld != 'variables' && data[fld] !== null && data[fld] !== undefined) {
if (form.fields[fld].type == 'select') { if (form.fields[fld].type == 'select') {
if (scope[fld + '_options'] && scope[fld + '_options'].length > 0) { if (scope[fld + '_options'] && scope[fld + '_options'].length > 0) {
for (var i=0; i < scope[fld + '_options'].length; i++) { for (var i=0; i < scope[fld + '_options'].length; i++) {
@@ -383,6 +407,16 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
} }
master[fld] = scope[fld]; master[fld] = scope[fld];
} }
if (fld == 'variables') {
// Parse extra_vars, converting to YAML.
if ($.isEmptyObject(data.extra_vars) || data.extra_vars == "\{\}") {
scope.variables = "---";
}
else {
scope.variables = jsyaml.safeDump(JSON.parse(data.extra_vars));
}
master.variables = scope.variables;
}
if (form.fields[fld].type == 'lookup' && data.summary_fields[form.fields[fld].sourceModel]) { if (form.fields[fld].type == 'lookup' && data.summary_fields[form.fields[fld].sourceModel]) {
scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
@@ -435,15 +469,28 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
// Save changes to the parent // Save changes to the parent
scope.formSave = function() { scope.formSave = function() {
var data = {} var data = {}
try {
// Make sure we have valid variable data
if (scope.parseType == 'json') {
var myjson = JSON.parse(scope.variables); //make sure JSON parses
var json_data = scope.variables;
}
else {
var json_data = jsyaml.load(scope.variables); //parse yaml
}
for (var fld in form.fields) { for (var fld in form.fields) {
if (form.fields[fld].type == 'select' && fld != 'playbook') { if (form.fields[fld].type == 'select' && fld != 'playbook') {
data[fld] = scope[fld].value; data[fld] = scope[fld].value;
} }
else { else {
if (fld != 'variables') {
data[fld] = scope[fld]; data[fld] = scope[fld];
} }
} }
Rest.setUrl(defaultUrl + $routeParams.id + '/'); }
data.extra_vars = json_data;
Rest.setUrl(defaultUrl + id + '/');
Rest.put(data) Rest.put(data)
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
var base = $location.path().replace(/^\//,'').split('/')[0]; var base = $location.path().replace(/^\//,'').split('/')[0];
@@ -451,8 +498,13 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
}) })
.error( function(data, status, headers, config) { .error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form, ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update team: ' + $routeParams.id + '. PUT status: ' + status }); { hdr: 'Error!', msg: 'Failed to update job template. PUT returned status: ' + status });
}); });
}
catch(err) {
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
}
}; };
// Cancel // Cancel
@@ -461,6 +513,7 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
for (var fld in master) { for (var fld in master) {
scope[fld] = master[fld]; scope[fld] = master[fld];
} }
scope.parseType = 'yaml';
$('#forks-slider').slider("option", "value", scope.forks); $('#forks-slider').slider("option", "value", scope.forks);
}; };
@@ -506,5 +559,5 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
JobTemplatesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm', JobTemplatesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList', 'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList',
'ProjectList', 'LookUpInit', 'PromptPasswords', 'GetBasePath', 'md5Setup' 'ProjectList', 'LookUpInit', 'PromptPasswords', 'GetBasePath', 'md5Setup', 'ParseTypeChange'
]; ];
+1 -1
View File
@@ -36,7 +36,7 @@ angular.module('GroupFormDefinition', [])
editRequird: false, editRequird: false,
rows: 10, rows: 10,
"class": 'modal-input-xlarge', "class": 'modal-input-xlarge',
"default": "\{\}", "default": "---",
dataTitle: 'Group Variables', dataTitle: 'Group Variables',
dataPlacement: 'right', dataPlacement: 'right',
awPopOver: "<p>Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.</p>" + awPopOver: "<p>Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.</p>" +
+1 -1
View File
@@ -41,7 +41,7 @@ angular.module('HostFormDefinition', [])
editRequird: false, editRequird: false,
rows: 10, rows: 10,
"class": "modal-input-xlarge", "class": "modal-input-xlarge",
"default": "\{\}", "default": "---",
awPopOver: "<p>Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.</p>" + awPopOver: "<p>Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.</p>" +
'<p>View JSON examples at <a href="http://www.json.org" target="_blank">www.json.org</a></p>' + '<p>View JSON examples at <a href="http://www.json.org" target="_blank">www.json.org</a></p>' +
'<p>View YAML examples at <a href="http://www.ansibleworks.com/docs/YAMLSyntax.html" target="_blank">ansibleworks.com</a></p>', '<p>View YAML examples at <a href="http://www.ansibleworks.com/docs/YAMLSyntax.html" target="_blank">ansibleworks.com</a></p>',
+1 -1
View File
@@ -63,7 +63,7 @@ angular.module('InventoryFormDefinition', [])
editRequird: false, editRequird: false,
rows: 10, rows: 10,
"class": "modal-input-xlarge", "class": "modal-input-xlarge",
"default": "\{\}", "default": "---",
awPopOver: "<p>Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.</p>" + awPopOver: "<p>Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.</p>" +
'<p>View JSON examples at <a href="http://www.json.org" target="_blank">www.json.org</a></p>' + '<p>View JSON examples at <a href="http://www.json.org" target="_blank">www.json.org</a></p>' +
'<p>View YAML examples at <a href="http://www.ansibleworks.com/docs/YAMLSyntax.html" target="_blank">ansibleworks.com</a></p>', '<p>View YAML examples at <a href="http://www.ansibleworks.com/docs/YAMLSyntax.html" target="_blank">ansibleworks.com</a></p>',
+3 -3
View File
@@ -127,17 +127,17 @@ angular.module('JobTemplateFormDefinition', [])
dataTitle: 'Verbosity', dataTitle: 'Verbosity',
dataPlacement: 'left' dataPlacement: 'left'
}, },
extra_vars: { variables: {
label: 'Extra Variables', label: 'Extra Variables',
type: 'textarea', type: 'textarea',
rows: 6, rows: 6,
"class": 'span12', "class": 'span12',
addRequired: false, addRequired: false,
editRequired: false, editRequired: false,
"default": "\{\}", "default": "---",
column: 2, column: 2,
awPopOver: "<p>Pass extra command line variables to the playbook. This is the -e or --extra-vars command line parameter " + awPopOver: "<p>Pass extra command line variables to the playbook. This is the -e or --extra-vars command line parameter " +
"for ansible-playbook. Provide key=value pairs or JSON. <p><a href=\"http://www.ansibleworks.com/docs/playbooks2.html" + "for ansible-playbook. Provide key/value pairs using either YAML or JSON. <p><a href=\"http://www.ansibleworks.com/docs/playbooks2.html" +
"#passing-variables-on-the-command-line\" target=\"_blank\">Click here to view documentation and examples.</a></p>", "#passing-variables-on-the-command-line\" target=\"_blank\">Click here to view documentation and examples.</a></p>",
dataTitle: 'Extra Variables', dataTitle: 'Extra Variables',
dataPlacement: 'left' dataPlacement: 'left'
+9 -7
View File
@@ -175,7 +175,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
scope.formModalActionLabel = 'Save'; scope.formModalActionLabel = 'Save';
scope.formModalHeader = 'Create Group'; scope.formModalHeader = 'Create Group';
scope.formModalCancelShow = true; scope.formModalCancelShow = true;
scope.parseType = 'json'; scope.parseType = 'yaml';
ParseTypeChange(scope); ParseTypeChange(scope);
$('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success'); $('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
@@ -237,7 +237,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
}); });
} }
catch(err) { catch(err) {
Alert("Error", "Error parsing group variables. Expecting valid JSON. Parser returned " + err); Alert("Error", "Error parsing group variables. Parser returned: " + err);
} }
} }
@@ -270,7 +270,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
scope.formModalActionLabel = 'Save'; scope.formModalActionLabel = 'Save';
scope.formModalHeader = 'Edit Group'; scope.formModalHeader = 'Edit Group';
scope.formModalCancelShow = true; scope.formModalCancelShow = true;
scope.parseType = 'json'; scope.parseType = 'yaml';
ParseTypeChange(scope); ParseTypeChange(scope);
$('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success'); $('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
@@ -288,10 +288,10 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
Rest.get() Rest.get()
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
if ($.isEmptyObject(data)) { if ($.isEmptyObject(data)) {
scope.variables = "\{\}"; scope.variables = "---";
} }
else { else {
scope.variables = JSON.stringify(data, null, " "); scope.variables = jsyaml.safeDump(data);
} }
}) })
.error( function(data, status, headers, config) { .error( function(data, status, headers, config) {
@@ -301,8 +301,9 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
}); });
} }
else { else {
scope.variables = "\{\}"; scope.variables = "---";
} }
master.variables = scope.variables;
}); });
// Retrieve detail record and prepopulate the form // Retrieve detail record and prepopulate the form
@@ -378,7 +379,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
}); });
} }
catch(err) { catch(err) {
Alert("Error", "Error parsing group variables. Expecting valid JSON. Parser returned " + err); Alert("Error", "Error parsing group variables. Parser returned: " + err);
} }
}; };
@@ -388,6 +389,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
for (var fld in master) { for (var fld in master) {
scope[fld] = master[fld]; scope[fld] = master[fld];
} }
scope.parseType = 'yaml';
} }
} }
}]) }])
+9 -7
View File
@@ -165,7 +165,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
scope.formModalActionLabel = 'Save'; scope.formModalActionLabel = 'Save';
scope.formModalHeader = 'Create Host'; scope.formModalHeader = 'Create Host';
scope.formModalCancelShow = true; scope.formModalCancelShow = true;
scope.parseType = 'json'; scope.parseType = 'yaml';
ParseTypeChange(scope); ParseTypeChange(scope);
$('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success'); $('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
@@ -223,7 +223,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
}); });
} }
catch(err) { catch(err) {
Alert("Error", "Error parsing host variables. Parser returned " + err); Alert("Error", "Error parsing host variables. Parser returned: " + err);
} }
} }
@@ -258,7 +258,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
scope.formModalActionLabel = 'Save'; scope.formModalActionLabel = 'Save';
scope.formModalHeader = 'Edit Host'; scope.formModalHeader = 'Edit Host';
scope.formModalCancelShow = true; scope.formModalCancelShow = true;
scope.parseType = 'json'; scope.parseType = 'yaml';
ParseTypeChange(scope); ParseTypeChange(scope);
$('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success'); $('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
@@ -275,10 +275,10 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
Rest.get() Rest.get()
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
if ($.isEmptyObject(data)) { if ($.isEmptyObject(data)) {
scope.variables = "\{\}"; scope.variables = "---";
} }
else { else {
scope.variables = JSON.stringify(data, null, " "); scope.variables = jsyaml.safeDump(data);
} }
}) })
.error( function(data, status, headers, config) { .error( function(data, status, headers, config) {
@@ -288,8 +288,9 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
}); });
} }
else { else {
scope.variables = "\{\}"; scope.variables = "---";
} }
master.variables = scope.variables;
}); });
// Retrieve detail record and prepopulate the form // Retrieve detail record and prepopulate the form
@@ -363,7 +364,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
}); });
} }
catch(err) { catch(err) {
Alert("Error", "Error parsing group variables. Expecting valid JSON. Parser returned " + err); Alert("Error", "Error parsing group variables. Parser returned: " + err);
} }
}; };
@@ -373,6 +374,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
for (var fld in master) { for (var fld in master) {
scope[fld] = master[fld]; scope[fld] = master[fld];
} }
scope.parseType = 'yaml';
} }
} }
}]) }])
+7 -3
View File
@@ -278,10 +278,14 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies'])
} }
html += field.label + '</label>' + "\n"; html += field.label + '</label>' + "\n";
html += "<div class=\"controls\">\n"; html += "<div class=\"controls\">\n";
if (fld == "variables") {
html += "<div class=\"parse-selection\">Parse as: <label class=\"radio inline\"><input type=\"radio\" ng-model=\"parseType\" value=\"json\"> JSON</label>\n"; // Variable editing
html += "<label class=\"radio inline\"><input type=\"radio\" ng-model=\"parseType\" value=\"yaml\"> YAML</label></div>\n"; if (fld == "variables" || fld == "extra_vars") {
html += "<div class=\"parse-selection\">Parse as: " +
"<label class=\"radio inline\"><input type=\"radio\" ng-model=\"parseType\" value=\"yaml\"> YAML</label>\n" +
"<label class=\"radio inline\"><input type=\"radio\" ng-model=\"parseType\" value=\"json\"> JSON</label></div>\n";
} }
html += "<textarea "; html += "<textarea ";
html += (field.rows) ? this.attr(field, 'rows') : ""; html += (field.rows) ? this.attr(field, 'rows') : "";
html += "ng-model=\"" + fld + '" '; html += "ng-model=\"" + fld + '" ';