From 0afa7e77feeed35190ee10a43a3fd186d524f2f7 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 13 Sep 2018 11:19:44 +0100 Subject: [PATCH 1/4] fix more generics issue in UI wizard, for entity spec selection --- .../spec-editor/spec-editor.directive.js | 14 +++++++----- .../app/components/util/model/entity.model.js | 22 ++++++++++++++----- 2 files changed, 25 insertions(+), 11 deletions(-) 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 8272d012b..6f370771a 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 @@ -20,7 +20,7 @@ import angular from 'angular'; import onEnter from 'brooklyn-ui-utils/on-enter/index'; import autoGrow from 'brooklyn-ui-utils/autogrow/index'; import blurOnEnter from 'brooklyn-ui-utils/blur-on-enter/index'; -import {EntityFamily} from '../util/model/entity.model'; +import {EntityFamily, baseType} from '../util/model/entity.model'; import {Dsl} from '../util/model/dsl.model'; import {Issue, ISSUE_LEVEL} from '../util/model/issue.model'; import {RESERVED_KEYS, DSL_ENTITY_SPEC} from '../providers/blueprint-service.provider'; @@ -357,6 +357,13 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani return issues.some(issue => issue.level === ISSUE_LEVEL.ERROR) ? 'badge-danger' : 'badge-warning'; }; + function baseType(s) { + if (s && s.indexOf("<")>=0) { + s = s.substring(0, s.indexOf("<")); + } + return s; + } + function getConfigWidgetModeInternal(item, val) { if (angular.element($document[0].activeElement).hasClass("form-control") && item.widgetMode) { // don't switch mode in mid-edit, e.g. if you are manually typing $brooklyn:component("x").config("y") @@ -371,10 +378,7 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani } if (!scope.defined(val)) val = scope.config[item.name]; - let type = item.type; - if (type && type.indexOf("<")>=0) { - type = type.substring(0, type.indexOf("<")); - } + let type = baseType(item.type); // if actual value's type does not match declared type, // e.g. object is a map when declared type is object or string or something else, diff --git a/ui-modules/blueprint-composer/app/components/util/model/entity.model.js b/ui-modules/blueprint-composer/app/components/util/model/entity.model.js index ed0ea8162..e09f7c6dd 100644 --- a/ui-modules/blueprint-composer/app/components/util/model/entity.model.js +++ b/ui-modules/blueprint-composer/app/components/util/model/entity.model.js @@ -644,6 +644,13 @@ function isCluster() { }).length > 0; } +export function baseType(s) { + if (s && s.indexOf("<")>=0) { + s = s.substring(0, s.indexOf("<")); + } + return s; +} + /** * Returns a map of => Entity of all spec {Entity} defined in the configuration * @returns {*} @@ -653,7 +660,7 @@ function getClusterMemberspecEntities() { return {}; } return MISC_DATA.get(this).get('config') - .filter((config)=>(config.type === 'org.apache.brooklyn.api.entity.EntitySpec')) + .filter((config)=>(baseType(config.type) === EntityFamily.SPEC.superType)) .reduce((acc, config)=> { if (CONFIG.get(this).has(config.name)) { acc[config.name] = CONFIG.get(this).get(config.name)[DSL.ENTITY_SPEC]; @@ -661,7 +668,7 @@ function getClusterMemberspecEntities() { return acc; }, {}); } - + /** * Returns the first memberspec that matches the given predicate * @@ -674,10 +681,13 @@ function getClusterMemberspecEntity(predicate = ()=>(true)) { } return MISC_DATA.get(this).get('config') - .filter((config)=>(config.type === 'org.apache.brooklyn.api.entity.EntitySpec')) + .filter((config)=>(baseType(config.type) === EntityFamily.SPEC.superType)) .reduce((acc, config)=> { - if (CONFIG.get(this).has(config.name) && predicate(config, CONFIG.get(this).get(config.name)[DSL.ENTITY_SPEC])) { - return CONFIG.get(this).get(config.name)[DSL.ENTITY_SPEC]; + if (CONFIG.get(this).has(config.name)) { + let entityV = CONFIG.get(this).get(config.name)[DSL.ENTITY_SPEC]; + if (entityV && predicate(config, entityV)) { + return entityV; + } } return acc; }, undefined); @@ -688,7 +698,7 @@ function setClusterMemberspecEntity(key, entity) { return this; } let definition = MISC_DATA.get(this).get('config') - .filter((config)=>(config.type === 'org.apache.brooklyn.api.entity.EntitySpec' && config.name === key)); + .filter((config)=>(baseType(config.type) === EntityFamily.SPEC.superType && config.name === key)); if (definition.length !== 1) { return this; } From cd2ac803f1fab71505b7400f86e9de630ba48314 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 13 Sep 2018 11:48:27 +0100 Subject: [PATCH 2/4] custom widgets should not copy scope values from parent but rather reference them explicitly. copying scope means if the parent changes that var, which it does e.g. for `config`, the child's scope value becomes disconnected. --- .../suggestion-dropdown.html | 16 +++++++++------- .../custom-config-widget/suggestion-dropdown.js | 2 +- .../spec-editor/spec-editor.directive.js | 8 -------- 3 files changed, 10 insertions(+), 16 deletions(-) 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 82ecfeabf..6c4a807b9 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,30 +30,32 @@ - - {{getCustomConfigWidgetModeTitle(item)}} [{{item.name}}] + + {{specEditor.getCustomConfigWidgetModeTitle(item)}} [{{item.name}}] -
+
{{ params['label-expanded'] || "" }}
{{ params['label-collapsed'] || "" }}
- - +
+ +
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 3dfa86043..1667d9837 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 @@ -39,7 +39,7 @@ export function suggestionDropdownDirective($rootScope) { }; function link(scope) { - scope.$parent.copyScopeForCustomConfigWidget(scope); + scope.specEditor = scope.$parent; scope.getSuggestions = () => { var result = []; if (scope.params['suggestion-values']) { 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 6f370771a..870a4729e 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 @@ -558,14 +558,6 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani } return widgetMetadata.enabled ? "Use standard widget" : "Use custom widget"; }; - scope.copyScopeForCustomConfigWidget = (descendantScope) => { - descendantScope.toggleCustomConfigWidgetMode = scope.toggleCustomConfigWidgetMode; - descendantScope.getCustomConfigWidgetModeTitle = scope.getCustomConfigWidgetModeTitle; - descendantScope.defined = scope.defined; - descendantScope.config = scope.config; - descendantScope.state = scope.state; - descendantScope.copyScopeForCustomConfigWidget = scope.copyScopeForCustomConfigWidget; - }; scope.getCustomConfigWidgetTemplate = (item) => { var widgetMetadata = scope.state.config.customConfigWidgetMetadata[item.name]; var widgetName = $sanitize(widgetMetadata.widget || '--no-widget--'); From b8d774344cbcb8b188198e4440dc4b5279faa792 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 13 Sep 2018 13:47:10 +0100 Subject: [PATCH 3/4] put functions on controller so there is less data we need to pass to the custom widget avoids entirely the use of $parent, and follows better the angular way --- .../suggestion-dropdown.html | 8 +-- .../suggestion-dropdown.js | 8 ++- .../spec-editor/spec-editor.directive.js | 68 +++++++++++-------- .../spec-editor/spec-editor.template.html | 60 ++++++++-------- 4 files changed, 78 insertions(+), 66 deletions(-) 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 6c4a807b9..56395a64a 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 @@ -35,15 +35,15 @@ -
+
{{ params['label-expanded'] || "" }}
{{ params['label-collapsed'] || "" }}
- - + ng-focus="specEditor.recordFocus(item)" on-enter="specEditor.advanceOutToFormGroupInPanel"> +
From 1d2705c4d06b153408ad1e7983b93a3838d9a236 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 13 Sep 2018 13:50:06 +0100 Subject: [PATCH 4/4] minor tidy as per PR review --- .../app/components/spec-editor/spec-editor.directive.js | 7 ------- 1 file changed, 7 deletions(-) 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 4ff2213e7..a6b19e8f2 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 @@ -365,13 +365,6 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani return issues.some(issue => issue.level === ISSUE_LEVEL.ERROR) ? 'badge-danger' : 'badge-warning'; }; - function baseType(s) { - if (s && s.indexOf("<")>=0) { - s = s.substring(0, s.indexOf("<")); - } - return s; - } - function getConfigWidgetModeInternal(item, val) { if (angular.element($document[0].activeElement).hasClass("form-control") && item.widgetMode) { // don't switch mode in mid-edit, e.g. if you are manually typing $brooklyn:component("x").config("y")