[Announce] little helper node for OK/Cancel dialog boxes with the notification node

Hi,
I had a little time today on my ride to the office and back ...

I don't know (but interested) how you work with the notification node. It`s a trivial task but I was looking for a universal solution. Perhaps this one? No custom node, only a little subflow:

Every comment or improvement welcome.

[{"id":"fd36bbc4.fe50d8","type":"subflow","name":"OK/Cancel helper","info":"# OK/Cancel dialog helper\n\n## description\n\nThis is a little helper to make OK/Cancel dialogs easy to implement inside a data stream\n\n## how it works\n\nIf a message arrives at the **imput** a message dialog box is triggered. The original Message is cloned into `msg.dialogHelperOrgMsg`. If the dialog sends `msg.payload` with the **passPayload** the original message is released on the second output.\n\n## configuration\n\n- **Title** ***optional** a string displayed on the title of the dialog\n- **Message** message to be displayed\n- **passPayload** the `msg.payload` expected on the imput to release to original message.","category":"","in":[{"x":37,"y":85,"wires":[{"id":"6a44f1d4.72a75"}]}],"out":[{"x":343,"y":85,"wires":[{"id":"6a44f1d4.72a75","port":1}]},{"x":343,"y":136,"wires":[{"id":"6a44f1d4.72a75","port":2}]}],"env":[{"name":"title","type":"str","value":"Please Confirm","ui":{"icon":"font-awesome/fa-comment","label":{"en-US":"Title"},"type":"input","opts":{"types":["str","env"]}}},{"name":"message","type":"str","value":"should the message pass on?","ui":{"icon":"font-awesome/fa-comment-o","label":{"en-US":"Message"},"type":"input","opts":{"types":["str","env"]}}},{"name":"passPayload","type":"str","value":"OK","ui":{"icon":"font-awesome/fa-check-square-o","type":"input","opts":{"types":["str","env"]},"label":{}}}],"color":"#3FADB5","icon":"font-awesome/fa-comments-o","status":{"x":343,"y":34,"wires":[{"id":"6a44f1d4.72a75","port":0}]}},{"id":"6a44f1d4.72a75","type":"function","z":"fd36bbc4.fe50d8","name":"confirm","func":"var status={fill:\"\",shape:\"dot\",text:\"\"};\nif (msg!==undefined && !msg.hasOwnProperty(\"dialogHelperOrgMsg\")) { // no message in queue\n    var dialogMsg={\n        topic:env.get('title'),\n        payload:env.get('message'),\n        socketid:msg.socketid,\n        dialogHelperOrgMsg:RED.util.cloneMessage(msg)\n    };\n    status={fill:\"yellow\",shape:\"dot\",text:\"waiting for response\"};\n    return [{payload:status},dialogMsg,null];\n} else {\n    if (msg.payload===env.get('passPayload')) {\n        status={fill:\"green\",shape:\"dot\",text:\"message passed\"};\n        return [{payload:status},null,msg.dialogHelperOrgMsg];\n    } else {\n        status={fill:\"blue\",shape:\"dot\",text:msg.payload+\" (!\"+env.get('passPayload')+\") message droped\"};\n        return [{payload:status},null,null];\n    }\n}","outputs":3,"noerr":0,"x":196,"y":85,"wires":[[],[],[]],"info":"# OK/Cancel dialog helper function\n\n## description\n\nThis is a little helper to make OK/Cancel dialogs easy to implement inside a data stream\n\n## how it works\n\nIf a message arrives at the **imput** a message dialog box is triggered. The original Message is cloned into `msg.dialogHelperOrgMsg`. If the dialog sends `msg.payload` with the **passPayload** the original message is released on the second output.\n\n## envioment variables\n\n- **title** ***optional** a string displayed on the title of the dialog\n- **message** message to be displayed\n- **passPayload** the `msg.payload` expected on the imput to release to original message."},{"id":"4d72ffb9.cfb97","type":"ui_toast","z":"4ddb981f.f34df8","position":"dialog","displayTime":"3","highlight":"","sendall":false,"outputs":1,"ok":"OK","cancel":"Cancel","raw":false,"topic":"","name":"OK / Cancel","x":784,"y":527,"wires":[["a757d8b6.692258"]]},{"id":"a757d8b6.692258","type":"subflow:fd36bbc4.fe50d8","z":"4ddb981f.f34df8","name":"dialog helper","env":[{"name":"message","value":"should the message pass?","type":"str"}],"x":597,"y":578,"wires":[["4d72ffb9.cfb97"],["eaab52bd.831cb"]]},{"id":"6a4fcd8.cd5fb34","type":"inject","z":"4ddb981f.f34df8","name":"Click and switch to the dashboard","topic":"Let's test this","payload":"Let me pass, please!","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":351,"y":578,"wires":[["a757d8b6.692258"]]},{"id":"eaab52bd.831cb","type":"debug","z":"4ddb981f.f34df8","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":764,"y":612,"wires":[]}]

OK/Cancel dialog helper

description

This is a little helper to make OK/Cancel dialogs easy to implement inside a data stream

how it works

If a message arrives at the imput a message dialog box is triggered. The original Message is cloned into msg.dialogHelperOrgMsg. If the notification node sends msg.payload with the passPayload the original message is released on the second output. If not the message is dropped.

configuration

  • Title optional a string displayed on the title of the dialog
  • Message message to be displayed
  • passPayload the msg.payload expected on the imput to release to original message (OK).
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.