Hello,
I'm looking to create sort of a configuration page with Dashboard 2.0.
This page should contain multiple text input nodes, a button to save the entered values and a table which displays the last changes made for each input (sort of a log).
My flow currently looks like this:
[{"id":"ab144c1b47805573","type":"ui-button","z":"e97c3811a2016996","group":"842e73ead28eb5a2","name":"Save","label":"Save","order":4,"width":"1","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"{}","payloadType":"global","topic":"save_button","topicType":"str","buttonColor":"","textColor":"","iconColor":"","x":770,"y":160,"wires":[["4441392ccf74dfce"]]},{"id":"39566cf71386f044","type":"ui-text-input","z":"e97c3811a2016996","group":"842e73ead28eb5a2","name":"Input_1","label":"Input_1","order":1,"width":"2","height":"1","topic":"input_1","topicType":"str","mode":"number","tooltip":"","delay":300,"passthru":true,"sendOnDelay":false,"sendOnBlur":true,"sendOnEnter":true,"className":"","clearable":false,"sendOnClear":false,"icon":"","iconPosition":"left","iconInnerPosition":"inside","x":780,"y":200,"wires":[["4441392ccf74dfce"]]},{"id":"4e0cf6449f1be04a","type":"ui-text-input","z":"e97c3811a2016996","group":"842e73ead28eb5a2","name":"Input_2","label":"Input_2","order":2,"width":"2","height":"1","topic":"input_2","topicType":"str","mode":"text","tooltip":"","delay":300,"passthru":true,"sendOnDelay":false,"sendOnBlur":true,"sendOnEnter":true,"className":"","clearable":false,"sendOnClear":false,"icon":"","iconPosition":"left","iconInnerPosition":"inside","x":780,"y":240,"wires":[["4441392ccf74dfce"]]},{"id":"21e7299682a26d77","type":"inject","z":"e97c3811a2016996","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":430,"y":140,"wires":[["aa019c43f81e650f"]]},{"id":"4441392ccf74dfce","type":"join","z":"e97c3811a2016996","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":true,"accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":970,"y":220,"wires":[["033651c71b59da29"]]},{"id":"033651c71b59da29","type":"switch","z":"e97c3811a2016996","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"save_button","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1010,"y":260,"wires":[["9aeb2934ba9d42de"]]},{"id":"fa29a859d522e80f","type":"function","z":"e97c3811a2016996","name":"prefill inputs","func":"//let jsonData = JSON.parse(msg.payload);\n//node.warn(jsonData);\nnode.warn(msg.payload);\nnode.warn(msg.payload.input_1);\nnode.warn(msg.payload.input_2);\nnode.warn(msg.payload.input_3);\n\n/*msg.payload = {\n input_1: jsonData.input_1,\n input_2: jsonData.input_2,\n input_3: jsonData.input_3\n};*/\n\nreturn [\n { payload: msg.payload.input_1 },\n { payload: msg.payload.input_2 },\n { payload: msg.payload.input_3 }\n];","outputs":3,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":240,"wires":[["39566cf71386f044"],["4e0cf6449f1be04a"],["947ae92045eb2e50"]],"outputLabels":["Input_1","Input_2","Input_3"]},{"id":"9aeb2934ba9d42de","type":"change","z":"e97c3811a2016996","name":"","rules":[{"t":"set","p":"#:(persistent)::configuration","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":260,"wires":[[]]},{"id":"aa019c43f81e650f","type":"change","z":"e97c3811a2016996","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"#:(persistent)::configuration","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":180,"wires":[["fa29a859d522e80f"]]},{"id":"947ae92045eb2e50","type":"ui-text-input","z":"e97c3811a2016996","group":"842e73ead28eb5a2","name":"Input_3","label":"Input_3","order":3,"width":"2","height":"1","topic":"input_3","topicType":"str","mode":"text","tooltip":"","delay":300,"passthru":true,"sendOnDelay":false,"sendOnBlur":true,"sendOnEnter":true,"className":"","clearable":false,"sendOnClear":false,"icon":"","iconPosition":"left","iconInnerPosition":"inside","x":780,"y":280,"wires":[["4441392ccf74dfce"]]},{"id":"842e73ead28eb5a2","type":"ui-group","name":"My Group","page":"8f25a3ecd25384a8","width":"6","height":"1","order":1,"showTitle":false,"className":"","visible":"true","disabled":"false"},{"id":"8f25a3ecd25384a8","type":"ui-page","name":"Configration","ui":"48b78019ef2446aa","path":"/configuration","icon":"home","layout":"grid","theme":"cf0f3291020d08d9","order":5,"className":"","visible":"true","disabled":"false"},{"id":"48b78019ef2446aa","type":"ui-base","name":"My Dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false,"showPageTitle":true,"navigationStyle":"icon","titleBarStyle":"default"},{"id":"cf0f3291020d08d9","type":"ui-theme","name":"Default Theme","colors":{"surface":"#ffffff","primary":"#0094CE","bgPage":"#eeeeee","groupBg":"#ffffff","groupOutline":"#cccccc"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]
I set the msg.payload to the value of persistent global.configuration, which I want to use to store the values saved from the dashboard, and push the value for each input field to a corresponding output of the function node to load the stored values into the ui.
The save button sets a msg.topic as "save_button", which is used in the switch node to check if the button has been clicked. The change node afterwards should persist the changed values to the context store.
My problem is, that so far only the changed values are stored in the context. If I only update input_1 via the dashboard, then the context only stores the value for that input, essentially loosing the values for the other inputs.
What do I need to change in my flow to make it save all the values? Maybe my current flow is badly designed for that task to begin with (it is my first experience with node red)? I would be happy to know if there are things I could improve.
I'm also a bit lost on how to create a row in a table for each change made to a saved value of an input field. I want the table to look like this:
The logs should also be persisted.
How can I do this?
Thank you for your help!