mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 02:47:36 -02:30
Merge pull request #4531 from jaredevantabor/host-extra-vars
fix for host.edit extra vars being non-prettified
This commit is contained in:
@@ -19,14 +19,46 @@
|
|||||||
|
|
||||||
$scope.parseType = 'yaml';
|
$scope.parseType = 'yaml';
|
||||||
$scope.host = host;
|
$scope.host = host;
|
||||||
$scope.variables = host.variables === '' ? '---' : host.variables;
|
$scope.variables = getVars(host.variables);
|
||||||
$scope.name = host.name;
|
$scope.name = host.name;
|
||||||
$scope.description = host.description;
|
$scope.description = host.description;
|
||||||
|
|
||||||
ParseTypeChange({
|
ParseTypeChange({
|
||||||
scope: $scope,
|
scope: $scope,
|
||||||
field_id: 'host_variables',
|
field_id: 'host_variables',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adding this function b/c sometimes extra vars are returned to the
|
||||||
|
// UI as a string (ex: "foo: bar"), and other times as a
|
||||||
|
// json-object-string (ex: "{"foo": "bar"}"). CodeMirror wouldn't know
|
||||||
|
// how to prettify the latter. The latter occurs when host vars were
|
||||||
|
// system generated and not user-input (such as adding a cloud host);
|
||||||
|
function getVars(str){
|
||||||
|
|
||||||
|
// Quick function to test if the host vars are a json-object-string,
|
||||||
|
// by testing if they can be converted to a JSON object w/o error.
|
||||||
|
function IsJsonString(str) {
|
||||||
|
try {
|
||||||
|
JSON.parse(str);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(str === ''){
|
||||||
|
return '---';
|
||||||
|
}
|
||||||
|
else if(IsJsonString(str)){
|
||||||
|
str = JSON.parse(str);
|
||||||
|
return jsyaml.safeDump(str);
|
||||||
|
}
|
||||||
|
else if(!IsJsonString(str)){
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$scope.formCancel = function(){
|
$scope.formCancel = function(){
|
||||||
$state.go('^');
|
$state.go('^');
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user