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 2021/05/31 15:17:14 UTC

[brooklyn-ui] branch master updated (359b4e5 -> 59c7fd5)

This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git.


    from 359b4e5  fix entity resolution logic
     new 5167b68  Allow downstream to configure edit.dsl controller
     new 68a6949  Create constants for DSL target; use subsection parameter in dsl.edit instead of isConfig
     new 0d2da83  Create DSL of kind TARGET on select by default
     new 59c7fd5  This closes #206

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../app/components/dsl-editor/dsl-editor.js        | 10 +--
 .../app/components/util/model/dsl.model.js         | 35 ++++++----
 .../app/components/util/model/dsl.model.spec.js    |  8 +--
 .../main/graphical/edit/dsl/edit.dsl.controller.js | 77 +++++++++++++++++-----
 4 files changed, 95 insertions(+), 35 deletions(-)

[brooklyn-ui] 01/04: Allow downstream to configure edit.dsl controller

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git

commit 5167b68645ea5655a8d92cbc66c2bb19b67781d2
Author: Mykola Mandra <my...@cloudsoftcorp.com>
AuthorDate: Fri May 28 18:35:55 2021 +0100

    Allow downstream to configure edit.dsl controller
    
    Signed-off-by: Mykola Mandra <my...@cloudsoftcorp.com>
---
 .../main/graphical/edit/dsl/edit.dsl.controller.js | 77 +++++++++++++++++-----
 1 file changed, 62 insertions(+), 15 deletions(-)

diff --git a/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js b/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js
index fe94cd7..c29e8d4 100644
--- a/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js
+++ b/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js
@@ -45,11 +45,7 @@ function EditDslController($scope, $state, $stateParams, objectCache, state) {
         updateRootDsl(data.dsl);
 
         if ($scope.state.levels.length === 0) {
-            if ($stateParams.index) {
-                $scope.state.entity.config.get($stateParams.for)[$stateParams.index] = $scope.state.rootDsl;
-            } else {
-                $scope.state.entity.addConfig($stateParams.for, $scope.state.rootDsl);
-            }
+            $scope.state.setRootDsl($stateParams, $scope.state.entity, $scope.state.rootDsl);
             objectCache.removeAll();
             viewName = $scope.state.view.name;
             viewParams = $scope.state.view.params;
@@ -131,27 +127,31 @@ export const graphicalEditDslState = {
         index: {
             value: '',
             squash: true
-        }
+        },
+        isConfig: true // This flag identifies whether DSL edit is for configuration or something else. Configuration is a default.
     },
     template: template,
     controller: ['$scope', '$state', '$stateParams', 'objectCache', 'state', EditDslController],
     controllerAs: 'vm',
     resolve: {
-        state: ['$state', '$stateParams', 'entity', 'brSnackbar', 'objectCache', ($state, $stateParams, entity, brSnackbar, objectCache) => {
-            let definition = entity.miscData.get('config').find(config => config.name === $stateParams.for);
+        state: ['$state', '$stateParams', 'entity', 'brSnackbar', 'objectCache', 'composerOverrides', ($state, $stateParams, entity, brSnackbar, objectCache, composerOverrides) => {
+
+            // Initialize dsl-edit helpers
+            $state.getDefinition = getConfigDefinition;
+            $state.getRootDsl = getConfigRootDsl;
+            $state.setRootDsl = setConfigRootDsl;
+
+            // Allow downstream to configure this controller and override helpers defined above, when required.
+            (composerOverrides.configureDslEdit || function () {})($state);
+
+            let definition = $state.getDefinition($stateParams, entity);
             if (!definition) {
                 brSnackbar.create(`Config key ${$stateParams.for} does not exist.`);
             }
 
             let rootDsl = objectCache.get(`${definition.name}.dsl`);
             if (!rootDsl) {
-                let config = entity.config.get(definition.name);
-                if ($stateParams.index) {
-                    config = config[$stateParams.index];
-                }
-                rootDsl = config instanceof Dsl
-                    ? config.clone()
-                    : new Dsl(KIND.STRING, '');
+                rootDsl = $state.getRootDsl($stateParams, entity, definition);
                 objectCache.put(`${definition.name}.dsl`, rootDsl);
             }
 
@@ -181,7 +181,54 @@ export const graphicalEditDslState = {
                 state.definition.type = '.*';
             }
 
+            // This step enables $state.setRootDsl override in the controller.
+            state.setRootDsl = $state.setRootDsl;
+
             return state;
         }]
     }
 };
+
+/**
+ * Gets configuration definition.
+ *
+ * @param {Object} stateParams The state parameters to get name of the configuration definition to look for.
+ * @param {Entity} entity The entity to get configuration definition from.
+ * @returns {Object} The configuration definition.
+ */
+function getConfigDefinition(stateParams, entity) {
+    return entity.miscData.get('config').find(config => config.name === stateParams.for);
+}
+
+/**
+ * Gets root DSL model from the entity configuration, creates a new one if it does not exist.
+ *
+ * @param {Object} stateParams The state parameters to get index of the configuration definition to look for.
+ * @param {Entity} entity The entity to get configuration definition from.
+ * @param {Object} definition The configuration definition.
+ * @returns {Dsl} The root DSL model.
+ */
+function getConfigRootDsl(stateParams, entity, definition) {
+    let config = entity.config.get(definition.name);
+    if (stateParams.index) {
+        config = config[stateParams.index];
+    }
+    return config instanceof Dsl
+        ? config.clone()
+        : new Dsl(KIND.STRING, '');
+}
+
+/**
+ * Sets root DSL model in the entity configuration.
+ *
+ * @param {Object} stateParams The state parameters to get index and name of the configuration definition to set.
+ * @param {Entity} entity The entity to update root DSL model with.
+ * @param {Dsl} rootDsl The root DSL model to set.
+ */
+function setConfigRootDsl(stateParams, entity, rootDsl) {
+    if (stateParams.index) {
+        entity.config.get(stateParams.for)[stateParams.index] = rootDsl;
+    } else {
+        entity.addConfig(stateParams.for, rootDsl);
+    }
+}

[brooklyn-ui] 02/04: Create constants for DSL target; use subsection parameter in dsl.edit instead of isConfig

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git

commit 68a694993741dbf00b9b3d13a7328dc7ed92b504
Author: Mykola Mandra <my...@cloudsoftcorp.com>
AuthorDate: Mon May 31 13:14:26 2021 +0100

    Create constants for DSL target; use subsection parameter in dsl.edit instead of isConfig
    
    Signed-off-by: Mykola Mandra <my...@cloudsoftcorp.com>
---
 .../app/components/dsl-editor/dsl-editor.js        |  8 ++---
 .../app/components/util/model/dsl.model.js         | 35 +++++++++++++++-------
 .../app/components/util/model/dsl.model.spec.js    |  8 ++---
 .../main/graphical/edit/dsl/edit.dsl.controller.js |  2 +-
 4 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js b/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
index 3b0cd20..5bbd0ee 100644
--- a/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
+++ b/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
@@ -18,7 +18,7 @@
  */
 import angular from 'angular';
 import angularSanitize from 'angular-sanitize';
-import {Dsl, DslParser, KIND} from '../util/model/dsl.model';
+import {Dsl, DslParser, KIND, TARGET} from '../util/model/dsl.model';
 import template from './dsl-editor.template.html';
 import brAutoFocus from 'brooklyn-ui-utils/autofocus/autofocus';
 import brUtils from 'brooklyn-ui-utils/utils/general';
@@ -354,10 +354,10 @@ export function dslEditorDirective($rootScope, $filter, $log, brUtilsGeneral, bl
 
     function getScopedDsl(entity, targetEntity, state) {
         if (entity === targetEntity) {
-            return new Dsl(KIND.TARGET, 'self');
+            return new Dsl(KIND.TARGET, TARGET.SELF);
         }
         if (entity.parent === targetEntity) {
-            return new Dsl(KIND.TARGET, 'parent');
+            return new Dsl(KIND.TARGET, TARGET.PARENT);
         }
 
         if (!targetEntity.hasId()) {
@@ -372,7 +372,7 @@ export function dslEditorDirective($rootScope, $filter, $log, brUtilsGeneral, bl
     }
 
     function isSelfDsl(dsl) {
-        return dsl && dsl.kind === KIND.TARGET && dsl.name === 'self';
+        return dsl && dsl.kind === KIND.TARGET && dsl.name === TARGET.SELF;
     }
 }
 
diff --git a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js
index 0caa5e4..27d4fb6 100644
--- a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js
+++ b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js
@@ -20,7 +20,20 @@ import {Entity} from './entity.model';
 
 const FUNCTION_PREFIX = '$brooklyn:';
 
-const TARGETS = [ 'self', 'parent', 'child', 'sibling', 'descendant', 'ancestor', 'root', 'scopeRoot', 'entity', 'component', ];
+export const TARGET = {
+    SELF: 'self',
+    ROOT: 'root',
+    CHILD: 'child',
+    ENTITY: 'entity',
+    PARENT: 'parent',
+    SIBLING: 'sibling',
+    ANCESTOR: 'ancestor',
+    SCOPEROOT: 'scopeRoot',
+    COMPONENT: 'component',
+    DESCENDANT: 'descendant'
+}
+
+const TARGETS = Object.values(TARGET);
 
 const UTILITIES = [ 'literal', 'formatString', 'urlEncode', 'regexReplacement' ];
 
@@ -585,20 +598,20 @@ export class Dsl {
         let curr = entity;
         while (dsl.kind === KIND.TARGET) {
             switch (dsl.name) {
-                case 'self':
+                case TARGET.SELF:
                     break;
-                case 'parent':
+                case TARGET.PARENT:
                     if (!curr.parent) {
                         this.issues.push('The entity with ID <code>' + curr.id + '</code> does not have a parent');
                     }
                     curr = curr.parent;
                     break;
-                case 'child':
-                case 'sibling':
-                case 'descendant':
-                case 'ancestor':
-                case 'entity':
-                case 'component': // component can have 1 or 2 params
+                case TARGET.CHILD:
+                case TARGET.SIBLING:
+                case TARGET.DESCENDANT:
+                case TARGET.ANCESTOR:
+                case TARGET.ENTITY:
+                case TARGET.COMPONENT: // component can have 1 or 2 params
                     let name = dsl.params[dsl.params.length - 1].name;
                     let resolvedEntity = entityResolver(name);
                     if (resolvedEntity === null) {
@@ -606,8 +619,8 @@ export class Dsl {
                     }
                     curr = resolvedEntity;
                     break;
-                case 'root':
-                case 'scopeRoot':
+                case TARGET.ROOT:
+                case TARGET.SCOPEROOT:
                     curr = this.resolveRoot(curr);
                     break;
             }
diff --git a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.spec.js b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.spec.js
index 836322b..83c621d 100644
--- a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.spec.js
+++ b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.spec.js
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import {Dsl, KIND, DslParser, Tokenizer, DslError} from './dsl.model';
+import {Dsl, KIND, DslParser, Tokenizer, DslError, TARGET} from './dsl.model';
 import {Entity} from './entity.model';
 
 describe('Dsl Component Model', ()=>{
@@ -159,7 +159,7 @@ describe('Dsl Component Model', ()=>{
            expect(dsl2.generate()).toEqual('10.2');
 
            // target function without parameters
-           let dsl3 = new Dsl(KIND.TARGET, 'self');
+           let dsl3 = new Dsl(KIND.TARGET, TARGET.SELF);
            expect(dsl3.generateParams()).toEqual('');
            expect(dsl3.toString()).toEqual('$brooklyn:self()');
            expect(dsl3.generate()).toEqual('self()');
@@ -175,8 +175,8 @@ describe('Dsl Component Model', ()=>{
            expect(dsl3.toString()).toEqual('$brooklyn:self().attributeWhenReady("http.port")');
 
            // chained target functions and methods: parent().sibling(...).attributeWhenReady(...)
-           let dsl4 = new Dsl(KIND.TARGET, 'parent');
-           let sib1 = new Dsl(KIND.TARGET, 'sibling');
+           let dsl4 = new Dsl(KIND.TARGET, TARGET.PARENT);
+           let sib1 = new Dsl(KIND.TARGET, TARGET.SIBLING);
            let par2 = new Dsl(KIND.STRING, 'rootNode');
            sib1.param(par2);
            dsl4.chain(sib1);
diff --git a/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js b/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js
index c29e8d4..c09af70 100644
--- a/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js
+++ b/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js
@@ -128,7 +128,7 @@ export const graphicalEditDslState = {
             value: '',
             squash: true
         },
-        isConfig: true // This flag identifies whether DSL edit is for configuration or something else. Configuration is a default.
+        subsection: '' // This parameter specifies what subsection DSL edit is for. Configuration subsection is default.
     },
     template: template,
     controller: ['$scope', '$state', '$stateParams', 'objectCache', 'state', EditDslController],

[brooklyn-ui] 04/04: This closes #206

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git

commit 59c7fd56e65b6cfba7f20f55b99698d1785508f1
Merge: 359b4e5 0d2da83
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Mon May 31 16:17:08 2021 +0100

    This closes #206

 .../app/components/dsl-editor/dsl-editor.js        | 10 +--
 .../app/components/util/model/dsl.model.js         | 35 ++++++----
 .../app/components/util/model/dsl.model.spec.js    |  8 +--
 .../main/graphical/edit/dsl/edit.dsl.controller.js | 77 +++++++++++++++++-----
 4 files changed, 95 insertions(+), 35 deletions(-)


[brooklyn-ui] 03/04: Create DSL of kind TARGET on select by default

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git

commit 0d2da83d6085ad54ad51048c4fbc9430cf592ea4
Author: Mykola Mandra <my...@cloudsoftcorp.com>
AuthorDate: Mon May 31 15:35:56 2021 +0100

    Create DSL of kind TARGET on select by default
    
    Signed-off-by: Mykola Mandra <my...@cloudsoftcorp.com>
---
 ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js b/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
index 5bbd0ee..c7b9e16 100644
--- a/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
+++ b/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
@@ -368,7 +368,7 @@ export function dslEditorDirective($rootScope, $filter, $log, brUtilsGeneral, bl
             }
         }
 
-        return new Dsl(KIND.METHOD, 'component').param(new Dsl(KIND.STRING, targetEntity.id));
+        return new Dsl(KIND.TARGET, TARGET.COMPONENT).param(new Dsl(KIND.STRING, targetEntity.id));
     }
 
     function isSelfDsl(dsl) {