Repository: brooklyn-ui Updated Branches: refs/heads/master a9fcd5276 -> 13c56f078
fix json editor state Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/8a82585b Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/8a82585b Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/8a82585b Branch: refs/heads/master Commit: 8a82585bcf4a402f6b935aca351880dd65819ead Parents: 4093d1f Author: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Authored: Tue Nov 20 13:35:07 2018 +0000 Committer: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Committed: Tue Nov 20 13:35:07 2018 +0000 ---------------------------------------------------------------------- .../spec-editor/spec-editor.directive.js | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/8a82585b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js ---------------------------------------------------------------------- diff --git a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js index 9c18129..ecfa249 100644 --- a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js +++ b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js @@ -699,7 +699,24 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani // errors don't get stringified because model value was not parsed return value; } - return JSON.stringify(value); + // if current local value gives same result then don't change it + // (don't interrupt user's flow, and respect their spacing, at least until + // they click away; ultimately we would like access to the parse tree, + // so we could take the text as entered exactly (maybe stripping initial whitespace), + // also supporting yaml and comments, but that is a bigger task!) + if (scope.config && typeof scope.config[key] === 'string') { + try { + if (JSON.stringify(JSON.parse(scope.config[key]))===JSON.stringify(value)) { + return scope.config[key]; + } + } catch (ignoredError) { + console.log("Couldn't handle entered JSON", scope.config[key], ignoredError); + } + } + // otherwise pretty print it, so they get decent multiline on first load and + // if they click off the entity then back on to the entity and this field + // (we'd like to respect what they actually typed but that needs the parse tree, as above) + return JSON.stringify(value, null, " "); } // else treat as value, with array/map special @@ -737,8 +754,8 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani scope.state.config.codeModeActive[key] = true; // and the widget mode updated to be 'manual' scope.getConfigWidgetMode(definition, value); - - return JSON.stringify(value); + // and rerun this method so we get it prettified if appropriate + return getLocalConfigValueFromModelValue(key, value); } // if boolean, return as primitive type