1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00

Fixed inventory group source drop-down so that selecting 'Choose a source' behaves the same as choosing 'Manual'. Fixed AC-989.

This commit is contained in:
Chris Houseknecht 2014-01-28 10:58:50 -05:00 committed by Matthew Jones
parent 1f6fe73a4a
commit be66062123
3 changed files with 105 additions and 107 deletions

View File

@ -67,12 +67,12 @@ angular.module('GroupFormDefinition', [])
ngChange: 'sourceChange()', ngChange: 'sourceChange()',
addRequired: false, addRequired: false,
editRequired: false, editRequired: false,
'default': { label: 'Manual', value: '' }, //'default': { label: 'Manual', value: '' },
tab: 'source' tab: 'source'
}, },
source_path: { source_path: {
label: 'Script Path', label: 'Script Path',
ngShow: "source.value == 'file'", ngShow: "source && source.value == 'file'",
type: 'text', type: 'text',
awRequiredWhen: {variable: "sourcePathRequired", init: "false" }, awRequiredWhen: {variable: "sourcePathRequired", init: "false" },
tab: 'source' tab: 'source'
@ -80,7 +80,7 @@ angular.module('GroupFormDefinition', [])
credential: { credential: {
label: 'Cloud Credential', label: 'Cloud Credential',
type: 'lookup', type: 'lookup',
ngShow: "source.value !== ''", ngShow: "source && source.value !== ''",
sourceModel: 'credential', sourceModel: 'credential',
sourceField: 'name', sourceField: 'name',
ngClick: 'lookUpCredential()', ngClick: 'lookUpCredential()',
@ -91,7 +91,7 @@ angular.module('GroupFormDefinition', [])
source_regions: { source_regions: {
label: 'Regions', label: 'Regions',
type: 'text', type: 'text',
ngShow: "source.value == 'rax' || source.value == 'ec2'", ngShow: "source && (source.value == 'rax' || source.value == 'ec2')",
addRequired: false, addRequired: false,
editRequired: false, editRequired: false,
awMultiselect: 'source_region_choices', awMultiselect: 'source_region_choices',
@ -105,7 +105,7 @@ angular.module('GroupFormDefinition', [])
}, },
source_vars: { source_vars: {
label: 'Source Variables', label: 'Source Variables',
ngShow: "source.value == 'file' || source.value == 'ec2'", ngShow: "source && (source.value == 'file' || source.value == 'ec2')",
type: 'textarea', type: 'textarea',
addRequired: false, addRequired: false,
editRequird: false, editRequird: false,
@ -145,7 +145,7 @@ angular.module('GroupFormDefinition', [])
checkbox_group: { checkbox_group: {
label: 'Update Options', label: 'Update Options',
type: 'checkbox_group', type: 'checkbox_group',
ngShow: "source.value !== '' && source.value !== null", ngShow: "source && (source.value !== '' && source.value !== null)",
tab: 'source', tab: 'source',
fields: [ fields: [

View File

@ -27,9 +27,13 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
Rest.options() Rest.options()
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
var choices = data.actions.GET.source.choices var choices = data.actions.GET.source.choices
console.log(choices);
for (var i=0; i < choices.length; i++) { for (var i=0; i < choices.length; i++) {
if (choices[i][0] !== 'file') { if (choices[i][0] !== 'file') {
scope[variable].push({ label: (choices[i][0] == "") ? 'Manual' : choices[i][1] , value: choices[i][0] }); scope[variable].push({
label: ( (choices[i][0] == '') ? 'Manual' : choices[i][1] ),
value: choices[i][0]
});
} }
} }
}) })
@ -212,42 +216,46 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
} }
}]) }])
.factory('SourceChange', [ 'GetBasePath', 'CredentialList', 'LookUpInit', .factory('SourceChange', [ 'GetBasePath', 'CredentialList', 'LookUpInit', 'Empty',
function(GetBasePath, CredentialList, LookUpInit){ function(GetBasePath, CredentialList, LookUpInit, Empty){
return function(params) { return function(params) {
var scope = params.scope; var scope = params.scope;
var form = params.form; var form = params.form;
if (scope['source'].value == 'file') { if (!Empty(scope['source'])) {
scope.sourcePathRequired = true; if (scope['source'].value == 'file') {
scope.sourcePathRequired = true;
}
else {
scope.sourcePathRequired = false;
// reset fields
scope.source_path = '';
scope[form.name + '_form']['source_path'].$setValidity('required',true);
}
if (scope['source'].value == 'rax') {
scope['source_region_choices'] = scope['rax_regions'];
//$('#s2id_group_source_regions').select2('data', []);
$('#s2id_group_source_regions').select2('data', [{ id: 'all', text: 'All' }]);
}
else if (scope['source'].value == 'ec2') {
scope['source_region_choices'] = scope['ec2_regions'];
//$('#s2id_group_source_regions').select2('data', []);
$('#s2id_group_source_regions').select2('data', [{ id: 'all', text: 'All' }]);
}
if (scope['source'].value == 'rax' || scope['source'].value == 'ec2') {
var kind = (scope.source.value == 'rax') ? 'rax' : 'aws';
var url = GetBasePath('credentials') + '?cloud=true&kind=' + kind;
LookUpInit({
url: url,
scope: scope,
form: form,
list: CredentialList,
field: 'credential'
});
}
} }
else {
scope.sourcePathRequired = false;
// reset fields
scope.source_path = '';
scope[form.name + '_form']['source_path'].$setValidity('required',true);
}
if (scope['source'].value == 'rax') {
scope['source_region_choices'] = scope['rax_regions'];
//$('#s2id_group_source_regions').select2('data', []);
$('#s2id_group_source_regions').select2('data', [{ id: 'all', text: 'All' }]);
}
else if (scope['source'].value == 'ec2') {
scope['source_region_choices'] = scope['ec2_regions'];
//$('#s2id_group_source_regions').select2('data', []);
$('#s2id_group_source_regions').select2('data', [{ id: 'all', text: 'All' }]);
}
else
var kind = (scope.source.value == 'rax') ? 'rax' : 'aws';
var url = GetBasePath('credentials') + '?cloud=true&kind=' + kind;
LookUpInit({
url: url,
scope: scope,
form: form,
list: CredentialList,
field: 'credential'
});
} }
}]) }])
@ -862,75 +870,65 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
var parseError = false; var parseError = false;
var saveError = false; var saveError = false;
// Update the selector tree with new group name, descr var data = { group: group_id,
//SetNodeName({ scope: scope['selectedNode'], group_id: group_id, source: ( (source && source.value) ? source.value : '' ),
// name: scope.name, description: scope.description }); source_path: scope['source_path'],
credential: scope['credential'],
overwrite: scope['overwrite'],
overwrite_vars: scope['overwrite_vars'],
update_on_launch: scope['update_on_launch']
//update_interval: scope['update_interval'].value
};
if (scope.source.value !== null && scope.source.value !== '') { // Create a string out of selected list of regions
var data = { group: group_id, var regions = $('#s2id_group_source_regions').select2("data");
source: scope['source'].value, var r = [];
source_path: scope['source_path'], for (var i=0; i < regions.length; i++) {
credential: scope['credential'], r.push(regions[i].id);
overwrite: scope['overwrite'], }
overwrite_vars: scope['overwrite_vars'], data['source_regions'] = r.join();
update_on_launch: scope['update_on_launch']
//update_interval: scope['update_interval'].value
};
// Create a string out of selected list of regions if (scope['source'].value == 'ec2') {
var regions = $('#s2id_group_source_regions').select2("data"); // for ec2, validate variable data
var r = []; try {
for (var i=0; i < regions.length; i++) { if (scope.envParseType == 'json') {
r.push(regions[i].id); var json_data = JSON.parse(scope.source_vars); //make sure JSON parses
}
else {
var json_data = jsyaml.load(scope.source_vars); //parse yaml
}
// Make sure our JSON is actually an object
if (typeof json_data !== 'object') {
throw "failed to return an object!";
}
// Send JSON as a string
if ($.isEmptyObject(json_data)) {
data.source_vars = "";
}
else {
data.source_vars = JSON.stringify(json_data, undefined, '\t');
}
} }
data['source_regions'] = r.join(); catch(err) {
parseError = true;
if (scope['source'].value == 'ec2') { scope.$emit('SaveComplete', true);
// for ec2, validate variable data Alert("Error", "Error parsing extra variables. Parser returned: " + err);
try {
if (scope.envParseType == 'json') {
var json_data = JSON.parse(scope.source_vars); //make sure JSON parses
}
else {
var json_data = jsyaml.load(scope.source_vars); //parse yaml
}
// Make sure our JSON is actually an object
if (typeof json_data !== 'object') {
throw "failed to return an object!";
}
// Send JSON as a string
if ($.isEmptyObject(json_data)) {
data.source_vars = "";
}
else {
data.source_vars = JSON.stringify(json_data, undefined, '\t');
}
}
catch(err) {
parseError = true;
scope.$emit('SaveComplete', true);
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
}
}
if (!parseError) {
Rest.setUrl(scope.source_url)
Rest.put(data)
.success( function(data, status, headers, config) {
scope.$emit('SaveComplete', false);
})
.error( function(data, status, headers, config) {
scope.$emit('SaveComplete', true);
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update group inventory source. PUT status: ' + status });
});
} }
} }
else {
// No source value if (!parseError) {
scope.$emit('SaveComplete', false); Rest.setUrl(scope.source_url)
Rest.put(data)
.success( function(data, status, headers, config) {
scope.$emit('SaveComplete', false);
})
.error( function(data, status, headers, config) {
scope.$emit('SaveComplete', true);
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update group inventory source. PUT status: ' + status });
});
} }
}); });

View File

@ -735,7 +735,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
field.awRequiredWhen.variable + "\" " : ""; field.awRequiredWhen.variable + "\" " : "";
html += ">\n"; html += ">\n";
html += "<option value=\"\">"; html += "<option value=\"\">";
html += (field.defaultOption) ? field.defaultOption : "Choose " + field.label; html += (field.defaultOption) ? field.defaultOption : "Choose a " + field.label.toLowerCase();
html += "</option>\n"; html += "</option>\n";
html += "</select>\n"; html += "</select>\n";
// Add error messages // Add error messages
@ -1462,8 +1462,8 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
html += "<tr ng-repeat=\"" + form.related[itm].iterator + " in " + itm + "\" >\n"; html += "<tr ng-repeat=\"" + form.related[itm].iterator + " in " + itm + "\" >\n";
if (form.related[itm].index == undefined || form.related[itm].index !== false) { if (form.related[itm].index == undefined || form.related[itm].index !== false) {
html += "<td>{{ $index + (" + form.related[itm].iterator + "Page * " + html += "<td>{{ $index + ((" + form.related[itm].iterator + "_page - 1) * " +
form.related[itm].iterator + "PageSize) + 1 }}.</td>\n"; form.related[itm].iterator + "_page_size) + 1 }}.</td>\n";
} }
var cnt = 1; var cnt = 1;
var rfield; var rfield;