hobbyquaker / node-red-contrib-polymer

A Polymer based Dashboard UI for Node-RED
MIT License
21 stars 0 forks source link

Reset of widget attributes #44

Open M0ebiu5 opened 7 years ago

M0ebiu5 commented 7 years ago

It should be possible to reset the attributes of a widget to the initial state from the settings dialogue. eg: after showing some errors with different colors or labels, a quick restore is possible.

It's also important because other nodes cannot read the attributes of a certain widget to save the original state, so that the restore can only be done manually.

hobbyquaker commented 7 years ago

So you mean you wanna reset via msg also or only in the options editor? Via msg this should already work if you set an attribute to null - then it should revert to its default value.

M0ebiu5 commented 7 years ago

I mean reset via msg - null does not work for "label" (empty).

M0ebiu5 commented 7 years ago

Hmmm, during testing v0.0.18, resetting the color stoped working. Here is a little sample, which shows that the color isn't restored. As side effect, you can see the effort to implement a countdown button (but, maybe it's only my lack of programming skill, so it shows event that :)) image

[ { "id": "88283593.848aa8", "type": "tab", "label": "Flow 4" }, { "id": "d519500.1290fb", "type": "polymer_nav_site", "z": "88283593.848aa8", "name": "Polytest", "title": "Polytest", "theme": "dark", "css": ".bigpage {\n font-size: 300%;\n}\n\n.sprit {\n text-align: left;\n width:700px;\n margin: 10px auto;\n}\n\n.afhtml {\n color: white;\n text-align: center;\n} \n\n.afhtml a:link {\n color: yellow;\n}\n\n.afhtml a:visited {\n color: lightgreen;\n}\n\n.node-red-collapse {\n justify-content: initial !important;\n}\n\n", "forceNarrow": true, "saveScroll": true, "fixed": true, "reveals": false, "pageOrder": [], "x": 700, "y": 151, "wires": [ [] ] }, { "id": "907dc4bd.e0f988", "type": "polymer_nav_page", "z": "88283593.848aa8", "name": "Garage", "title": "Garage", "parent": "d519500.1290fb", "class": "", "icon": "", "groupOrder": [], "x": 704, "y": 212, "wires": [ [] ] }, { "id": "c2941b59.922988", "type": "polymer_nav_group", "z": "88283593.848aa8", "name": "gGarage", "parent": "907dc4bd.e0f988", "class": "", "title": "", "elementOrder": [], "x": 703, "y": 266, "wires": [] }, { "id": "34f57002.b0463", "type": "polymer_paper-button", "z": "88283593.848aa8", "element": "polymer_paper-button", "name": "Tür absperren", "label": "Tür absperren", "class": "", "color": "#ffffff", "colorActive": true, "bgColor": "#ff0000", "bgColorActive": false, "parent": "c2941b59.922988", "repeat": "1", "width": "100%", "height": "", "icon": "", "topic": "btn", "payload": "cnt", "payloadType": "str", "raised": true, "x": 711, "y": 318, "wires": [ [ "c86fb455.734ce8" ] ] }, { "id": "c86fb455.734ce8", "type": "function", "z": "88283593.848aa8", "name": "Countdown", "func": "var state = context.get('state') || 0;\nvar msgb = {}\nvar msgd = {}\nvar msga = {}\n\nif (msg.topic === \"btn\") {\n if (state > 0) {\n state = 0; //reset\n msgb = {\"payload\": {\"color\": null,\"label\": \"Tür absperren\"}};\n msgd = null;\n }\n else {\n state = 10; //init\n msgb = {\"payload\": {\"color\": \"red\", \"label\": \"Absperren in \" + state + \" sec...\" }}\n msgd = {\"topic\": \"tmr\"};\n }\n context.set('state',state);\n return [msgb,msgd,msga];\n}\n\nif (msg.topic === \"tmr\") {\n if (state > 0) {\n state--;\n if (state === 0) \n msgb = {\"payload\": {\"label\": \"Absperren!\"}};\n else\n msgb = {\"payload\": {\"label\": \"Absperren in \" + state + \" sec...\"}};\n msgd = {\"topic\": \"tmr\"};\n }\n else { \n state = 0; //reset\n msgb = {\"payload\": {\"color\": null,\"label\": \"Tür absperren\"}}\n msgd = null;\n }\n context.set('state',state);\n return [msgb,msgd,msga];\n}\n\n//do not come in here!\nreturn null;", "outputs": "3", "noerr": 0, "x": 708, "y": 385, "wires": [ [ "34f57002.b0463" ], [ "6a1d2e5.c3b6cd" ], [] ] }, { "id": "6a1d2e5.c3b6cd", "type": "delay", "z": "88283593.848aa8", "name": "", "pauseType": "delay", "timeout": "1", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "x": 709, "y": 458, "wires": [ [ "c86fb455.734ce8" ] ] } ]