handle errors in custom widgets better
now if *.error is set, the widget silently falls back to the default.
if a user clicks to show the custom widget, the error message is shown.
subsequent custom widget toggles hide or show the error.
diff --git a/ui-modules/blueprint-composer/app/components/custom-config-widget/suggestion-dropdown.js b/ui-modules/blueprint-composer/app/components/custom-config-widget/suggestion-dropdown.js
index d58ec88..0899c0a 100644
--- a/ui-modules/blueprint-composer/app/components/custom-config-widget/suggestion-dropdown.js
+++ b/ui-modules/blueprint-composer/app/components/custom-config-widget/suggestion-dropdown.js
@@ -46,21 +46,28 @@
};
function link(scope, element, attrs, specEditor) {
- scope.specEditor = specEditor;
- scope.defined = specEditor.defined;
- scope.getSuggestions = () => {
- var result = [];
- if (scope.params['suggestion-values']) {
- scope.params['suggestion-values'].forEach( (v) => {
- if (v["value"]) {
- result.push(v);
- } else {
- result.push({value: v});
- }
- });
- return result;
+ try {
+ scope.specEditor = specEditor;
+ scope.defined = specEditor.defined;
+ scope.getSuggestions = () => {
+ var result = [];
+ if (scope.params['suggestion-values']) {
+ scope.params['suggestion-values'].forEach( (v) => {
+ if (v["value"]) {
+ result.push(v);
+ } else {
+ result.push({value: v});
+ }
+ });
+ return result;
+ }
+ };
+ } catch (e) {
+ if ($scope.params) {
+ $scope.params.error = e;
}
- };
+ throw e;
+ }
}
}
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 53be4f2..475952c 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
@@ -571,16 +571,35 @@
/** returns 'enabled' or 'disabled' if a widget is defined, or null if no special widget is defined */
specEditor.getCustomConfigWidgetMode = (item) => {
var widgetMetadata = scope.state.config.customConfigWidgetMetadata[item.name];
- if (!widgetMetadata || widgetMetadata["error"]) return null;
+ if (!widgetMetadata) return null;
+ if (widgetMetadata["error"]) {
+ return "disabled";
+ }
return widgetMetadata["enabled"] ? 'enabled' : 'disabled';
};
+ specEditor.customConfigWidgetError = (item) => {
+ var widgetMetadata = scope.state.config.customConfigWidgetMetadata[item.name];
+ if (!widgetMetadata || !widgetMetadata["error"]) return null;
+ if (widgetMetadata.manualToggleAfterError && widgetMetadata.enabled) {
+ // show the error if manually enabled
+ return widgetMetadata["error"];
+ }
+ return null;
+ };
specEditor.toggleCustomConfigWidgetMode = (item, newval) => {
var widgetMetadata = scope.state.config.customConfigWidgetMetadata[item.name];
if (!widgetMetadata) {
$log.error('Custom widget mode should not be toggled when not available: '+item.name);
return null;
}
- if (!specEditor.defined(newval)) newval = !widgetMetadata.enabled;
+ if (!specEditor.defined(newval)) {
+ if (widgetMetadata["error"] && !widgetMetadata.manualToggleAfterError) {
+ widgetMetadata.manualToggleAfterError = true;
+ newval = true;
+ } else {
+ newval = !widgetMetadata.enabled;
+ }
+ }
widgetMetadata.enabled = newval;
}
specEditor.getCustomConfigWidgetModeTitle = (item) => {
@@ -715,7 +734,7 @@
return scope.config[key];
}
} catch (ignoredError) {
- console.log("Couldn't handle entered JSON", scope.config[key], ignoredError);
+ $log.debug("Couldn't handle entered JSON", scope.config[key], ignoredError);
}
}
// otherwise pretty print it, so they get decent multiline on first load and
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 31af6f8..080c680 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
@@ -127,7 +127,7 @@
<form name="formSpecConfig" novalidate class="lightweight">
<div ng-repeat="item in (filteredItems = (model.miscData.get('config') | specEditorConfig:state.config.filter.values:model | filter:{name:state.config.search} | orderBy:+priority)) track by item.name ">
- <div class="form-group" ng-class="{'has-error': (model.issues | filter:{ref: item.name}:true).length > 0, 'used': config[item.name] !== undefined}"
+ <div class="form-group" ng-class="{'has-error': ((model.issues | filter:{ref: item.name}:true).length > 0) || (specEditor.customConfigWidgetError(item)), 'used': config[item.name] !== undefined}"
ng-switch="getConfigWidgetMode(item)"
tabindex="1"
auto-focus="state.config.focus === item.name"
@@ -332,6 +332,10 @@
</div>
<small ng-repeat="issue in model.issues | filter:{ref: item.name}:true" class="help-block issue" ng-bind-html="issue.message"></small>
+ <small ng-if="specEditor.customConfigWidgetError(item)" class="help-block issue">
+ Custom widget unavailable:
+ {{ specEditor.customConfigWidgetError(item) }}
+ </small>
</div>
</div>