Last active
April 16, 2022 10:01
-
-
Save padaVVan/9690bedc14a800798c2b69fc515b16e3 to your computer and use it in GitHub Desktop.
Store node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "379ce8c6.8e5b08", | |
"type": "subflow", | |
"name": "Store", | |
"info": "", | |
"category": "", | |
"in": [ | |
{ | |
"x": 116, | |
"y": 128, | |
"wires": [ | |
{ | |
"id": "c2d6373b.87b848" | |
} | |
] | |
} | |
], | |
"out": [ | |
{ | |
"x": 948, | |
"y": 96, | |
"wires": [ | |
{ | |
"id": "cdb43a53.0abdd8", | |
"port": 0 | |
} | |
] | |
}, | |
{ | |
"x": 948, | |
"y": 144, | |
"wires": [ | |
{ | |
"id": "6d26eb8a.950424", | |
"port": 0 | |
} | |
] | |
} | |
], | |
"env": [ | |
{ | |
"name": "attribute", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"icon": "font-awesome/fa-anchor", | |
"label": { | |
"en-US": "Attribute" | |
}, | |
"type": "input", | |
"opts": { | |
"types": [ | |
"str", | |
"env" | |
] | |
} | |
} | |
}, | |
{ | |
"name": "send_on_start", | |
"type": "bool", | |
"value": "false", | |
"ui": { | |
"icon": "font-awesome/fa-upload", | |
"label": { | |
"en-US": "Send on start" | |
}, | |
"type": "checkbox" | |
} | |
}, | |
{ | |
"name": "default", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"icon": "font-awesome/fa-thumb-tack", | |
"label": { | |
"en-US": "Default" | |
} | |
} | |
} | |
], | |
"color": "#DDAA99", | |
"status": { | |
"x": 948, | |
"y": 192, | |
"wires": [ | |
{ | |
"id": "30e7a5c8.ebdf7a", | |
"port": 0 | |
} | |
] | |
} | |
}, | |
{ | |
"id": "e37544d7.235948", | |
"type": "function", | |
"z": "379ce8c6.8e5b08", | |
"name": "storing", | |
"func": "let attributeName = flow.get('name');\n\n// Валидация имени аттрибута\nif (!attributeName.length) {\n throw new Error(\"Укажите наименование аттрибута\", msg)\n}\n\nif (msg.payload === undefined) {\n msg.payload = env.get('default');\n}\n\nlet oldValue = global.get(attributeName);\nlet newValue = msg.payload;\n\n// Устанавливание новое значение в сторе\nglobal.set(attributeName, newValue);\n\n// Статус\nnode.status({text: newValue});\n\n// Если новое значение отличается от старого\n// То пишем в порт изменения новое значение\nif (oldValue != newValue) {\n return [msg, msg];\n}\n\n// Иначе пишем старое значение только в порт установки значения\nreturn [null, msg];", | |
"outputs": 2, | |
"noerr": 0, | |
"initialize": "// Code added here will be run once\n// whenever the node is deployed.\nnode.status({text: \"Setup\"});", | |
"finalize": "", | |
"libs": [], | |
"x": 642, | |
"y": 128, | |
"wires": [ | |
[ | |
"c5d952ca.d1cd3" | |
], | |
[ | |
"b1c3dda6.c5b46" | |
] | |
] | |
}, | |
{ | |
"id": "30e7a5c8.ebdf7a", | |
"type": "status", | |
"z": "379ce8c6.8e5b08", | |
"name": "", | |
"scope": [ | |
"e37544d7.235948", | |
"4c08af66.6e5f" | |
], | |
"x": 652, | |
"y": 192, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "ea8ace97.c4266", | |
"type": "inject", | |
"z": "379ce8c6.8e5b08", | |
"name": "", | |
"props": [], | |
"repeat": "", | |
"crontab": "", | |
"once": true, | |
"onceDelay": 0.1, | |
"topic": "", | |
"x": 146, | |
"y": 64, | |
"wires": [ | |
[ | |
"a3c3c43.18b6438" | |
] | |
] | |
}, | |
{ | |
"id": "7f804aed.a82c74", | |
"type": "switch", | |
"z": "379ce8c6.8e5b08", | |
"name": "is send on start", | |
"property": "send_on_start", | |
"propertyType": "env", | |
"rules": [ | |
{ | |
"t": "true" | |
} | |
], | |
"checkall": "true", | |
"repair": false, | |
"outputs": 1, | |
"x": 464, | |
"y": 64, | |
"wires": [ | |
[ | |
"4c08af66.6e5f" | |
] | |
] | |
}, | |
{ | |
"id": "cdb43a53.0abdd8", | |
"type": "link in", | |
"z": "379ce8c6.8e5b08", | |
"name": "", | |
"links": [ | |
"ca5ff98a.1c6c08", | |
"c5d952ca.d1cd3" | |
], | |
"x": 863, | |
"y": 96, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "6d26eb8a.950424", | |
"type": "link in", | |
"z": "379ce8c6.8e5b08", | |
"name": "", | |
"links": [ | |
"b1c3dda6.c5b46", | |
"ca5ff98a.1c6c08" | |
], | |
"x": 863, | |
"y": 144, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "c5d952ca.d1cd3", | |
"type": "link out", | |
"z": "379ce8c6.8e5b08", | |
"name": "", | |
"links": [ | |
"cdb43a53.0abdd8" | |
], | |
"x": 751, | |
"y": 112, | |
"wires": [] | |
}, | |
{ | |
"id": "b1c3dda6.c5b46", | |
"type": "link out", | |
"z": "379ce8c6.8e5b08", | |
"name": "", | |
"links": [ | |
"6d26eb8a.950424" | |
], | |
"x": 751, | |
"y": 144, | |
"wires": [] | |
}, | |
{ | |
"id": "ca5ff98a.1c6c08", | |
"type": "link out", | |
"z": "379ce8c6.8e5b08", | |
"name": "", | |
"links": [ | |
"cdb43a53.0abdd8", | |
"6d26eb8a.950424" | |
], | |
"x": 751, | |
"y": 64, | |
"wires": [] | |
}, | |
{ | |
"id": "4c08af66.6e5f", | |
"type": "function", | |
"z": "379ce8c6.8e5b08", | |
"name": "status", | |
"func": "// Статус\nnode.status({text: msg.payload});\n\nreturn [msg];", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"x": 642, | |
"y": 64, | |
"wires": [ | |
[ | |
"ca5ff98a.1c6c08" | |
] | |
] | |
}, | |
{ | |
"id": "c2d6373b.87b848", | |
"type": "function", | |
"z": "379ce8c6.8e5b08", | |
"name": "default", | |
"func": "// Статус\nif (msg.payload === undefined) {\n msg.payload = env.get('default')\n}\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 290, | |
"y": 128, | |
"wires": [ | |
[ | |
"e37544d7.235948" | |
] | |
] | |
}, | |
{ | |
"id": "a3c3c43.18b6438", | |
"type": "function", | |
"z": "379ce8c6.8e5b08", | |
"name": "default", | |
"func": "// Статус\n\nlet name = env.get('attribute')\nif (name === undefined || name.length === 0) {\n flow.set('name', node.path.split('/').reverse()[1])\n} else {\n flow.set('name', name)\n}\n\nmsg.payload = global.get(flow.get('name'))\n\nif (msg.payload === undefined) {\n msg.payload = env.get('default')\n global.set(flow.get('name'), msg.payload)\n}\n\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 290, | |
"y": 64, | |
"wires": [ | |
[ | |
"7f804aed.a82c74" | |
] | |
] | |
}, | |
{ | |
"id": "52cc859fa5ce6448", | |
"type": "subflow:379ce8c6.8e5b08", | |
"z": "1b722add.8cbf75", | |
"name": "", | |
"x": 206, | |
"y": 4592, | |
"wires": [ | |
[], | |
[] | |
] | |
} | |
] |
Author
padaVVan
commented
Apr 16, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment