mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 00:08:44 -03:30
fix non-prettified extra vars on the Hosts Edit UI
this seems to be a duplicate of #3333, only in a different location. Resolves #4700
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
$scope.host = host.data;
|
$scope.host = host.data;
|
||||||
$scope.name = host.data.name;
|
$scope.name = host.data.name;
|
||||||
$scope.description = host.data.description;
|
$scope.description = host.data.description;
|
||||||
$scope.variables = host.data.variables === '' ? '---' : host.data.variables;
|
$scope.variables = getVars(host.data.variables);
|
||||||
ParseTypeChange({
|
ParseTypeChange({
|
||||||
scope: $scope,
|
scope: $scope,
|
||||||
field_id: 'host_variables',
|
field_id: 'host_variables',
|
||||||
@@ -42,5 +42,35 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}];
|
}];
|
||||||
|
|||||||
Reference in New Issue
Block a user