generate the minimum snippet to define parameters
description + display name dropped if empty. default value more clever to differentiate between "" set in yaml and null/absent.
contraints removed if `[]`.
confirmed saved items work nicely.
diff --git a/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js b/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
index ecfefae..38687da 100644
--- a/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
+++ b/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
@@ -530,10 +530,7 @@
function addParameterDefinition(params, key) {
params.push({
"name": key,
- "description": "",
"type": "string",
- "default": "",
- "constraints": [],
});
}
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 dae9220..052bf18 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
@@ -391,6 +391,7 @@
item: $item,
newName: $item.name,
constraints: $item.constraints ? JSON.stringify($item.constraints) : '',
+ original: Object.assign({}, $item),
json: JSON.stringify($item, null, " "),
};
};
@@ -1109,11 +1110,35 @@
}
try {
- item.constraints = JSON.parse(scope.state.parameters.edit.constraints);
+ let c = scope.state.parameters.edit.constraints ? JSON.parse(scope.state.parameters.edit.constraints) : [];
+ if (Array.isArray(c)) {
+ if (c.length==0) {
+ delete item['constraints'];
+ } else {
+ item.constraints = c;
+ }
+ } else {
+ scope.state.parameters.edit.errors.push({ message: "Constraint JSON must be a list" });
+ }
} catch (e) {
// $log.warn("ERROR parsing constraints", scope.state.parameters.edit.constraints, e);
scope.state.parameters.edit.errors.push({ message: "Invalid constraint JSON" });
}
+
+ // empty values are removed
+ if (item.description == '') {
+ delete item['description'];
+ }
+ if (item.label == '') {
+ delete item['label'];
+ }
+ if (item.default == '') {
+ if (scope.state.parameters.edit.original.default!=='') {
+ // don't delete if default was explicitly set in yaml as "";
+ // this allows empty string defaults to be used (although you can't set them in the visual ui)
+ delete item['default'];
+ }
+ }
}
}
diff --git a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.template.html b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.template.html
index 1f21e08..0b28abd 100644
--- a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.template.html
+++ b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.template.html
@@ -136,7 +136,9 @@
<div class="input-group hide-when-collapsed" ng-if="state.parameters.codeModeActive[item.name]">
<span class="main-control span-for-rounded-edge">
<textarea ng-model="state.parameters.edit.json" class="form-control rounded-edge" name="{{item.name}}" id="json-{{item.name}}"
- auto-grow placeholder="(empty)" ng-focus="specEditor.recordParameterFocus(item)"
+ auto-grow
+ placeholder="(required)"
+ ng-focus="specEditor.recordParameterFocus(item)"
on-enter="specEditor.advanceOutToFormGroupInPanel"></textarea>
</span>
</div>
@@ -145,7 +147,9 @@
<div class="param-field"> <span class="param-field-label">Key</span>
<span class="param-field-value">
<textarea ng-model="state.parameters.edit.newName" class="form-control rounded-edge" id="name-{{item.name}}"
- auto-grow placeholder="(empty)" ng-focus="specEditor.recordParameterFocus(item)"
+ auto-grow
+ placeholder="(required)"
+ ng-focus="specEditor.recordParameterFocus(item)"
on-enter="specEditor.advanceOutToFormGroupInPanel">
</textarea>
</span>
@@ -153,7 +157,9 @@
<div class="param-field"> <span class="param-field-label">Type</span>
<span class="param-field-value">
<textarea ng-model="filteredParams[$index].type" class="form-control rounded-edge" id="type-{{item.name}}"
- auto-grow placeholder="(empty)" ng-focus="specEditor.recordParameterFocus(item)"
+ auto-grow
+ placeholder="(required)"
+ ng-focus="specEditor.recordParameterFocus(item)"
on-enter="specEditor.advanceOutToFormGroupInPanel">
</textarea>
</span>
@@ -161,7 +167,9 @@
<div class="param-field"> <span class="param-field-label">Default value</span>
<span class="param-field-value">
<textarea ng-model="filteredParams[$index].default" class="form-control rounded-edge" id="default-{{item.name}}"
- auto-grow placeholder="(empty)" ng-focus="specEditor.recordParameterFocus(item)"
+ auto-grow
+ placeholder="{{ state.parameters.edit.original.default == '' ? '(empty)' : '(not set)' }}"
+ ng-focus="specEditor.recordParameterFocus(item)"
on-enter="specEditor.advanceOutToFormGroupInPanel">
</textarea>
</span>
@@ -169,7 +177,9 @@
<div class="param-field"> <span class="param-field-label">Display name</span>
<span class="param-field-value">
<textarea ng-model="filteredParams[$index].label" class="form-control rounded-edge" id="label-{{item.name}}"
- auto-grow placeholder="(empty)" ng-focus="specEditor.recordParameterFocus(item)"
+ auto-grow
+ placeholder="(not set)"
+ ng-focus="specEditor.recordParameterFocus(item)"
on-enter="specEditor.advanceOutToFormGroupInPanel">
</textarea>
</span>
@@ -177,20 +187,24 @@
<div class="param-field"> <span class="param-field-label">Description</span>
<span class="param-field-value">
<textarea ng-model="filteredParams[$index].description" class="form-control rounded-edge" id="description-{{item.name}}"
- auto-grow placeholder="(empty)" ng-focus="specEditor.recordParameterFocus(item)"
+ auto-grow
+ placeholder="(not set)"
+ ng-focus="specEditor.recordParameterFocus(item)"
on-enter="specEditor.advanceOutToFormGroupInPanel">
</textarea>
</span>
</div>
<div class="param-field"> <span class="param-field-label">Constraints
<i class="fa fa-fw fa-info-circle" popover-trigger="'mouseenter'"
- uib-popover="Constraints such as required or forbiddenUnless(otherKey), expressed as a JSON list (wrapped in brackets)"
+ uib-popover="Constraints such as "required" or "forbiddenUnless(otherKey)", expressed as a JSON list (wrapped in square brackets)"
x-popover-class="spec-editor-popover"
popover-placement="top-left" popover-append-to-body="true"></i>
</span>
<span class="param-field-value">
<textarea ng-model="state.parameters.edit.constraints" class="form-control rounded-edge code" id="constraints-{{item.name}}"
- auto-grow placeholder="(empty)" ng-focus="specEditor.recordParameterFocus(item)"
+ auto-grow
+ placeholder="(none)"
+ ng-focus="specEditor.recordParameterFocus(item)"
on-enter="specEditor.advanceOutToFormGroupInPanel">
</textarea>
</span>