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 b7c38dd65286a638b4c0d78b9cdd65216a1a1349
Author: Alex Heneveld <[email protected]>
AuthorDate: Fri Apr 23 18:54:39 2021 +0100

    set_from_parameter minimally working!!!
---
 .../app/components/quick-fix/quick-fix.js          | 57 ++++++++++++++++++++--
 .../spec-editor/spec-editor.directive.js           |  2 +-
 .../app/components/spec-editor/spec-editor.less    |  2 +
 .../app/components/util/model/entity.model.js      | 11 +++++
 4 files changed, 66 insertions(+), 6 deletions(-)

diff --git 
a/ui-modules/blueprint-composer/app/components/quick-fix/quick-fix.js 
b/ui-modules/blueprint-composer/app/components/quick-fix/quick-fix.js
index a542742..049a713 100644
--- a/ui-modules/blueprint-composer/app/components/quick-fix/quick-fix.js
+++ b/ui-modules/blueprint-composer/app/components/quick-fix/quick-fix.js
@@ -65,7 +65,7 @@ export function computeQuickFixesForIssue(issue, entity, 
proposalHolder) {
         if (!qfi) {
             console.log("Skipping unknown quick fix", qf);
         } else {
-            qfi.propose(issue, proposalHolder);
+            qfi.propose(qf, issue, entity, proposalHolder);
             // we could offer the fix per-issue, but no need as they can get 
that by navigating to the entity
             //qfi.propose(issue, issueO.quickFixes);  // issueO from previous 
method
         }
@@ -75,10 +75,10 @@ export function computeQuickFixesForIssue(issue, entity, 
proposalHolder) {
 const QUICK_FIX_PROPOSERS = {
     clear_config: {
         // the propose function updates the proposals object
-        propose: (issue, proposals) => {
+        propose: (qfdef, issue, entity, proposals) => {
             if (!issue.ref) return;
-
             if (!proposals) proposals = {};
+
             if (!proposals.clear_config) {
                 proposals.clear_config = {
                     text: "Remove value",
@@ -91,7 +91,8 @@ const QUICK_FIX_PROPOSERS = {
         },
     },
     set_from_parameter: {
-        propose: (issue, proposals) => {}
+        propose: proposeSetFrom('parameter')
+
       // - key: post_code
       //   fix: set_from_parameter
       //   message-regex: required
@@ -104,7 +105,8 @@ const QUICK_FIX_PROPOSERS = {
 
     },
     set_from_config_key: {
-        propose: (issue, proposals) => {}
+        propose: proposeSetFrom('config')
+
         // - key: post_code
         //   fix: set_from_config_key
         //   message-regex: required
@@ -116,6 +118,51 @@ const QUICK_FIX_PROPOSERS = {
     }
 };
 
+function proposeSetFrom(sourceType) {
+    return function (qfdef, issue, entity, proposals) {
+        if (!issue.ref) return;
+        if (!proposals) proposals = {};
+
+        let sourceNode = {
+            id: 'root',
+            name: 'the application root node',
+            entity: entity.getApplication(),
+        };
+
+        if (sourceType === 'parameter') {
+            let params = sourceNode.entity.getParametersAsArray();
+            console.log("params", params);
+        }
+
+        let key = 'set_from_'+sourceType+'_'+sourceNode.id;
+        if (!proposals[key]) {
+            proposals[key] = {
+                text: "Set from a new "+sourceType+" on "+sourceNode.name,
+                tooltip: "This will create a "+sourceType+" on 
"+sourceNode.name+" and fix this error by setting it equal to that "+sourceType,
+                issues: [],
+                apply: (issue, entity) => {
+                    entity = (entity || issue.entity);
+                    console.log("TODO do this; NB issue invoked wrt", entity, 
qfdef);
+                    if (sourceType === 'parameter') {
+                        if 
(!sourceNode.entity.getParameterNamed(qfdef['source-parameter'])) {
+                            sourceNode.entity.addParameter({
+                                name: qfdef['source-parameter'],
+                                constraints: qfdef['source-constraints']
+                            });
+                        }
+                        if (!sourceNode.entity.id) {
+                            // TODO
+                            sourceNode.entity.id = 'id_XXX';
+                        }
+                        entity.addConfig(issue.ref, 
'$brooklyn:component("'+sourceNode.entity.id+'").config("'+qfdef['source-parameter']+'")');
+                    }
+                }
+            };
+        }
+        proposals[key].issues.push(issue);
+    };
+}
+
 export function getQuickFixProposer(type) {
     return QUICK_FIX_PROPOSERS[type];
 }
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 43ac178..892167a 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,7 +558,7 @@ export function specEditorDirective($rootScope, 
$templateCache, $injector, $sani
             return item.widgetMode;
         };
         specEditor.getParameterWidgetMode = (item) => {
-            let type = item.type || item.typeName;
+            let type = item.type || item.typeName || 'string';
 
             if (type === 'java.lang.Boolean') type = 'boolean';
             else if (type === 'java.util.Map') type = 'map';
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 4fcefca..0396469 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
@@ -474,6 +474,8 @@ spec-editor {
       .btn {
         float: right;
         color: @gray-lighter !important;
+        margin-left: 1em;
+        margin-bottom: 2px;
       }
     }
     .param-fields {
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 782da39..f8afc28 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
@@ -463,6 +463,11 @@ export class Entity {
         }
     }
 
+    getApplication() {
+        if (this.hasParent()) return this.parent.getApplication();
+        return this;
+    }
+
     /**
      * Has {Entity} got a parent
      * @returns {boolean}
@@ -567,6 +572,7 @@ Entity.prototype.getConfigAsJson = getConfigAsJson;
 Entity.prototype.setConfigFromJson = setConfigFromJson;
 
 Entity.prototype.getParametersAsArray = getParametersAsArray;
+Entity.prototype.getParameterNamed = getParameterNamed;
 Entity.prototype.setParametersFromJson = setParametersFromJson;
 
 Entity.prototype.getMetadataAsJson = getMetadataAsJson;
@@ -1116,6 +1122,11 @@ function getParametersAsArray() {
     return PARAMETERS.get(this);
 }
 
+function getParameterNamed(name) {
+    // TODO confirm works
+    return PARAMETERS.get(this).find(p => p.name === name);
+}
+
 /* "cleaning" here means:  Dsl objects are toStringed, to the given depth (or 
infinite if depth<0);
  * and entries in Map that are memberspec are unwrapped.
  * previously we also stringified maps/lists but that seemed pointless, and it 
was lossy and buggy.

Reply via email to