You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2018/08/20 09:39:23 UTC
[03/12] brooklyn-ui git commit: collect config-widget metadata from
ui-composer-hints tags on registered types
collect config-widget metadata from ui-composer-hints tags on registered types
all that's left is to show the suggested dropdown values
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/19de59de
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/19de59de
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/19de59de
Branch: refs/heads/master
Commit: 19de59de10894f8a3720c989d0e3be7fd68b260a
Parents: 29ba70e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Aug 7 01:18:01 2018 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Aug 7 01:18:01 2018 +0100
----------------------------------------------------------------------
.../suggestion-dropdown.html | 6 +-
.../custom-config-widget/suggestion-dropdown.js | 4 +-
.../providers/blueprint-service.provider.js | 16 +++++
.../spec-editor/spec-editor.directive.js | 63 ++++++++++++--------
.../app/components/spec-editor/spec-editor.less | 2 +-
.../spec-editor/spec-editor.template.html | 6 +-
6 files changed, 63 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/19de59de/ui-modules/blueprint-composer/app/components/custom-config-widget/suggestion-dropdown.html
----------------------------------------------------------------------
diff --git a/ui-modules/blueprint-composer/app/components/custom-config-widget/suggestion-dropdown.html b/ui-modules/blueprint-composer/app/components/custom-config-widget/suggestion-dropdown.html
index c511dfe..4ca05cc 100644
--- a/ui-modules/blueprint-composer/app/components/custom-config-widget/suggestion-dropdown.html
+++ b/ui-modules/blueprint-composer/app/components/custom-config-widget/suggestion-dropdown.html
@@ -30,17 +30,17 @@
<span class="label-rhs-buttons">
<span class="spacer"> </span>
<span class="custom-widget-enable-button custom-widget-active">
- <i class="fa fa-fw fa-sun-o" ng-click="toggleCustomConfigWidgetMode(item, 'disabled')" aria-hidden="true" title="{{getCustomConfigWidgetModeTitle(item)}} [{{item.name}}]"></i>
+ <i class="fa fa-fw fa-sun-o" ng-click="toggleCustomConfigWidgetMode(item, false)" aria-hidden="true" title="{{getCustomConfigWidgetModeTitle(item)}} [{{item.name}}]"></i>
<span class="sr-only">{{getCustomConfigWidgetModeTitle(item)}} [{{item.name}}]</span>
</span>
</span>
<div class="control-value" ng-class="{ 'inline-control': item.widgetMode==='boolean', 'unset': !defined(config[item.name]), 'has-default': defined(item.defaultValue) && item.defaultValue!=null }">
<div class="hide-when-collapsed">
- <a ng-click="test()">Extra information</a>
+ {{ params['label-expanded'] || "" }}
</div>
<div>
- <span class="hide-when-expanded">Custom widget: </span>
+ <span class="hide-when-expanded">{{ params['label-collapsed'] || "" }}</span>
{{ config[item.name] }}
</div>
</div>
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/19de59de/ui-modules/blueprint-composer/app/components/custom-config-widget/suggestion-dropdown.js
----------------------------------------------------------------------
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 d36c801..7c23092 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
@@ -31,7 +31,8 @@ export function suggestionDropdownDirective($rootScope) {
return {
restrict: 'E',
scope: {
- item: '='
+ item: '=',
+ params: '=',
},
template: template,
link: link,
@@ -39,6 +40,7 @@ export function suggestionDropdownDirective($rootScope) {
function link(scope) {
scope.$parent.copyScopeForCustomConfigWidget(scope);
+ console.log("params for widget for "+scope.item.name, scope.params);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/19de59de/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
----------------------------------------------------------------------
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 0e4b360..9f2491a 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
@@ -499,10 +499,26 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
}));
entity.miscData.set('sensors', data.sensors || []);
entity.miscData.set('traits', data.supertypes || []);
+ entity.miscData.set('tags', data.tags || []);
+ var uiHints = {};
+ data.tags.forEach( (t) => {
+ mergeAppendingLists(uiHints, t['ui-composer-hints']);
+ });
+ entity.miscData.set('ui-composer-hints', uiHints);
entity.miscData.set('virtual', data.virtual || null);
addUnlistedConfigKeysDefinitions(entity);
return entity;
}
+ function mergeAppendingLists(dst, src) {
+ for (let p in src) {
+ if (Array.isArray(dst[p]) || Array.isArray(src[p])) {
+ dst[p] = [].concat(dst[p] || [], src[p]);
+ } else {
+ dst[p] = Object.assign({}, dst[p], src[p]);
+ }
+ }
+ return dst;
+ }
function populateEntityFromApiError(entity) {
entity.clearIssues({group: 'type'});
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/19de59de/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 a0eeba8..17ab03a 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
@@ -106,9 +106,9 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani
codeModeActive: {},
codeModeForced: {},
codeModeError: {},
- customWidget: {
- "defaultDisplayName": { mode: "full", widget: "known-widget-missing" },
- "download.url": { mode: "full", widget: "suggestion-dropdown" },
+ customConfigWidgetMetadata: {
+ "defaultDisplayName": { enabled: true, widget: "known-widget-missing" },
+ "download.url": { enabled: true, widget: "suggestion-dropdown" },
},
},
location: {
@@ -148,6 +148,8 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani
scope.state.config.add.list = getAddListConfig();
});
+ loadCustomConfigWidgetMetadata(scope);
+
scope.config = {};
scope.$watch('model', (newVal, oldVal)=> {
if (newVal && !newVal.equals(oldVal)) {
@@ -528,36 +530,29 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani
} else {
return "Edit in simple mode, unwrapping JSON if possible ["+itemName+"]";
}
- }
+ };
+ /** returns 'enabled' or 'disabled' if a widget is defined, or null if no special widget is defined */
scope.getCustomConfigWidgetMode = (item) => {
- var mode = (scope.state.config.customWidget[item.name] || {})["mode"] || null;
- if (mode) {
- if ((scope.state.config.customWidget[item.name] || {})["error"]) return null;
- }
- return mode;
- } ;
+ var widgetMetadata = scope.state.config.customConfigWidgetMetadata[item.name];
+ if (!widgetMetadata || widgetMetadata["error"]) return null;
+ return widgetMetadata["enabled"] ? 'enabled' : 'disabled';
+ };
scope.toggleCustomConfigWidgetMode = (item, newval) => {
- if (!scope.state.config.customWidget[item.name]) {
+ 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 (newval) scope.state.config.customWidget[item.name].mode = newval;
- else {
- if (scope.state.config.customWidget[item.name].mode === "disabled") {
- // TODO not always full
- scope.state.config.customWidget[item.name].mode = "full"
- } else {
- scope.state.config.customWidget[item.name].mode = "full"
- }
- }
+ if (!scope.defined(newval)) newval = !widgetMetadata.enabled;
+ widgetMetadata.enabled = newval;
}
scope.getCustomConfigWidgetModeTitle = (item) => {
- if (!scope.state.config.customWidget[item.name]) {
+ var widgetMetadata = scope.state.config.customConfigWidgetMetadata[item.name];
+ if (!widgetMetadata) {
// shouldn't be visible
return "(custom widget not available)";
}
- if (scope.state.config.customWidget[item.name].mode === "disabled") return "Enable custom widget";
- else return "Disable custom widget";
+ return widgetMetadata.enabled ? "Use standard widget" : "Use custom widget";
};
scope.copyScopeForCustomConfigWidget = (descendantScope) => {
descendantScope.toggleCustomConfigWidgetMode = scope.toggleCustomConfigWidgetMode;
@@ -568,15 +563,16 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani
descendantScope.copyScopeForCustomConfigWidget = scope.copyScopeForCustomConfigWidget;
};
scope.getCustomConfigWidgetTemplate = (item) => {
- var widgetName = $sanitize(scope.state.config.customWidget[item.name].widget);
+ var widgetMetadata = scope.state.config.customConfigWidgetMetadata[item.name];
+ var widgetName = $sanitize(widgetMetadata.widget || '--no-widget--');
var templateName = 'custom-config-widget-'+widgetName;
if (!$templateCache.get(templateName)) {
var widgetDirective = widgetName.replace(/(-[a-z])/g, function($1){return $1[1].toUpperCase();})+'Directive';
if ($injector.has(widgetDirective)) {
- $templateCache.put(templateName, '<'+widgetName+' item="item">foo</'+widgetName+'>');
+ $templateCache.put(templateName, '<'+widgetName+' item="item" params="state.config.customConfigWidgetMetadata[item.name]"/>');
} else {
$log.error('Missing directive '+widgetDirective+' for custom widget for '+item.name+'; falling back to default widget');
- scope.state.config.customWidget[item.name].error = "Missing directive";
+ scope.state.config.customConfigWidgetMetadata[item.name].error = "Missing directive";
templateName = "error-" + templateName;
$templateCache.put(templateName, '<i>Widget '+widgetName+' missing</i>');
}
@@ -615,6 +611,21 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani
});
}
+ function loadCustomConfigWidgetMetadata(model) {
+ console.log("misc data", model.miscData, scope.model.miscData.get('ui-composer-hints'));
+ var customConfigWidgets = (scope.model.miscData.get('ui-composer-hints') || {})['config-widgets'] || [];
+ console.log("customs", customConfigWidgets);
+ customConfigWidgets.forEach( (wd) => {
+ console.log("looking at", wd);
+ var keys = wd.keys || [ wd.key ];
+ keys.forEach( (k) => {
+ console.log("setting key", k);
+ scope.state.config.customConfigWidgetMetadata[k] = angular.extend({ enabled: true }, scope.state.config.customConfigWidgetMetadata[k], wd);
+ });
+ });
+ console.log("custom config", scope.state.config.customConfigWidgetMetadata);
+ }
+
/* config state for each item is stored in multiple places:
* * scope.config = map of values used/set by editor (strings, map of strings, json code if using code mode, etc);
* this should be suitable for ng-model to work with, so e.g. if using code mode we need to put JSON.stringify value in here,
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/19de59de/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.less
----------------------------------------------------------------------
diff --git a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.less b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.less
index 233d937..da74f0f 100644
--- a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.less
+++ b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.less
@@ -338,7 +338,7 @@ spec-editor {
}
}
.form-group {
- &, .config-flex-row, .custom-widget-full {
+ &, .config-flex-row, .custom-config-widget {
display: flex;
flex-flow: row wrap;
width: 100%;
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/19de59de/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.template.html
----------------------------------------------------------------------
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 cc3e11e..740d295 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
@@ -139,12 +139,12 @@
auto-focus-not-if-within="true"
ng-focus="recordFocus(item)"
on-enter="advanceControlInFormGroup">
- <div ng-if="getCustomConfigWidgetMode(item) === 'full'" class="custom-widget-full">
- <ng-include src="getCustomConfigWidgetTemplate(item)" class="custom-widget-full"/>
+ <div ng-if="getCustomConfigWidgetMode(item) === 'enabled'" class="custom-config-widget">
+ <ng-include src="getCustomConfigWidgetTemplate(item)" class="custom-config-widget"/>
</div>
<!-- have to hide it; excluding it conditionally via if doesn't play nice with switch -->
- <div ng-show="getCustomConfigWidgetMode(item) !== 'full'" class="config-flex-row">
+ <div ng-show="getCustomConfigWidgetMode(item) !== 'enabled'" class="config-flex-row">
<label class="control-label" for="{{item.name}}">
<span class="label-spec-configuration">{{item.label || item.name}}</span>
<span class="info-spec-configuration">