Configuring a dashboard tab in response to a URL

Thanks @Nxito,
You have solved my problem.

I have it slightly different from your flows. But it is now working well. I put the whole solution here for those who may want it.
image

  1. The top flow stores the URL that is called the first time the idpicker's Group tab is displayed. (It doesn't actualy display anything on the Group tab)
  2. The second line receives the URL request, parses the parameters and creates two messages.
    a) The first message responds with the stored URL inside an <iFrame>
    b) The second message contains the parameters from the URL request and can be passed to something else in your flow.

Here are the nodes

[{"id":"d708dc8e.a89f1","type":"http in","z":"89aed991.562928","name":"/history url handler","url":"/ui/history/:params","method":"get","upload":false,"swaggerDoc":"","x":190,"y":200,"wires":[["f42bc357.beb1b"]]},{"id":"3882eb1b.c1dd74","type":"debug","z":"89aed991.562928","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":240,"wires":[]},{"id":"67706912.8ce228","type":"http response","z":"89aed991.562928","name":"","statusCode":"","headers":{},"x":770,"y":200,"wires":[]},{"id":"f42bc357.beb1b","type":"function","z":"89aed991.562928","name":"Set historic data","func":"//the url will arrive as http::local/history/&type=someType&date=someDate\nvar parameters = {};\nfor ( entry of msg.req.params.params.split(\"&\")) \n{\n  pair = entry.split(\"=\");\n  parameters[pair[0]] = pair[1];\n}\nvar type = parameters[\"type\"];\nvar date = parameters[\"date\"];\n\n\nmsg.url = flow.get(\"Node-red-Url\")|| \"no url\"\n//msg2 is for configuring your flow using the passed in parameteres from the URL\nmsg2 = {payload:\"From URL\", type:type, date:date };\n\nreturn [msg, msg2];","outputs":2,"noerr":0,"x":400,"y":200,"wires":[["19fcb2b9.83b4dd"],["3882eb1b.c1dd74"]]},{"id":"63ef29e2.05a538","type":"comment","z":"89aed991.562928","name":"Handle external URLs","info":"","x":200,"y":80,"wires":[]},{"id":"76dd4ee2.e4d0b","type":"ui_template","z":"89aed991.562928","group":"45a87283.4150ac","name":"idpicker","order":1,"width":"0","height":"0","format":"<div id=\"idpickertable\" ng-init=\"send(action())\"><!-- it is called at the start-->\n</div>\n<script>\n    var url= parent.document.location.href\n    var obj = {\"Url\":url};\n    this.scope.action = function() { return obj; }\n</script>\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":160,"y":140,"wires":[["336f0644.28756a"]]},{"id":"336f0644.28756a","type":"function","z":"89aed991.562928","name":"Store full socketid url","func":"//Only store the first URL received. Future URLs could be external such as ./history/&type=type&date=date\n//store the full URL e.g http::local/#!/0?socketid=74hSZxlqHVZwQ1_iAAD9\nvar url= msg.Url\nif( url.includes(\"socketid\") ) \n    flow.set(\"Node-red-Url\",url);\nreturn msg","outputs":1,"noerr":0,"x":420,"y":140,"wires":[["2d1ef00f.ed848"]]},{"id":"19fcb2b9.83b4dd","type":"template","z":"89aed991.562928","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<http>\n<head>\n<style type=\"text/css\">\n    body {scrolling:no;}\n    iframe {position:absolute;\n    z-index:1;\n    top:0px;\n    left:0px;\n}\n</style>\n</head>\n<body>\n    <iframe src={{url}} height=\"100%\" width=\"100%\" frameborder=\"0\"></iframe>\n</body>    \n</http>","output":"str","x":620,"y":200,"wires":[["67706912.8ce228"]]},{"id":"2d1ef00f.ed848","type":"debug","z":"89aed991.562928","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":140,"wires":[]},{"id":"45a87283.4150ac","type":"ui_group","z":"","name":"Testing","tab":"dadd1654.354a78","order":1,"disp":true,"width":"17","collapse":false},{"id":"dadd1654.354a78","type":"ui_tab","z":"","name":"Testing","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

Note that I changed the URL parameter format from my initial post example. You can now try https://shannstainable.fewings.org/historic/&type=power&date=20191219

2 Likes