tbouron commented on a change in pull request #129: UI for defining parameters
URL: https://github.com/apache/brooklyn-ui/pull/129#discussion_r270353437
##########
File path:
ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js
##########
@@ -548,24 +638,65 @@ export function specEditorDirective($rootScope,
$templateCache, $injector, $sani
value = JSON.stringify(value);
}
}
- if (value!=null) {
+ if (value != null) {
scope.config[item.name] = value;
}
}
scope.state.config.codeModeActive[item.name] = !oldMode;
- if (value!=null) {
+ if (value != null) {
// local config changed, make sure model is updated too
setModelFromLocalConfig();
}
};
scope.getJsonModeTitle = (itemName) => {
if (!scope.state.config.codeModeActive[itemName]) {
- return "Treat this value as a JSON-encoded object
["+itemName+"]";
+ return "Treat this value as a JSON-encoded object [" +
itemName + "]";
}
if (scope.state.config.codeModeForced[itemName]) {
- return "This data is a complex object and can only be entered
as JSON ["+itemName+"]";
+ return "This data is a complex object and can only be entered
as JSON [" + itemName + "]";
+ } else {
+ return "Edit in simple mode, unwrapping JSON if possible [" +
itemName + "]";
+ }
+ };
+ scope.parameterCodeModeClick = (item) => {
+ let oldMode = !!(item &&
scope.state.parameters.codeModeActive[item.name]);
+ let value = null;
+ if (oldMode) {
+ // leaving code mode
+ value = scope.state.parameters.edit.json;
+ try {
+ value = JSON.parse(value);
+ let i = scope.parameters.findIndex(p => p.name ===
item.name);
+ scope.parameters[i] = value;
+ } catch (notJson) {
+ // if not parseable then leave alone
+ value = null;
+ }
} else {
- return "Edit in simple mode, unwrapping JSON if possible
["+itemName+"]";
+ // entering code mode
+ // leave code mode for other parameter if set
+ if (scope.state.parameters.edit.newName &&
scope.state.parameters.edit.newName!=item.name) {
+
scope.parameterCodeModeClick(getParameter(scope.state.parameters.edit.newName));
+ }
+ // convert local parameter from json to non-json or vice-versa
+ value = item;
+ if (value != null) {
Review comment:
```suggestion
if (value !== null) {
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services