Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback - Refactor Feedback function and update feedback example #281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions examples/feedback.json → examples/Feedback.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
[
{
"id": "46f4b9ae1c66c1ba",
"type": "tab",
"label": "Flow 4",
"disabled": false,
"info": "",
"env": []
},
{
"id": "c643e022.1816c",
"type": "worldmap",
Expand Down Expand Up @@ -63,7 +55,7 @@
"type": "function",
"z": "46f4b9ae1c66c1ba",
"name": "add new rectangle",
"func": "\nmsg.payload = {\"command\":{\"bounds\":[[49.83682820280039,-4.019763692204326],[51.4723362586149,1.1741268015945219]]}};\nnode.send(msg);\nmsg.payload = {\"command\":{\"zoom\":9.7}};\nnode.send(msg);\n\n\nvar popup = \"<button name=\\\"B1name\\\" onclick='feedback(\\\"${name}\\\",\\\"${name} sends {x} Hellow\\\",\\\"myAction\\\",true);'>Hellow1 from ${name}</button>\";\npopup += \"<button name=\\\"B2name\\\" onclick='feedback(this.name,\\\"${name} sends {x} Hellow\\\",\\\"myAction\\\",true);'>Hellow2 from ${name}</button>\";\n\nvar points = [ { \"lat\": 50.66, \"lng\": -1.59 }, { \"lat\": 50.60, \"lng\": -1.47 } ] ;\nmsg.payload = {\n popup: popup.replace(/\\{x\\}/,\"popup\"),\n contextmenu: popup.replace(/\\{x\\}/, \"context\"),\n name: \"myShape\",\n area: points,\n clickable:true,\n };\nnode.send(msg);\n\nmsg.payload = {\n popup: popup,\n contextmenu: popup,\n name: \"myMarker\",\n lat: 50.40,\n lon: -1.0,\n weight: 1,\n};\nnode.send(msg);\nreturn msg;",
"func": "\nmsg.payload = {\"command\":{\"bounds\":[[49.83682820280039,-4.019763692204326],[51.4723362586149,1.1741268015945219]]}};\nnode.send(msg);\nmsg.payload = {\"command\":{\"zoom\":9.7}};\nnode.send(msg);\n\n\nvar popup = \"<button name=\\\"B1name\\\" onclick='feedback(\\\"${name}\\\", this.name + \\\" sends {x} Hellow\\\",\\\"myAction\\\",true);'>Hellow1 from ${name}</button>\";\npopup += \"<button name=\\\"B2name\\\" onclick='feedback(\\\"${name}\\\", this.name + \\\" sends {x} Hellow\\\",\\\"myAction\\\",true);'>Hellow2 from ${name}</button>\";\n\nvar points = [ { \"lat\": 50.66, \"lng\": -1.59 }, { \"lat\": 50.60, \"lng\": -1.47 } ] ;\nmsg.payload = {\n popup: popup.replace(/\\{x\\}/g,\"popup\"),\n contextmenu: popup.replace(/\\{x\\}/g, \"context\"),\n name: \"myShape\",\n area: points,\n clickable:true,\n };\nnode.send(msg);\n\nmsg.payload = {\n popup: popup.replace(/\\{x\\}/g,\"popup\"),\n contextmenu: popup.replace(/\\{x\\}/g, \"context\"),\n name: \"myMarker\",\n lat: 50.40,\n lon: -1.0,\n weight: 1,\n};\nnode.send(msg);\nmsg.payload.command = {\n contextmenu: popup.replace(/\\{x\\}/g,\"context\")\n};\nnode.send(msg);\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
Expand Down
59 changes: 40 additions & 19 deletions worldmap/worldmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,30 +864,51 @@ var addThing = function() {

var form = {};
var addToForm = function(n,v) { form[n] = v; }
var feedback = function(n,v,a,c) {
var feedback = function(n = "map",v,a = "feedback",c) {
if (v === "_form") { v = form; }
if (markers[n]) {
// console.log("FB1",n,v,a,c)
allData[n].action = a || "feedback";
// undefined is handled directly in the function declaration, but null/"" also requires explicit handling within the function.
n = (n === null || n === "") ? "map" : n;
var dataToSend = { "name": n, "action": a, "value": v };
//Kept only for backward compatibility, as the context menu should handle the click position values internally.
if (n == "map") {
dataToSend.lat = rclk.lat;
dataToSend.lon = rclk.lng;
}
ws.send(JSON.stringify(dataToSend));

//** The following lines left just to verify reasoning and clarifying why it was removed

//** the reasong to seperate entities uncleare
//if (markers[n]) {
// console.log("FB1",n,v,a,c)
//** Why are we even modifying `allData`?
// allData[n].action = a || "feedback";
//if (v !== undefined) { allData[n][a||"value"] = v; }
if (v !== undefined) { allData[n]["value"] = v; }
ws.send(JSON.stringify(allData[n]));
setMarker(allData[n]);
}
else if (polygons[n]) {
// if (v !== undefined) { allData[n]["value"] = v; }
//** Why are we sending back the `allData` object at all?
// ws.send(JSON.stringify(allData[n]));
///** Why are we updating the markers array from a feedback function?
// setMarker(allData[n]);
//}

//** what is so sppecial about feedback fomr polygons?
//else if (polygons[n]) {
// console.log("FB2", n, v, a);
const polyData = { "name": n, "action": a || "feedback", "value": v || null };
// const polyData = { "name": n, "action": a || "feedback", "value": v || null };
//sendDrawing(n,v,a)
ws.send(JSON.stringify(polyData));
}
else {
if (n === undefined) { n = "map"; }
// ws.send(JSON.stringify(polyData));
//}
//** If neither a polygon nor a marker is found, assume it's a map and send the same data?
//else {
// if (n === undefined) { n = "map"; }
// console.log("FB3",n,v,a,c)
rmenudata = v;
ws.send(JSON.stringify({action:a||"feedback", name:n, value:v, lat:rclk.lat, lon:rclk.lng}));
}
const dataToSend = { "name": n, "action": a || "feedback", "value": v || null };
ws.send(JSON.stringify(dataToSend));
//** Modifying menu content inside feedback function is a bug!
// rmenudata = v;
// ws.send(JSON.stringify({action:a||"feedback", name:n, value:v, lat:rclk.lat, lon:rclk.lng}));
//}
//** Sending the same data again is redundant, as it could result in feedback being sent twice (except for the markers where we sent unnecessary data).
//const dataToSend = { "name": n, "action": a || "feedback", "value": v || null };
//ws.send(JSON.stringify(dataToSend));
if (c === true) { map.closePopup(); }
}

Expand Down
Loading