Hello everyone,
I'm recent in using node red and I have the following question.
In my project, I'm listing the contents of a directory in a UI_table and I have check boxes that allow selecting one or more lines. However I need to have a button for select/deselect all.
I leave my flow below if someone can help.
Thanks to everyone and congratulations for your contribution to the community
[
{
"id": "f0ac6e667fc173d9",
"type": "tab",
"label": "Download",
"disabled": false,
"info": ""
},
{
"id": "40ce0bd9496ea3c6",
"type": "function",
"z": "f0ac6e667fc173d9",
"name": "",
"func": "//var user = global.get(\"user\")\n//var ip = global.get(\"host\")\n//var cmd = \"whoami\";\n//var file = {};\n//var status = {};\n \nmsg.payload = `scp pi@10.42.0.2:/home/pi/animalTAGS/data/logs/datalog--2021-6-30--11-54--0.csv /data/`;\n \nreturn msg\n\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 260,
"y": 80,
"wires": [
[
"9e76d69ac90056ab"
]
]
},
{
"id": "9e76d69ac90056ab",
"type": "exec",
"z": "f0ac6e667fc173d9",
"command": "",
"addpay": "payload",
"append": "",
"useSpawn": "false",
"timer": "5",
"winHide": false,
"oldrc": false,
"name": "",
"x": 390,
"y": 80,
"wires": [
[
"5d6b37170365daa9"
],
[],
[]
]
},
{
"id": "3b810f98cb3ecee8",
"type": "ui_button",
"z": "f0ac6e667fc173d9",
"name": "",
"group": "2768d5bb10e62e93",
"order": 3,
"width": 0,
"height": 0,
"passthru": false,
"label": "Update Files List",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 110,
"y": 280,
"wires": [
[
"b6828ff0e97ee852",
"658e66209e05b0f5"
]
]
},
{
"id": "0ece2307eb0c58ad",
"type": "inject",
"z": "f0ac6e667fc173d9",
"name": "",
"props": [
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 110,
"y": 180,
"wires": [
[
"b6828ff0e97ee852"
]
]
},
{
"id": "d5de889f057ef535",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "func",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 690,
"y": 60,
"wires": []
},
{
"id": "5d6b37170365daa9",
"type": "function",
"z": "f0ac6e667fc173d9",
"name": "",
"func": "//var user = global.get(\"user\")\n//var ip = global.get(\"host\")\n//var cmd = \"whoami\";\n//var file = {};\n//var status = {};\n \nmsg.payload = `scp /data/datalog--2021-6-30--11-54--0.csv miguelsoares@10.42.0.1:/home/miguelsoares/Desktop`;\n\n \nreturn msg\n\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 540,
"y": 60,
"wires": [
[
"d5de889f057ef535"
]
]
},
{
"id": "b6828ff0e97ee852",
"type": "function",
"z": "f0ac6e667fc173d9",
"name": "",
"func": "var user = global.get(\"user\");\nvar ip = global.get(\"host\");\nvar cmd1 = \"ls\";\nvar cmd2 = \"-lvh\";\nvar dir = \"/home/pi/animalTAGS/data/videos/\";\nvar header1 =\"| awk '{print $5 \";\nvar header2 = '\"->\"';\nvar header3 = \" $9}'\";\nvar file = {};\nvar status = {};\n \n//ssh pi@10.42.0.2 ls /home/pi/animalTAGS/data/videos/ -lvh | awk '{print $5 \" -> \" $9}'\nmsg.payload = `ssh ${user}@${ip} ${cmd1} ${dir} ${cmd2} ${header1}${header2}${header3}`;\n \nreturn msg;\n\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 300,
"y": 200,
"wires": [
[
"0812e650858b0358"
]
]
},
{
"id": "0812e650858b0358",
"type": "exec",
"z": "f0ac6e667fc173d9",
"command": "",
"addpay": "payload",
"append": "",
"useSpawn": "false",
"timer": "10",
"winHide": false,
"oldrc": false,
"name": "",
"x": 450,
"y": 200,
"wires": [
[
"63b569e1e53b2802",
"aa32606ab2d36c43"
],
[],
[]
]
},
{
"id": "63b569e1e53b2802",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "debug_LS",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 570,
"y": 300,
"wires": []
},
{
"id": "aa32606ab2d36c43",
"type": "json",
"z": "f0ac6e667fc173d9",
"name": "",
"property": "payload",
"action": "str",
"pretty": true,
"x": 630,
"y": 180,
"wires": [
[
"c02d050c2abb6c2e",
"0f5afe1072fec061"
]
]
},
{
"id": "3070a972d0a0cec1",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "js",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 930,
"y": 300,
"wires": []
},
{
"id": "c02d050c2abb6c2e",
"type": "split",
"z": "f0ac6e667fc173d9",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": "1",
"arraySpltType": "len",
"stream": false,
"addname": "key",
"x": 770,
"y": 180,
"wires": [
[
"3070a972d0a0cec1",
"50352d57a13aa964"
]
]
},
{
"id": "50352d57a13aa964",
"type": "function",
"z": "f0ac6e667fc173d9",
"name": "",
"func": "var data=msg.payload;\nvar temp=data.split(\"->\");\nmsg.file_size=temp[0];\nmsg.file_name=temp[1];\n\nreturn msg;\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 920,
"y": 180,
"wires": [
[
"8a73d7aed4f0c188",
"b1e1f66e4419d48d"
]
]
},
{
"id": "0f5afe1072fec061",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "debug_json",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 750,
"y": 300,
"wires": []
},
{
"id": "44599119a368ca93",
"type": "ui_table",
"z": "f0ac6e667fc173d9",
"group": "870a91418c5861d1",
"name": "",
"order": 1,
"width": 10,
"height": 7,
"columns": [],
"outputs": 1,
"cts": true,
"x": 1210,
"y": 360,
"wires": [
[
"2154edb51d899a58",
"785c9fd83e7be407",
"afac46f550f2172f"
]
]
},
{
"id": "8a73d7aed4f0c188",
"type": "function",
"z": "f0ac6e667fc173d9",
"name": "updateOrAddData (add)",
"func": "var check=msg.file_size;\nif(check===\"\"){\n return null; \n}\nelse {\n var id=flow.get(\"lastId\") || 0;\n ++id;\n msg.payload={\n command:\"updateOrAddData\",\n arguments: [\n [\n {\n \"id\":id,\n \"filesize\":msg.file_size,\n \"filename\":msg.file_name,\n \"check_box\":false\n }\n ]\n ],\n returnPromise: true\n }\n flow.set(\"lastId\",id);\n return msg;\n}\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1130,
"y": 180,
"wires": [
[
"2afe27d64fd9d669",
"56e34c6dd19c7e1f"
]
],
"info": "# updateOrAddData([row])\n\nadds a the row with a new id (same as addRow)"
},
{
"id": "6c4c6d5e44c1aead",
"type": "inject",
"z": "f0ac6e667fc173d9",
"name": "format table",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 110,
"y": 440,
"wires": [
[
"658e66209e05b0f5"
]
]
},
{
"id": "658e66209e05b0f5",
"type": "change",
"z": "f0ac6e667fc173d9",
"name": "",
"rules": [
{
"t": "set",
"p": "ui_control",
"pt": "msg",
"to": "{\"customHeight\":12,\"tabulator\":{\"columns\":[{\"title\":\" <div style='text-align:center'>#</div>\",\"field\":\"id\",\"width\":5,\"formatter\":\"rownum\",\"align\":\"center\"},{\"title\":\" <div style='text-align:center'>File Size</div>\",\"field\":\"filesize\",\"align\":\"center\",\"formatter\":\"text\",\"width\":100,\"layout\":\"fitData\"},{\"title\":\" <div style='text-align:center'>File Name</div>\",\"field\":\"filename\",\"formatter\":\"text\",\"width\":330,\"sorter\":\"alphanum\",\"sorterParams\":{\"alignEmptyValues\":\"bottom\"},\"layout\":\"fitData\",\"align\":\"center\"},{\"title\":\"\",\"field\":\"check_box\",\"width\":5,\"formatter\":\"tickCross\",\"formatterParams\":{\"target\":\"_blank\",\"allowEmpty\":true,\"allowTruthy\":true,\"tickElement\":\"<i class='fa fa-check-square-o fa-1x'></i>\",\"crossElement\":\"<i class='fa fa-square-o fa-1x'></i>\"},\"align\":\"center\"}],\"initialSort\":[{\"column\":\"filename\",\"dir\":\"asc\"}],\"setSort\":[{\"column\":\"filename\",\"dir\":\"asc\"}],\"layout\":\"fitColumns\",\"movableColumns\":false,\"resizableColumns\":false,\"headerVisible\":true,\"headerSort\":false,\"autoColumns\":false,\"selectable\":true}}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 330,
"y": 360,
"wires": [
[
"44599119a368ca93"
]
]
},
{
"id": "2154edb51d899a58",
"type": "switch",
"z": "f0ac6e667fc173d9",
"name": "",
"property": "payload.check_box",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 410,
"y": 520,
"wires": [
[
"39a1f890d6922b15"
],
[
"605ec706105cb760"
]
]
},
{
"id": "39a1f890d6922b15",
"type": "change",
"z": "f0ac6e667fc173d9",
"name": "change_icon_false",
"rules": [
{
"t": "set",
"p": "payload.check_box",
"pt": "msg",
"to": "false",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 590,
"y": 500,
"wires": [
[
"20d5d68ff73ed577"
]
]
},
{
"id": "605ec706105cb760",
"type": "change",
"z": "f0ac6e667fc173d9",
"name": "change_icon_true",
"rules": [
{
"t": "set",
"p": "payload.check_box",
"pt": "msg",
"to": "true",
"tot": "bool"
},
{
"t": "set",
"p": "change_icon",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 590,
"y": 540,
"wires": [
[
"063f4ca61b41d4c3"
]
]
},
{
"id": "063f4ca61b41d4c3",
"type": "switch",
"z": "f0ac6e667fc173d9",
"name": "",
"property": "change_icon",
"propertyType": "msg",
"rules": [
{
"t": "null"
},
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 790,
"y": 540,
"wires": [
[],
[
"20d5d68ff73ed577"
],
[]
]
},
{
"id": "20d5d68ff73ed577",
"type": "function",
"z": "f0ac6e667fc173d9",
"name": "update_data",
"func": "var id = msg.payload.id\n\nmsg.payload={\n command:\"updateOrAddData\",\n arguments: [\n [\n {\n \"id\":id,\n \"filesize\":msg.file_size,\n \"filename\":msg.file_name,\n \"check_box\":msg.payload.check_box\n }\n ]\n ],\n returnPromise: true\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1110,
"y": 520,
"wires": [
[
"658e66209e05b0f5"
]
],
"info": "# updateOrAddData([row])\n\nupdates a the row with an id in the middle from 1 to lastId, hope it exists!\nIf not a row will be added"
},
{
"id": "b1e1f66e4419d48d",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "js",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1090,
"y": 240,
"wires": []
},
{
"id": "2afe27d64fd9d669",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "check_blanks",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1400,
"y": 80,
"wires": []
},
{
"id": "bbd1a8e0279a419e",
"type": "switch",
"z": "f0ac6e667fc173d9",
"name": "",
"property": "return.arguments[0][0].check_box",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1510,
"y": 360,
"wires": [
[
"2fc9567e0d90dc95"
],
[
"1e4734db8a9e6825"
]
]
},
{
"id": "5739cb8cfed70545",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "concat",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1950,
"y": 340,
"wires": []
},
{
"id": "785c9fd83e7be407",
"type": "switch",
"z": "f0ac6e667fc173d9",
"name": "",
"property": "return.command",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "updateOrAddData",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 1370,
"y": 360,
"wires": [
[
"bbd1a8e0279a419e"
]
]
},
{
"id": "afac46f550f2172f",
"type": "change",
"z": "f0ac6e667fc173d9",
"name": "",
"rules": [
{
"t": "move",
"p": "payload.filesize",
"pt": "msg",
"to": "filesize",
"tot": "flow"
},
{
"t": "move",
"p": "payload.filename",
"pt": "msg",
"to": "filename",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1400,
"y": 420,
"wires": [
[]
]
},
{
"id": "2fc9567e0d90dc95",
"type": "function",
"z": "f0ac6e667fc173d9",
"name": "",
"func": "msg.payload=flow.get(\"filename\");\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1640,
"y": 300,
"wires": [
[
"295423132774751e",
"2c5d048c1153bc6b"
]
]
},
{
"id": "295423132774751e",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1690,
"y": 360,
"wires": []
},
{
"id": "1e4734db8a9e6825",
"type": "function",
"z": "f0ac6e667fc173d9",
"name": "",
"func": "var arr=flow.get(\"selected_array\");\nvar value = flow.get(\"filename\");\n\nfunction removeItemOnce(arr, value) {\n var index = arr.indexOf(value);\n if (index > -1) {\n arr.splice(index, 1);\n }\n return arr;\n}\n\nmsg.payload=removeItemOnce(arr, value);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1650,
"y": 420,
"wires": [
[
"4399bb92ab057975"
]
]
},
{
"id": "a81faf8bd0a44154",
"type": "change",
"z": "f0ac6e667fc173d9",
"name": "",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "selected_array",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1990,
"y": 240,
"wires": [
[]
]
},
{
"id": "4399bb92ab057975",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "selected_dw",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1690,
"y": 480,
"wires": []
},
{
"id": "2c5d048c1153bc6b",
"type": "function",
"z": "f0ac6e667fc173d9",
"name": "concat",
"func": "var arr = flow.get(\"selected_array\");\nvar value = msg.payload;\n\n\nmsg.payload=arr.concat(value);\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1810,
"y": 300,
"wires": [
[
"a81faf8bd0a44154",
"5739cb8cfed70545"
]
]
},
{
"id": "56e34c6dd19c7e1f",
"type": "change",
"z": "f0ac6e667fc173d9",
"name": "",
"rules": [
{
"t": "set",
"p": "selected_array",
"pt": "flow",
"to": "[]",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1340,
"y": 240,
"wires": [
[
"44599119a368ca93"
]
]
},
{
"id": "ddcc4658deb88732",
"type": "ui_button",
"z": "f0ac6e667fc173d9",
"name": "",
"group": "2768d5bb10e62e93",
"order": 4,
"width": 0,
"height": 0,
"passthru": false,
"label": "Set Files For Download",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 1630,
"y": 560,
"wires": [
[
"c8b3477f13671566"
]
]
},
{
"id": "c8b3477f13671566",
"type": "change",
"z": "f0ac6e667fc173d9",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "selected_array",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1840,
"y": 560,
"wires": [
[
"8ae438fbf7b0f1db"
]
]
},
{
"id": "8ae438fbf7b0f1db",
"type": "split",
"z": "f0ac6e667fc173d9",
"name": "Split array",
"splt": "\\n",
"spltType": "str",
"arraySplt": "1",
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 2000,
"y": 560,
"wires": [
[
"ca59221821fc89c7"
]
]
},
{
"id": "ca59221821fc89c7",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 2150,
"y": 560,
"wires": []
},
{
"id": "1c6cf2e317868d1a",
"type": "function",
"z": "f0ac6e667fc173d9",
"name": "",
"func": "function toggle(source) {\n var checkboxes = document.querySelectorAll('input[type=\"checkbox\"]');\n for (var i = 0; i < checkboxes.length; i++) {\n if (checkboxes[i] != source)\n checkboxes[i].checked = source.checked;\n }\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1050,
"y": 680,
"wires": [
[
"b18e2c5c8b2c7459"
]
]
},
{
"id": "b55751b892fa15b4",
"type": "ui_button",
"z": "f0ac6e667fc173d9",
"name": "",
"group": "2768d5bb10e62e93",
"order": 4,
"width": 0,
"height": 0,
"passthru": false,
"label": "Select All Files",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 880,
"y": 680,
"wires": [
[
"1c6cf2e317868d1a"
]
]
},
{
"id": "b18e2c5c8b2c7459",
"type": "debug",
"z": "f0ac6e667fc173d9",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1190,
"y": 680,
"wires": []
},
{
"id": "960b6ba012d7ced2",
"type": "ui_spacer",
"z": "f0ac6e667fc173d9",
"name": "spacer",
"group": "2768d5bb10e62e93",
"order": 1,
"width": 6,
"height": 1
},
{
"id": "0a70b37758bc78b8",
"type": "ui_spacer",
"z": "f0ac6e667fc173d9",
"name": "spacer",
"group": "2768d5bb10e62e93",
"order": 2,
"width": 6,
"height": 1
},
{
"id": "2768d5bb10e62e93",
"type": "ui_group",
"name": "Group 1",
"tab": "94ff3c5caa315fa9",
"order": 1,
"disp": false,
"width": 6,
"collapse": false,
"className": ""
},
{
"id": "870a91418c5861d1",
"type": "ui_group",
"name": "List of files in directory",
"tab": "94ff3c5caa315fa9",
"order": 2,
"disp": true,
"width": "10",
"collapse": false,
"className": ""
},
{
"id": "94ff3c5caa315fa9",
"type": "ui_tab",
"name": "Download",
"icon": "fa-cloud-download fa-2x",
"order": 4,
"disabled": false,
"hidden": false
}
]