in ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js [1096:1156]
function setModelFromLocalConfig() {
let localConfig = scope.config;
let result = {};
for (let keyRef in localConfig) {
if (angular.isUndefined(localConfig[keyRef]) || localConfig[keyRef] === null || localConfig[keyRef].length < 1) {
// TODO if we wanted to support explicit empty strings or null, this would be the place to tweak it,
// plus a few other guards on null, and forcing code mode.
continue;
}
if (localConfig[keyRef].hasOwnProperty(REPLACED_DSL_ENTITYSPEC)) {
result[keyRef] = {};
result[keyRef][DSL_ENTITY_SPEC] = localConfig[keyRef][REPLACED_DSL_ENTITYSPEC];
continue;
}
let definition = scope.model.miscData.get('config').find(config => config.name === keyRef);
if (!definition) {
definition = {};
scope.getConfigWidgetMode(definition, localConfig[keyRef])
}
let v = localConfig[keyRef];
// if JSON mode then parse
scope.state.config.codeModeError[keyRef] = null;
if (scope.state.config.codeModeActive && scope.state.config.codeModeActive[keyRef]) {
// first try a yaml parse
try {
result[keyRef] = parseYamlOrJson(v);
continue;
} catch (ex) {
scope.state.config.codeModeError[keyRef] = "Invalid JSON";
result[keyRef] = localConfig[keyRef];
continue;
}
}
// else return as is, or introspect for array/map
if (definition.widgetMode === 'array') {
if (Array.isArray(v)) {
result[keyRef] = v.map(getModelValueFromString);
continue;
}
}
if (definition.widgetMode === 'map') {
if (typeof v === "object") {
result[keyRef] = {};
for (let keyObject in v) {
result[keyRef][keyObject] = getModelValueFromString(v[keyObject]);
}
continue;
}
}
result[keyRef] = getModelValueFromString(v);
}
scope.model.setConfigFromJson(result);
}