@semilimes/node-red-semilimes
Advanced tools
Comparing version 0.9.4 to 0.9.5
@@ -236,2 +236,2 @@ [ | ||
} | ||
] | ||
] |
@@ -11,2 +11,20 @@ [ | ||
{ | ||
"id": "c96f4fe387066a5d", | ||
"type": "group", | ||
"z": "03f230443c464b5e", | ||
"name": "Local processing", | ||
"style": { | ||
"label": true | ||
}, | ||
"nodes": [ | ||
"e209e805b09415e8", | ||
"bc637f7410c849d5", | ||
"936084037c176bf7" | ||
], | ||
"x": 74, | ||
"y": 799, | ||
"w": 652, | ||
"h": 82 | ||
}, | ||
{ | ||
"id": "fa6f0ce1f5bb3e30", | ||
@@ -86,3 +104,3 @@ "type": "inject", | ||
"z": "03f230443c464b5e", | ||
"connector": "", | ||
"connector": "fa4257e98eaed462", | ||
"async": "0", | ||
@@ -121,3 +139,3 @@ "x": 570, | ||
"z": "03f230443c464b5e", | ||
"name": "", | ||
"name": "Send New Form Message", | ||
"props": [ | ||
@@ -139,3 +157,3 @@ { | ||
"payloadType": "date", | ||
"x": 160, | ||
"x": 210, | ||
"y": 380, | ||
@@ -156,3 +174,3 @@ "wires": [ | ||
"title": "Lamp control panel", | ||
"x": 760, | ||
"x": 700, | ||
"y": 380, | ||
@@ -176,3 +194,3 @@ "wires": [ | ||
"valueType": "msg", | ||
"x": 730, | ||
"x": 670, | ||
"y": 420, | ||
@@ -203,8 +221,7 @@ "wires": [ | ||
"stepType": "num", | ||
"x": 740, | ||
"x": 680, | ||
"y": 460, | ||
"wires": [ | ||
[ | ||
"00a8ea7c327d2c9d", | ||
"6cc5dfcca8f2f468" | ||
"0b2bb1bf856bf412" | ||
] | ||
@@ -227,3 +244,3 @@ ] | ||
"refNameType": "msg", | ||
"x": 530, | ||
"x": 490, | ||
"y": 380, | ||
@@ -253,4 +270,4 @@ "wires": [ | ||
"channelIdType": "str", | ||
"x": 1030, | ||
"y": 440, | ||
"x": 1090, | ||
"y": 460, | ||
"wires": [ | ||
@@ -275,4 +292,4 @@ [ | ||
"statusType": "auto", | ||
"x": 1520, | ||
"y": 440, | ||
"x": 1240, | ||
"y": 540, | ||
"wires": [] | ||
@@ -284,6 +301,6 @@ }, | ||
"z": "03f230443c464b5e", | ||
"connector": "", | ||
"connector": "fa4257e98eaed462", | ||
"async": "0", | ||
"x": 1290, | ||
"y": 440, | ||
"x": 1170, | ||
"y": 500, | ||
"wires": [ | ||
@@ -330,25 +347,8 @@ [ | ||
{ | ||
"id": "00a8ea7c327d2c9d", | ||
"type": "function", | ||
"z": "03f230443c464b5e", | ||
"name": "Save Form", | ||
"func": "var formRefName = msg._sme.sendingMsgs[0].dataComponent.refName;\nflow.set('savedFormRefName', formRefName);\nflow.set(formRefName, msg._sme.sendingMsgs[0].dataComponent);\nreturn msg;", | ||
"outputs": 1, | ||
"noerr": 0, | ||
"initialize": "", | ||
"finalize": "", | ||
"libs": [], | ||
"x": 970, | ||
"y": 500, | ||
"wires": [ | ||
[] | ||
] | ||
}, | ||
{ | ||
"id": "3f090137152dcd32", | ||
"type": "comment", | ||
"z": "03f230443c464b5e", | ||
"name": "Step 2: Send a control form to the channel and save its form reference name and the message Id for further updates", | ||
"name": "Step 2: Send a control form to the channel and save its form and the message Id for further updates", | ||
"info": "", | ||
"x": 470, | ||
"x": 420, | ||
"y": 260, | ||
@@ -371,8 +371,8 @@ "wires": [] | ||
"z": "03f230443c464b5e", | ||
"connector": "", | ||
"connector": "fa4257e98eaed462", | ||
"x": 170, | ||
"y": 600, | ||
"y": 660, | ||
"wires": [ | ||
[ | ||
"5a73a7b38e6ad3ff" | ||
"3a2497f836e72e1e" | ||
] | ||
@@ -382,8 +382,60 @@ ] | ||
{ | ||
"id": "5a73a7b38e6ad3ff", | ||
"id": "e209e805b09415e8", | ||
"type": "function", | ||
"z": "03f230443c464b5e", | ||
"g": "c96f4fe387066a5d", | ||
"name": "Send values to lamp", | ||
"func": "var valuesArr = msg.savedSubmission.submission.formComponents;\n\nmsg.payload = {};\nvar lampSwitch = valuesArr.find(o => o.refName == \"myLampSwitch\");\nvar lampDimmer = valuesArr.find(o => o.refName == \"myLampDimmer\");\n\nmsg.payload.lampSwitch = {\n refName: lampSwitch.refName,\n value: lampSwitch.value\n};\n\nmsg.payload.lampDimmer = {\n refName: lampDimmer.refName,\n value: lampDimmer.value\n};\n\nreturn msg;", | ||
"outputs": 1, | ||
"timeout": "", | ||
"noerr": 0, | ||
"initialize": "", | ||
"finalize": "", | ||
"libs": [], | ||
"x": 200, | ||
"y": 840, | ||
"wires": [ | ||
[ | ||
"bc637f7410c849d5" | ||
] | ||
] | ||
}, | ||
{ | ||
"id": "91ca047551d8ae8a", | ||
"type": "function", | ||
"z": "03f230443c464b5e", | ||
"name": "Random Form Id", | ||
"func": "msg.formReference = \"form\"+Date.now();\n\nreturn msg;", | ||
"outputs": 1, | ||
"noerr": 0, | ||
"initialize": "", | ||
"finalize": "", | ||
"libs": [], | ||
"x": 270, | ||
"y": 480, | ||
"wires": [ | ||
[ | ||
"a56f9ae41e78f648" | ||
] | ||
] | ||
}, | ||
{ | ||
"id": "e7a8a880c6b45291", | ||
"type": "comment", | ||
"z": "03f230443c464b5e", | ||
"name": "Listen to submission for the saved form, extract values and send to lamp, update and send the form to achieve statefulness", | ||
"info": "", | ||
"x": 490, | ||
"y": 560, | ||
"wires": [] | ||
}, | ||
{ | ||
"id": "3a2497f836e72e1e", | ||
"type": "sme-filter-formSubmission", | ||
"z": "03f230443c464b5e", | ||
"reference": "savedFormRefName", | ||
"reference": "mySavedForm.refName", | ||
"referenceType": "flow", | ||
"x": 300, | ||
"saveLocation": "savedSubmission", | ||
"saveLocationType": "msg", | ||
"x": 450, | ||
"y": 660, | ||
@@ -397,8 +449,74 @@ "wires": [ | ||
{ | ||
"id": "e209e805b09415e8", | ||
"id": "0b2bb1bf856bf412", | ||
"type": "sme-main-formSaver", | ||
"z": "03f230443c464b5e", | ||
"location": "mySavedForm", | ||
"locationType": "flow", | ||
"x": 870, | ||
"y": 460, | ||
"wires": [ | ||
[ | ||
"6cc5dfcca8f2f468" | ||
] | ||
] | ||
}, | ||
{ | ||
"id": "3bf47a245e003ea3", | ||
"type": "sme-main-formLoader", | ||
"z": "03f230443c464b5e", | ||
"location": "mySavedForm", | ||
"locationType": "flow", | ||
"x": 1050, | ||
"y": 700, | ||
"wires": [ | ||
[ | ||
"98ad87a92732964b" | ||
] | ||
] | ||
}, | ||
{ | ||
"id": "bc637f7410c849d5", | ||
"type": "delay", | ||
"z": "03f230443c464b5e", | ||
"g": "c96f4fe387066a5d", | ||
"name": "Simulate hw delay", | ||
"pauseType": "delay", | ||
"timeout": "1", | ||
"timeoutUnits": "seconds", | ||
"rate": "1", | ||
"nbRateUnits": "1", | ||
"rateUnits": "second", | ||
"randomFirst": "1", | ||
"randomLast": "5", | ||
"randomUnits": "seconds", | ||
"drop": false, | ||
"allowrate": false, | ||
"outputs": 1, | ||
"x": 430, | ||
"y": 840, | ||
"wires": [ | ||
[ | ||
"936084037c176bf7" | ||
] | ||
] | ||
}, | ||
{ | ||
"id": "b29fe19a8f16fa99", | ||
"type": "comment", | ||
"z": "03f230443c464b5e", | ||
"name": "In this example, a dimmer set to 0 will bring the lamp switch to off", | ||
"info": "", | ||
"x": 310, | ||
"y": 600, | ||
"wires": [] | ||
}, | ||
{ | ||
"id": "936084037c176bf7", | ||
"type": "function", | ||
"z": "03f230443c464b5e", | ||
"name": "Retrieve received values", | ||
"func": "var dataComponent = msg.payload.submission.eventBody.dataComponent;\n\nvar messageId = dataComponent.replyTo.messageId;\nvar refName = dataComponent.replyTo.refName;\nvar formComponents = dataComponent.formComponents;\n\nformComponents.forEach(function(comp) {\n var finalValue;\n if (comp.value !== undefined) {\n if (comp.refName == \"myLampSwitch\") {\n finalValue = comp.value == 1 ? true : false;\n }\n else {\n finalValue = comp.value;\n } \n msg.payload[comp.refName] = finalValue;\n }\n});\n\nreturn msg;", | ||
"g": "c96f4fe387066a5d", | ||
"name": "Lamp logic", | ||
"func": "//Dimmer is 0, force switch to 0 (off)\nif (msg.payload.lampSwitch.value == 1 &&\n msg.payload.lampDimmer.value == 0) {\n msg.payload.lampSwitch.value = 0;\n}\n\nreturn msg;", | ||
"outputs": 1, | ||
"timeout": "", | ||
"noerr": 0, | ||
@@ -409,6 +527,25 @@ "initialize": "", | ||
"x": 630, | ||
"y": 840, | ||
"wires": [ | ||
[ | ||
"396030b411e16a98" | ||
] | ||
] | ||
}, | ||
{ | ||
"id": "396030b411e16a98", | ||
"type": "sme-main-formUpdater", | ||
"z": "03f230443c464b5e", | ||
"name": "Update Switch Value", | ||
"location": "mySavedForm", | ||
"locationType": "flow", | ||
"compRefName": "payload.lampSwitch.refName", | ||
"compRefNameType": "msg", | ||
"compValue": "payload.lampSwitch.value", | ||
"compValueType": "msg", | ||
"x": 820, | ||
"y": 660, | ||
"wires": [ | ||
[ | ||
"511340c73a26ab73" | ||
"a33b65627d65a086" | ||
] | ||
@@ -418,6 +555,64 @@ ] | ||
{ | ||
"id": "511340c73a26ab73", | ||
"id": "a33b65627d65a086", | ||
"type": "sme-main-formUpdater", | ||
"z": "03f230443c464b5e", | ||
"name": "Update Dimmer Value", | ||
"location": "mySavedForm", | ||
"locationType": "flow", | ||
"compRefName": "payload.lampDimmer.refName", | ||
"compRefNameType": "msg", | ||
"compValue": "payload.lampDimmer.value", | ||
"compValueType": "msg", | ||
"x": 840, | ||
"y": 720, | ||
"wires": [ | ||
[ | ||
"3bf47a245e003ea3" | ||
] | ||
] | ||
}, | ||
{ | ||
"id": "98ad87a92732964b", | ||
"type": "sme-main-actionSelector", | ||
"z": "03f230443c464b5e", | ||
"actionName": "channel_message_update", | ||
"recipientId": "", | ||
"recipientIdType": "str", | ||
"messageId": "savedSubmission.submission.replyTo.messageId", | ||
"messageIdType": "msg", | ||
"limit": 0, | ||
"limitType": "num", | ||
"recipientIds": "", | ||
"recipientIdsType": "str", | ||
"groupChatId": "", | ||
"groupChatIdType": "str", | ||
"channelId": "52cd6010-4d7d-46f3-9d7c-4286b5cf1600", | ||
"channelIdType": "str", | ||
"x": 1180, | ||
"y": 760, | ||
"wires": [ | ||
[ | ||
"1c1da4e77b720db5" | ||
] | ||
] | ||
}, | ||
{ | ||
"id": "1c1da4e77b720db5", | ||
"type": "sme-main-sender", | ||
"z": "03f230443c464b5e", | ||
"connector": "fa4257e98eaed462", | ||
"async": "0", | ||
"x": 1270, | ||
"y": 820, | ||
"wires": [ | ||
[ | ||
"7e4b042ba957e9ab" | ||
] | ||
] | ||
}, | ||
{ | ||
"id": "7e4b042ba957e9ab", | ||
"type": "debug", | ||
"z": "03f230443c464b5e", | ||
"name": "Check values", | ||
"name": "debug 51", | ||
"active": true, | ||
@@ -431,35 +626,16 @@ "tosidebar": true, | ||
"statusType": "auto", | ||
"x": 880, | ||
"y": 660, | ||
"x": 1360, | ||
"y": 880, | ||
"wires": [] | ||
}, | ||
{ | ||
"id": "91ca047551d8ae8a", | ||
"type": "function", | ||
"z": "03f230443c464b5e", | ||
"name": "Random Form Id", | ||
"func": "msg.formReference = \"form\"+Date.now();\n\nreturn msg;", | ||
"outputs": 1, | ||
"noerr": 0, | ||
"initialize": "", | ||
"finalize": "", | ||
"libs": [], | ||
"x": 270, | ||
"y": 480, | ||
"wires": [ | ||
[ | ||
"a56f9ae41e78f648" | ||
] | ||
] | ||
}, | ||
{ | ||
"id": "e7a8a880c6b45291", | ||
"id": "92d232876967a4d7", | ||
"type": "comment", | ||
"z": "03f230443c464b5e", | ||
"name": "Listen to submission for the saved form and extract values", | ||
"info": "", | ||
"x": 290, | ||
"y": 560, | ||
"name": "Read this", | ||
"info": "The filter submission node saves:\n\n1. The messageId of the original form message.\nThis is useful to update a message with updated form values\n\n2. The refName of the form to identify which form has been filtered\n\n3. the formComponents of the submitted form, containing the actual settings and values of each component.\nThis is then extracted for local processing.\nLocal values can be reentered in an existing form and sent back to semilimes, using the original messageId", | ||
"x": 420, | ||
"y": 700, | ||
"wires": [] | ||
} | ||
] |
{ | ||
"name": "@semilimes/node-red-semilimes", | ||
"version": "0.9.4", | ||
"version": "0.9.5", | ||
"description": "The new semilimes connector which integrates with the public API", | ||
@@ -9,3 +9,3 @@ "scripts": { | ||
"author": "Davide Ribezzo", | ||
"license": "ISC", | ||
"license": "Apache-2.0", | ||
"node-red": { | ||
@@ -20,2 +20,5 @@ "version": ">=2.0.0", | ||
"sme-main-sshTunnel": "src/sme-main-sshTunnel.js", | ||
"sme-main-formSaver": "src/sme-main-formSaver.js", | ||
"sme-main-formLoader": "src/sme-main-formLoader.js", | ||
"sme-main-formUpdater": "src/sme-main-formUpdater.js", | ||
"sme-comp-text": "src/data-components/sme-comp-text.js", | ||
@@ -22,0 +25,0 @@ "sme-comp-html": "src/data-components/sme-comp-html.js", |
@@ -12,2 +12,4 @@ "use strict"; | ||
this.referenceType = config.referenceType; | ||
this.saveLocation = config.saveLocation; | ||
this.saveLocationType = config.saveLocationType; | ||
@@ -22,3 +24,5 @@ var node = this; | ||
var smeReceivedMsg = smeHelper.getReceivedMsg(msg); | ||
var referenceValue = smeHelper.getNodeConfigValue(node, msg, node.referenceType, node.reference); | ||
console.log("referenceValue: ", referenceValue); | ||
//filter submissions | ||
var isMatchedSubmissionMessage = | ||
@@ -31,5 +35,4 @@ smeReceivedMsg && | ||
if (isMatchedSubmissionMessage && node.reference) { | ||
var referenceValue = smeHelper.getNodeConfigValue(node, msg, node.referenceType, node.reference); | ||
node.log(`Node reference is: ${referenceValue}`); | ||
if (isMatchedSubmissionMessage && referenceValue) { | ||
//filter submissions by form reference | ||
isMatchedSubmissionMessage = | ||
@@ -41,5 +44,25 @@ smeReceivedMsg.eventBody.dataComponent.replyTo && | ||
if (isMatchedSubmissionMessage) { | ||
msg = {}; | ||
msg.payload = {}; | ||
msg.payload.submission = smeReceivedMsg; | ||
if (node.saveLocation) { | ||
//Location specified: extract values and save into location | ||
var submission = { | ||
submission: { | ||
replyTo: smeReceivedMsg.eventBody.dataComponent.replyTo, | ||
formComponents: smeReceivedMsg.eventBody.dataComponent.formComponents | ||
} | ||
} | ||
switch (node.saveLocationType) { | ||
case 'msg': | ||
msg[node.saveLocation] = submission; | ||
break; | ||
case 'flow': | ||
node.context().flow.set(node.saveLocation, submission); | ||
break; | ||
case 'global': | ||
node.context().global.set(node.saveLocation, submission); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
send(msg, false); | ||
@@ -53,2 +76,2 @@ } | ||
RED.nodes.registerType("sme-filter-formSubmission", SmeFilterFormSubmissionNode); | ||
}; | ||
}; |
@@ -79,5 +79,5 @@ "use strict"; | ||
var limitValue = smeHelper.getNodeConfigValue(node, msg, node.limitType, node.limit); | ||
if (recipientIdValue) request.parameters.recipientId = msg.recipientId || recipientIdValue; | ||
if (messageIdValue) request.parameters.messageId = msg.messageId || messageIdValue; | ||
if (limitValue) request.parameters.limit = msg.limit || limitValue; | ||
if (recipientIdValue) request.parameters.recipientId = recipientIdValue; | ||
if (messageIdValue) request.parameters.messageId = messageIdValue; | ||
if (limitValue) request.parameters.limit = limitValue; | ||
smeHelper.addSendingMsg(msg, request); | ||
@@ -94,3 +94,3 @@ break; | ||
smeMsg.body = { | ||
recipientId: msg.recipientId || recipientIdValue, | ||
recipientId: recipientIdValue, | ||
dataComponent: smeMsg.dataComponent | ||
@@ -111,3 +111,3 @@ }; | ||
smeMsg.body = { | ||
messageId: msg.messageId || messageIdValue, | ||
messageId: messageIdValue, | ||
dataComponent: smeMsg.dataComponent | ||
@@ -150,5 +150,5 @@ }; | ||
var limitValue = smeHelper.getNodeConfigValue(node, msg, node.limitType, node.limit); | ||
if (groupChatIdValue) request.parameters.groupChatId = msg.groupChatId || groupChatIdValue; | ||
if (messageIdValue) request.parameters.messageId = msg.messageId || messageIdValue; | ||
if (limitValue) request.parameters.limit = msg.limit || limitValue; | ||
if (groupChatIdValue) request.parameters.groupChatId = groupChatIdValue; | ||
if (messageIdValue) request.parameters.messageId = messageIdValue; | ||
if (limitValue) request.parameters.limit = limitValue; | ||
smeHelper.addSendingMsg(msg, request); | ||
@@ -165,3 +165,3 @@ break; | ||
smeMsg.body = { | ||
groupChatId: msg.groupChatId || groupChatIdValue, | ||
groupChatId: groupChatIdValue, | ||
dataComponent: smeMsg.dataComponent | ||
@@ -182,3 +182,3 @@ }; | ||
smeMsg.body = { | ||
messageId: msg.messageId || messageIdValue, | ||
messageId: messageIdValue, | ||
dataComponent: smeMsg.dataComponent | ||
@@ -213,3 +213,3 @@ }; | ||
smeMsg.body = { | ||
channelId: msg.channelId || channelIdValue, | ||
channelId: channelIdValue, | ||
dataComponent: smeMsg.dataComponent | ||
@@ -230,3 +230,3 @@ }; | ||
smeMsg.body = { | ||
messageId: msg.messageId || messageIdValue, | ||
messageId: messageIdValue, | ||
dataComponent: smeMsg.dataComponent | ||
@@ -233,0 +233,0 @@ }; |
@@ -140,3 +140,20 @@ "use strict"; | ||
function getNodeConfigValue(node, msg, selectionType, selectionValue) { | ||
if (selectionType && selectionValue) { | ||
//Function to make nested properties work in UI | ||
const leaf = (obj, path) => { | ||
if (path.startsWith('.')) { | ||
path = path.substring(1); | ||
} | ||
return path.length > 0 | ||
? (path.split('.').reduce((value,el) => value && value[el], obj)) | ||
: obj; | ||
} | ||
var firstProperty = String(selectionValue).split('.')[0]; | ||
var searchPath = String(selectionValue).replace(`${firstProperty}`, ''); | ||
console.log("SelectionValue: ", selectionValue); | ||
console.log("firstProperty: ",firstProperty); | ||
console.log("searchPath: ", searchPath); | ||
switch (selectionType) { | ||
@@ -147,5 +164,8 @@ case 'str': return selectionValue; | ||
case 'json': return JSON.parse(selectionValue); | ||
case 'msg': return msg[selectionValue]; | ||
case 'flow': return node && node.context().flow.get(selectionValue); | ||
case 'global': return node && node.context().global.get(selectionValue); | ||
//case 'msg': return msg[selectionValue]; | ||
case 'msg': return leaf(msg[firstProperty], searchPath); | ||
//case 'flow': return node && node.context().flow.get(selectionValue); | ||
case 'flow': return node && leaf(node.context().flow.get(firstProperty), searchPath); | ||
//case 'global': return node && node.context().global.get(selectionValue); | ||
case 'global': return node && leaf(node.context().global.get(firstProperty), searchPath); | ||
} | ||
@@ -152,0 +172,0 @@ } |
@@ -16,3 +16,3 @@ "use strict"; | ||
var clonedMsg = JSON.parse(JSON.stringify(smeMsg)); | ||
var nodeRedMsg = { payload: smeMsg }; | ||
var nodeRedMsg = { payload: null }; | ||
@@ -19,0 +19,0 @@ var core = new Core(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
429302
83
0
3375