I am want to make a button that closes the dashboard

47 views
Skip to first unread message

Preben Østerlid

unread,
May 25, 2017, 4:28:10 AM5/25/17
to Node-RED
I suppose it is relatively simple, but I dont know how.

Any ideas?

Function or Template node?  Javascript or html?

/Preben

Librae

unread,
May 25, 2017, 5:34:37 AM5/25/17
to Node-RED
I use 3 nodes to do this trick.
FYI


script in template node​:

<script>
(function(scope) {
    scope.$watch('msg', function(msg) {
        if (msg.payload === 'close') {
            window.close();
        }
    });
})(scope);
</script>

raw flow source:
--
[{"id":"3ee86b68.3e4214","type":"ui_button","z":"d4db6128.68b55","name":"","group":"54b54612.4b5058","order":0,"width":0,"height":0,"passthru":false,"label":"close","color":"","bgcolor":"","icon":"","payload":"close","payloadType":"str","topic":"","x":390,"y":80,"wires":[["d5a441ec.84b5"]]},{"id":"d5a441ec.84b5","type":"ui_template","z":"d4db6128.68b55","group":"54b54612.4b5058","name":"","order":0,"width":0,"height":0,"format":"<script>\n(function(scope) {\n    scope.$watch('msg', function(msg) {\n        if (msg.payload === 'close') {\n            window.close();\n        }\n    });\n})(scope);\n</script>","storeOutMessages":false,"fwdInMessages":false,"x":550,"y":80,"wires":[[]]},{"id":"eec33938.157738","type":"ui_ui_control","z":"d4db6128.68b55","name":"ui control","x":380,"y":40,"wires":[["d5a441ec.84b5"]]},{"id":"54b54612.4b5058","type":"ui_group","name":"Group 1","tab":"4a83afb9.5089e","order":1,"disp":true,"width":6},{"id":"4a83afb9.5089e","type":"ui_tab","name":"Tab 1","icon":"dashboard","order":1}]

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/ce377400-a936-45af-a6ae-a52fb3bf481a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Librae

unread,
May 25, 2017, 5:45:09 AM5/25/17
to Node-RED
​Along with this topic, doesn't matter to Preben's question, I'd like to raise a small issue.

There I used one 'ui control' node. Odd.
Without this, each time the dashboard ui page does refresh​, the close action will be triggered.
That is, even without press the 'close' button, template node still receives msg.

I checked the details by printing the raw msg, and find out the socketid still bound to previous session.
Here's the corresponding browser console log:



Does anyone encountered this?

Thanks,
Librae

Preben Østerlid

unread,
May 25, 2017, 11:12:38 AM5/25/17
to Node-RED
Hmm - the sample code does nothing in my setup.
The button shows up, but nothing happens when I push it.

/Preben
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages