mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 18:40:01 -03:30
Change default pod spec in OPTIONS request to json
This commit is contained in:
parent
ad1e7c46c3
commit
59413e0a8f
@ -2,7 +2,6 @@
|
||||
# All Rights Reserved.
|
||||
|
||||
from collections import OrderedDict
|
||||
import yaml
|
||||
|
||||
# Django
|
||||
from django.core.exceptions import PermissionDenied
|
||||
@ -203,7 +202,7 @@ class Metadata(metadata.SimpleMetadata):
|
||||
continue
|
||||
|
||||
if field == "pod_spec_override":
|
||||
meta['default'] = yaml.dump(PodManager().pod_definition)
|
||||
meta['default'] = PodManager().pod_definition
|
||||
|
||||
# Add type choices if available from the serializer.
|
||||
if field == 'type' and hasattr(serializer, 'get_type_choices'):
|
||||
|
||||
@ -57,9 +57,42 @@ function EditContainerGroupController($rootScope, $scope, $state, models, string
|
||||
toggleLabel: strings.get('container.POD_SPEC_TOGGLE')
|
||||
};
|
||||
|
||||
const podSpecValue = EditContainerGroupDataset.data.pod_spec_override.trim();
|
||||
const defaultPodSpecValue = instanceGroup.model.OPTIONS.actions.PUT.pod_spec_override.default.trim();
|
||||
if (podSpecValue && podSpecValue !== defaultPodSpecValue) {
|
||||
function sanitizeVars (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 (varStr) {
|
||||
try {
|
||||
JSON.parse(varStr);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (typeof str === 'undefined') {
|
||||
return '---';
|
||||
}
|
||||
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 === '{}') {
|
||||
return '---';
|
||||
} else if (IsJsonString(str)) {
|
||||
str = JSON.parse(str);
|
||||
return jsyaml.safeDump(str);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
const podSpecValue = sanitizeVars(EditContainerGroupDataset.data.pod_spec_override);
|
||||
const defaultPodSpecValue = sanitizeVars(instanceGroup.model.OPTIONS.actions.PUT.pod_spec_override.default);
|
||||
|
||||
if (podSpecValue && podSpecValue.trim() !== defaultPodSpecValue.trim()) {
|
||||
vm.form.extraVars.isOpen = true;
|
||||
} else {
|
||||
vm.form.extraVars.isOpen = false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user