rikukissa / node-red-contrib-image-output

🏞 Easy way of previewing and examining images in your flows
MIT License
13 stars 6 forks source link

Activation button #17

Closed bartbutenaers closed 4 years ago

bartbutenaers commented 4 years ago

Hi @rikukissa , @dceejay ,

I have added an activation/deactivation button. When clicked, the images will be ignored (on the server-side) and not send - via the websocket channel - to the client side. This way you can add as many image-output nodes to your flow, without having to be worried the websocket channel is going to be overloaded.

P.S. This is a bit more convenient compared to "disabling" the node via the Node-RED disable button, since you can use the activation button "live"...

Here is a small demo (that automatically generates images in the cloud):

image_output_button

[{"id":"46ffc819.b736f8","type":"http request","z":"30fb1577.8f556a","name":"","method":"GET","ret":"bin","paytoqs":false,"url":"https://dummyimage.com/200x150/000/fff&text={{{payload}}}","tls":"","persist":false,"proxy":"","authType":"","x":610,"y":640,"wires":[["27a53fad.5c768"]]},{"id":"25d928c1.708098","type":"inject","z":"30fb1577.8f556a","name":"Generate next image","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":640,"wires":[["878f8ec1.effe4"]]},{"id":"878f8ec1.effe4","type":"function","z":"30fb1577.8f556a","name":"image counter","func":"var count = flow.get(\"count\")||0;\n\ncount++;\n\nnode.status({fill:\"blue\",shape:\"ring\",text:\"Image \" + count});\n\n// Save the new value back to context so it will be available next time\nflow.set('count',count);\n\n// Update the message payload and return - no need to create a new msg\nmsg.payload = \"Image \" + count;\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":640,"wires":[["46ffc819.b736f8"]]},{"id":"27a53fad.5c768","type":"base64","z":"30fb1577.8f556a","name":"","action":"str","property":"payload","x":780,"y":640,"wires":[["d603e881.2fa1c8"]]},{"id":"d603e881.2fa1c8","type":"image","z":"30fb1577.8f556a","name":"","width":160,"thumbnail":false,"x":960,"y":640,"wires":[]}]

I have one open issue, but don't know how to solve it ;(

To have no impact on existing flows, I would like to have the existing nodes to be activated by default. However these existing nodes don't have a node.active field yet, until the user opens the config screen. As a result:

dceejay commented 4 years ago

in the html file you need to add a function to the oneditprepare function, so if it's undefined... then you define it.

if ($("#node-input-active").val() === undefined) {
    $("#node-input-active").val(true);
    this.active = true;
}

Or something like that...