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

View File

@ -27,9 +27,13 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
Rest.options()
.success( function(data, status, headers, config) {
var choices = data.actions.GET.source.choices
console.log(choices);
for (var i=0; i < choices.length; i++) {
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',
function(GetBasePath, CredentialList, LookUpInit){
.factory('SourceChange', [ 'GetBasePath', 'CredentialList', 'LookUpInit', 'Empty',
function(GetBasePath, CredentialList, LookUpInit, Empty){
return function(params) {
var scope = params.scope;
var form = params.form;
if (scope['source'].value == 'file') {
scope.sourcePathRequired = true;
var form = params.form;
if (!Empty(scope['source'])) {
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 saveError = false;
// Update the selector tree with new group name, descr
//SetNodeName({ scope: scope['selectedNode'], group_id: group_id,
// name: scope.name, description: scope.description });
var data = { group: group_id,
source: ( (source && source.value) ? source.value : '' ),
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 !== '') {
var data = { group: group_id,
source: scope['source'].value,
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
};
// Create a string out of selected list of regions
var regions = $('#s2id_group_source_regions').select2("data");
var r = [];
for (var i=0; i < regions.length; i++) {
r.push(regions[i].id);
// Create a string out of selected list of regions
var regions = $('#s2id_group_source_regions').select2("data");
var r = [];
for (var i=0; i < regions.length; i++) {
r.push(regions[i].id);
}
data['source_regions'] = r.join();
if (scope['source'].value == 'ec2') {
// for ec2, validate variable data
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');
}
}
data['source_regions'] = r.join();
if (scope['source'].value == 'ec2') {
// for ec2, validate variable data
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 });
});
catch(err) {
parseError = true;
scope.$emit('SaveComplete', true);
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
}
}
else {
// No source value
scope.$emit('SaveComplete', false);
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 });
});
}
});

View File

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