Ui_notification view in a only tab

Hey guys
I need help
I am using ui_notification in red node. But I don't want it to show on other tabs.
It should appear in a single tab.
Can you help me?

You can use a UI Template node associated to this tab, with a JS script section which issues an alert() command.
For example:

Try this

[{"id":"bb7ef9863eea1ea9","type":"ui_ui_control","z":"02ca79a9a08a0cf4","name":"","events":"all","x":200,"y":740,"wires":[["98f6f8872fac0320","854585b31749180e"]]},{"id":"f33a6678ec5c0348","type":"change","z":"02ca79a9a08a0cf4","name":"allow notifications","rules":[{"t":"set","p":"notifications","pt":"global","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":660,"wires":[[]]},{"id":"98f6f8872fac0320","type":"switch","z":"02ca79a9a08a0cf4","name":"check for dashboard changes","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"change","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":740,"wires":[["6392474fdfc3ea0f"],["6bc115b9e5e2ec8e"]]},{"id":"6392474fdfc3ea0f","type":"switch","z":"02ca79a9a08a0cf4","name":"allow notifications for tab 0 ","property":"tab","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":620,"y":680,"wires":[["f33a6678ec5c0348"],["6bc115b9e5e2ec8e"]]},{"id":"6bc115b9e5e2ec8e","type":"change","z":"02ca79a9a08a0cf4","name":"disable notifications","rules":[{"t":"set","p":"notifications","pt":"global","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":720,"wires":[[]]},{"id":"e9315c323af950c2","type":"ui_toast","z":"02ca79a9a08a0cf4","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"className":"","topic":"","name":"","x":870,"y":840,"wires":[]},{"id":"5d88b5eb9222e5a0","type":"inject","z":"02ca79a9a08a0cf4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello world","payloadType":"str","x":400,"y":840,"wires":[["e5107f52fa76871c"]]},{"id":"e5107f52fa76871c","type":"switch","z":"02ca79a9a08a0cf4","name":"if notifications enabled","property":"notifications","propertyType":"global","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":620,"y":840,"wires":[["e9315c323af950c2"]]},{"id":"854585b31749180e","type":"debug","z":"02ca79a9a08a0cf4","name":"Dashboard says","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":320,"y":680,"wires":[]}]

Perfect @hotNipi
But I have several users connected to the server, and your example is linked to screen switching. It can get confusing if one user doesn't switch screens and another does. :slight_smile:
but the idea was really good. thank you

Thank you for your help.
I was trying to get away from an html because I have no experience, but I think it's the only way.
Thanks

I don't see any options to send or limit notifications based on socket I'd so this seems to be end of story. It is not possible.

Notifications should only go to a single client if the socketId is included. It isn't a terribly robust mechanism though since many things can cause a client to get a new socket id.

1 Like

Can you help me?

this is my node:

[
{
"id": "10df8c489491addf",
"type": "ui_button",
"z": "c61d0d5905659bc7",
"name": "",
"group": "50e5db1fad5aad4a",
"order": 1,
"width": 3,
"height": 1,
"passthru": false,
"label": "OP",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "DIGITE A OP",
"payloadType": "str",
"topic": " ",
"topicType": "str",
"x": 70,
"y": 60,
"wires": [
[
"bcca6b5d3dda1e53"
]
]
},
{
"id": "bcca6b5d3dda1e53",
"type": "ui_toast",
"z": "c61d0d5905659bc7",
"position": "prompt",
"displayTime": "5",
"highlight": "",
"sendall": true,
"outputs": 1,
"ok": "OK",
"cancel": "CANCEL",
"raw": true,
"className": " ",
"topic": "",
"name": " OP",
"x": 230,
"y": 60,
"wires": [
[
"b069222f31e953af",
"2fe887e4857ec0bb",
"453135cd52728d3e"
]
]
},
{
"id": "b069222f31e953af",
"type": "change",
"z": "c61d0d5905659bc7",
"name": "",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "op_busca",
"tot": "global"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 170,
"y": 140,
"wires": [

]
},
{
"id": "50e5db1fad5aad4a",
"type": "ui_group",
"name": "SELECIONAR CONSULTA",
"tab": "01defd39958bdd2d",
"order": 1,
"disp": true,
"width": 15,
"collapse": false,
"className": ""
},
{
"id": "01defd39958bdd2d",
"type": "ui_tab",
"name": "CONSULTA PRODUÇÃO",
"icon": "find_in_page",
"order": 10,
"disabled": false,
"hidden": false
}
]

how change for ui_template? Thank you

Definitely useful info but didn't find anything in documents.
Anyway, that makes it kind of possible again...

[{"id":"bb7ef9863eea1ea9","type":"ui_ui_control","z":"02ca79a9a08a0cf4","name":"","events":"all","x":200,"y":1040,"wires":[["854585b31749180e","95883a3ea9e161b1"]]},{"id":"e9315c323af950c2","type":"ui_toast","z":"02ca79a9a08a0cf4","position":"top right","displayTime":"5","highlight":"","sendall":false,"outputs":0,"ok":"OK","cancel":"","raw":false,"className":"","topic":"","name":"","x":730,"y":1080,"wires":[]},{"id":"854585b31749180e","type":"debug","z":"02ca79a9a08a0cf4","name":"Dashboard says","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":400,"y":1040,"wires":[]},{"id":"c3e698e26b68d589","type":"inject","z":"02ca79a9a08a0cf4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello world from trigger node","payloadType":"str","x":210,"y":1080,"wires":[["a39eeb910b13efe8"]]},{"id":"95883a3ea9e161b1","type":"function","z":"02ca79a9a08a0cf4","name":"store dashboards states","func":"let dashboards = global.get('dashboards') || []\nswitch (msg.payload) {\n    case \"connect\":\n        dashboards.push({socketid:msg.socketid, tab:-1})\n        break;\n    case \"lost\":\n        dashboards = dashboards.filter(function (d) { return d.socketid != msg.socketid; });\n        break;\n    case \"change\":\n        let changed = false\n        dashboards.forEach(function(d) {\n            if(d.socketid == msg.socketid){\n                d.tab = msg.tab\n                changed = true\n            }            \n        });\n        if(!changed){\n            dashboards.push({ socketid: msg.socketid ,tab:msg.tab});\n        }\n        break;\n    default:\n        dashboards = []\n        \n}\n\nglobal.set('dashboards',dashboards);\n","outputs":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":1000,"wires":[]},{"id":"ea53ae149ba0da3e","type":"inject","z":"02ca79a9a08a0cf4","name":"clear on init","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":980,"wires":[["95883a3ea9e161b1"]]},{"id":"a39eeb910b13efe8","type":"function","z":"02ca79a9a08a0cf4","name":"check for connected dashboards tabs","func":"let allowedTab = 0;\nlet dashboards = global.get('dashboards') || []\n\ndashboards.forEach(function(d) {\n    if(d.tab === allowedTab){\n        node.send({payload:msg.payload,topic:msg.topic,socketid:d.socketid})\n    }\n});\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":1080,"wires":[["e9315c323af950c2"]]}]

You can use the following:

[
    {
        "id": "bde8e413e9664562",
        "type": "ui_template",
        "z": "cc0dc37e13d8db0a",
        "group": "50e5db1fad5aad4a",
        "name": "",
        "order": 1,
        "width": 0,
        "height": 0,
        "format": "<form>\n    <md-button style=\"background-color:gray;text-transform:none\" class=\"button\" ng-click=\"buttonClick()\"> OP </md-button>\n</form>\n\n<script>\nvar $scope = this.scope;\n\nthis.scope.buttonClick = function()\n{\n    let ok = confirm('OK to proceed?');\n    let newMsg = {};\n    if (ok)\n        newMsg.payload = \"OK\";\n    else\n        newMsg.payload = \"Cancel\";\n    \n    $scope.send(newMsg);\n}\n\n</script>",
        "storeOutMessages": false,
        "fwdInMessages": false,
        "resendOnRefresh": false,
        "templateScope": "local",
        "className": "",
        "x": 320,
        "y": 100,
        "wires": [
            [
                "b39e2c5ec3b1750e"
            ]
        ]
    },
    {
        "id": "b39e2c5ec3b1750e",
        "type": "debug",
        "z": "cc0dc37e13d8db0a",
        "name": "debug 57",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 460,
        "y": 100,
        "wires": []
    },
    {
        "id": "50e5db1fad5aad4a",
        "type": "ui_group",
        "name": "SELECIONAR CONSULTA",
        "tab": "01defd39958bdd2d",
        "order": 1,
        "disp": true,
        "width": 15,
        "collapse": false,
        "className": ""
    },
    {
        "id": "01defd39958bdd2d",
        "type": "ui_tab",
        "name": "CONSULTA PRODUÇÃO",
        "icon": "find_in_page",
        "order": 10,
        "disabled": false,
        "hidden": false
    }
]

Don't move your result to a global variable, as you might run into concurrency issues (race conditions)

I'm sure I remember seeing it somewhere. But worth remembering that Dashboard uses the Socket.IO library to manage its websocket connections. The id is managed by that library.

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