use code-mirror directive for host facts

This commit is contained in:
Keith Grant
2019-03-19 15:07:10 -04:00
parent 5583af2a58
commit b6d8f9c6f6
3 changed files with 20 additions and 17 deletions

View File

@@ -77,6 +77,14 @@ function atCodeMirrorController (
return true; return true;
} }
if (typeof str !== 'string') {
const yamlStr = jsyaml.safeDump(str);
// jsyaml.safeDump doesn't process an empty object correctly
if (yamlStr === '{}\n') {
return '---';
}
return yamlStr;
}
if (str === '' || str === '{}') { if (str === '' || str === '{}') {
return '---'; return '---';
} else if (IsJsonString(str)) { } else if (IsJsonString(str)) {

View File

@@ -4,25 +4,17 @@
* All Rights Reserved * All Rights Reserved
*************************************************/ *************************************************/
function AnsibleFacts($scope, Facts, ParseTypeChange, ParseVariableString) { function AnsibleFacts($scope, Facts) {
function init() { function init() {
$scope.facts = ParseVariableString(Facts); $scope.facts = Facts;
let rows = (_.isEmpty(Facts)) ? 6 : 20; let rows = (_.isEmpty(Facts)) ? 6 : 20;
$("#host_facts").attr("rows", rows); $("#host_facts").attr("rows", rows);
$scope.parseType = 'yaml'; $scope.parseType = 'yaml';
ParseTypeChange({
scope: $scope,
variable: 'facts',
parse_variable: 'parseType',
field_id: 'host_facts',
readOnly: true
});
} }
init(); init();
} }
export default ['$scope', 'Facts', 'ParseTypeChange', 'ParseVariableString', AnsibleFacts export default ['$scope', 'Facts', AnsibleFacts];
];

View File

@@ -1,10 +1,13 @@
<form class="Form ng-pristine ng-valid ng-valid-required" name="host_form" id="host_form" autocomplete="off" novalidate=""> <form class="Form ng-pristine ng-valid ng-valid-required" name="host_form" id="host_form" autocomplete="off" novalidate="">
<div class="form-group Form-formGroup Form-formGroup--fullWidth"> <div class="form-group Form-formGroup Form-formGroup--fullWidth">
<label class="Form-inputLabelContainer " for="facts"> <at-code-mirror
<span class="Form-inputLabel" translate>FACTS</span> id="host_facts"
</label> name="facts"
<div> class="Form-textArea Form-formGroup--fullWidth"
<textarea rows="6" ng-model="facts" name="facts" class="form-control Form-textArea Form-formGroup--fullWidth" id="host_facts"></textarea> label="facts"
</div> variables="facts"
tooltip=""
disabled="true"
></at-code-mirror>
</div> </div>
</form> </form>