Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge of my local changes #64

Closed
bartbutenaers opened this issue May 27, 2021 · 6 comments
Closed

Merge of my local changes #64

bartbutenaers opened this issue May 27, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@bartbutenaers
Copy link
Owner

I have an old local version of the blockly node at home. Due to the pull request of @jsccjj those changes will have to be reviewed and tested, because they probably won't work anymore.

These are the major changes:

  1. Load blockly as an npm dependency instead of downloading and importing all blockly files manually to our repository. The advantage of this change is that we only need to change the Blockly version number in our package.json file.
  2. Load the data picker, which is a separate npm module -> when this is done, we can implement Add date picker block (see issue).
  3. I have a added some blocks to the Node-RED toolbox, to support new functionality of the function node API:
    • New block for node environment variable
    • New block for node done support
    • The existing node properties block has (besides node name and id) now extra the node output count.
@bartbutenaers bartbutenaers added the enhancement New feature or request label May 27, 2021
@bartbutenaers bartbutenaers self-assigned this May 27, 2021
@bartbutenaers
Copy link
Owner Author

@cymplecy , @jsccjj ,
I have made some changes in the 1.1.0 branch for point "3":

  • The blockly.js file is back in sync with the current Node-RED function node, to make sure we have an up-to-date API. This allows us to add the 3 changes below...

  • I have added a new "Done" block, to allow users to specify when a message handling is done.

    image

    This is mostly interesting if we ever add asynchronous processing blocks, but there might be other use cases...

    In the following example flow, the Complete node is only triggered when the "done" block (inside the if statement) is triggered:

    image

    [{"id":"bb6162cc.e1704","type":"Blockly","z":"c2a7925b.6e143","language":"en","func":"node.send([msg]);\nif ((msg['payload']) == 'activate_done') {\n  node.done();\n}\n","workspaceXml":"<xml xmlns=\"https://developers.google.com/blockly/xml\">\n  <block type=\"node_send\" id=\"Yoqo0*^[cs89^n:s:mB:\" x=\"-587\" y=\"-537\">\n    <field name=\"OUTPUT_NR\">1</field>\n    <value name=\"MESSAGE_INPUT\">\n      <shadow type=\"node_msg\" id=\"54X^[E^pMXOTtqY3prub\"></shadow>\n      <block type=\"node_msg\" id=\"2pz7$WcP#?EYH`4,t}rO\"></block>\n    </value>\n    <next>\n      <block type=\"controls_if\" id=\"f4)[rrPR|B;uWPhziE]T\">\n        <value name=\"IF0\">\n          <block type=\"logic_compare\" id=\"UM.)|z.!+]O^@#z+qaD]\">\n            <field name=\"OP\">EQ</field>\n            <value name=\"A\">\n              <block type=\"node_object_get\" id=\"FCAkJxW%BN$,0],!tE=*\">\n                <mutation xmlns=\"http://www.w3.org/1999/xhtml\" action=\"GET\"></mutation>\n                <field name=\"action\">GET</field>\n                <value name=\"object\">\n                  <shadow type=\"node_msg\" id=\"L.1CSMob$,3W[o0)]1B8\"></shadow>\n                  <block type=\"node_msg\" id=\"g@IOruwt,yUL,zy[|jA3\"></block>\n                </value>\n                <value name=\"field_name\">\n                  <shadow type=\"text\" id=\"eHgGVFgeUM:q^-r!FFP`\">\n                    <field name=\"TEXT\">payload</field>\n                  </shadow>\n                </value>\n              </block>\n            </value>\n            <value name=\"B\">\n              <block type=\"text\" id=\"%a|;]8Jx=84[U#9ooWD!\">\n                <field name=\"TEXT\">activate_done</field>\n              </block>\n            </value>\n          </block>\n        </value>\n        <statement name=\"DO0\">\n          <block type=\"node_done\" id=\"BE:%8^@,:?;!$W1~^w_o\"></block>\n        </statement>\n      </block>\n    </next>\n  </block>\n</xml>","outputs":1,"name":"","x":380,"y":100,"wires":[["38459650.ac32da"]]},{"id":"88a2a218.f1f35","type":"inject","z":"c2a7925b.6e143","name":"Don't activate \"done\"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"dont_activate_done","payloadType":"str","x":170,"y":100,"wires":[["bb6162cc.e1704"]]},{"id":"38459650.ac32da","type":"debug","z":"c2a7925b.6e143","name":"Blockly output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":100,"wires":[]},{"id":"e48085d7.32f838","type":"complete","z":"c2a7925b.6e143","name":"","scope":["bb6162cc.e1704"],"uncaught":false,"x":390,"y":220,"wires":[["c8ab2289.02c92"]]},{"id":"c8ab2289.02c92","type":"debug","z":"c2a7925b.6e143","name":"Msg completed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":220,"wires":[]},{"id":"bf4e9e59.f7a49","type":"inject","z":"c2a7925b.6e143","name":"Activate \"done\"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"activate_done","payloadType":"str","x":160,"y":140,"wires":[["bb6162cc.e1704"]]}]
    
  • A new "environment" block has been added to get the content of an environment variable. The following example flow gets my Windows 10 PATH variable content:

    image

    [{"id":"6f9044a0.b3870c","type":"Blockly","z":"c2a7925b.6e143","language":"en","func":"msg['payload'] = (env.get('PATH'));\nnode.send([msg]);\n","workspaceXml":"<xml xmlns=\"https://developers.google.com/blockly/xml\">\n  <block type=\"node_object_set\" id=\"gX/eh*PQB7$|#s[cv?qF\" x=\"-662\" y=\"-712\">\n    <value name=\"object_field\">\n      <shadow type=\"node_msg\" id=\"Q@l{i.!VToOzB|awKfkU\"></shadow>\n    </value>\n    <value name=\"field_name\">\n      <shadow type=\"text\" id=\"y[l*wG~*rfPtoU{T~Ggk\">\n        <field name=\"TEXT\">payload</field>\n      </shadow>\n    </value>\n    <value name=\"value_field\">\n      <shadow type=\"text\" id=\"0f6:Op^1?@z=$0X,?Hkz\">\n        <field name=\"TEXT\"></field>\n      </shadow>\n      <block type=\"node_object_get\" id=\"$qp;H#n%r?:}A6LuT1Jr\">\n        <mutation xmlns=\"http://www.w3.org/1999/xhtml\" action=\"GET\"></mutation>\n        <field name=\"action\">GET</field>\n        <value name=\"object\">\n          <shadow type=\"node_msg\" id=\":Lg%EQ6x$(1#SOXHko,t\"></shadow>\n          <block type=\"node_env\" id=\"mG,huw9)S!~YPzS091d=\"></block>\n        </value>\n        <value name=\"field_name\">\n          <shadow type=\"text\" id=\"wyCS2#H47#_4E)PB~2)m\">\n            <field name=\"TEXT\">PATH</field>\n          </shadow>\n        </value>\n      </block>\n    </value>\n    <next>\n      <block type=\"node_send\" id=\"Yoqo0*^[cs89^n:s:mB:\">\n        <field name=\"OUTPUT_NR\">1</field>\n        <value name=\"MESSAGE_INPUT\">\n          <shadow type=\"node_msg\" id=\"54X^[E^pMXOTtqY3prub\"></shadow>\n          <block type=\"node_msg\" id=\"2pz7$WcP#?EYH`4,t}rO\"></block>\n        </value>\n      </block>\n    </next>\n  </block>\n</xml>","outputs":1,"name":"","x":420,"y":580,"wires":[["23f77ae.7ac7086"]]},{"id":"bb11da23.5f7ff8","type":"inject","z":"c2a7925b.6e143","name":"Get environment variable","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":580,"wires":[["6f9044a0.b3870c"]]},{"id":"23f77ae.7ac7086","type":"debug","z":"c2a7925b.6e143","name":"Environment variable","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":580,"wires":[]}]
    

    Which results into this:

    image

  • A new "output count" option has been added to the node properties block:

    image

    The following example flow shows how to get the number of output ports (i.e. 4) of the blockly node:

    image

    [{"id":"297aee54.4b93a2","type":"Blockly","z":"c2a7925b.6e143","language":"en","func":"msg['payload'] = node.outputCount;\nnode.send([msg, null, null, null]);\n","workspaceXml":"<xml xmlns=\"https://developers.google.com/blockly/xml\">\n  <block type=\"node_object_set\" id=\"gX/eh*PQB7$|#s[cv?qF\" x=\"-587\" y=\"-612\">\n    <value name=\"object_field\">\n      <shadow type=\"node_msg\" id=\"Q@l{i.!VToOzB|awKfkU\"></shadow>\n    </value>\n    <value name=\"field_name\">\n      <shadow type=\"text\" id=\"y[l*wG~*rfPtoU{T~Ggk\">\n        <field name=\"TEXT\">payload</field>\n      </shadow>\n    </value>\n    <value name=\"value_field\">\n      <shadow type=\"text\" id=\"0f6:Op^1?@z=$0X,?Hkz\">\n        <field name=\"TEXT\"></field>\n      </shadow>\n      <block type=\"node_properties\" id=\"jFf;@xp_,+0Dcs~$35wY\">\n        <field name=\"PROPERTY_NAME\">OUTPUT_COUNT</field>\n      </block>\n    </value>\n    <next>\n      <block type=\"node_send\" id=\"Yoqo0*^[cs89^n:s:mB:\">\n        <field name=\"OUTPUT_NR\">1</field>\n        <value name=\"MESSAGE_INPUT\">\n          <shadow type=\"node_msg\" id=\"54X^[E^pMXOTtqY3prub\"></shadow>\n          <block type=\"node_msg\" id=\"2pz7$WcP#?EYH`4,t}rO\"></block>\n        </value>\n      </block>\n    </next>\n  </block>\n</xml>","outputs":4,"name":"","x":380,"y":400,"wires":[["ba089c9e.89b7a"],[],[],[]]},{"id":"dc53e84d.1696e8","type":"inject","z":"c2a7925b.6e143","name":"Get output count","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":400,"wires":[["297aee54.4b93a2"]]},{"id":"ba089c9e.89b7a","type":"debug","z":"c2a7925b.6e143","name":"Output count","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":570,"y":380,"wires":[]}]
    

The problem with the environment block, is that you are only allowed to get the value of an environment variable. You are not allowed to set it. So we need to prevent somehow that this new block cannot be dropped e.g. in the node-set block. It is too long ago that I worked with Blockly, so I don't know anymore how to accomplish that. If you guys have an idea, please let me know!

P.S. I got a little surprise at work that I have to work tomorrow on sunday. So not much time left to continue on this release this weekend :-(

@bartbutenaers
Copy link
Owner Author

Hi @cymplecy , @jsccjj ,
I had to wait 30 minutes while waiting for my son to help him with his statistics exam...
So to avoid wasting this time interval, I have tested my old local changes for "2" and "3" in the 1.1.0 branch version of this node ;-)
And I was lucky since it seemed to be still working....

  • I have removed the Blockly library clone that we had copied locally to our project.
  • All the files Blockly files required by the frontend are now served by the backend endpoint, which will get all the required files from the downloaded NPM module directories (see next step).
  • I have added Blockly NPM dependencies to our package.json file:
    "dependencies": {
       "blockly": "^5.20210325.1",
       "@blockly/field-date": "^4.2.14"
    },
    

So we specify the minimal required version and with "^" the latest minor release will automatically be downloaded if available. And if we want to switch to a new major Blockly version, we only need to adjust the version number to the new major version number.

This allows us to keep our node easier up-to-date with future Blockly releases from Google.

P.S. the @blockly/field-date NPM package allows us now to implement a Date picker block (see here).

@cymplecy
Copy link
Collaborator

cymplecy commented May 29, 2021 via email

@jsccjj
Copy link
Contributor

jsccjj commented May 30, 2021

Same here. I will start looking into the code tonight

@bartbutenaers
Copy link
Owner Author

@cymplecy,
I think all 3 points have been implemented.
Can you please close this issue if it is all ok for you?

@cymplecy
Copy link
Collaborator

cymplecy commented Jun 8, 2021

All seem OK

@cymplecy cymplecy closed this as completed Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants