From d5cc5b2574bbe46df7662e327515aae895a5a0d9 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 7 Jan 2021 15:34:27 +0000 Subject: [PATCH] Use subflow.info for help text and meta.type for node type --- .../editor-client/locales/en-US/editor.json | 1 + .../@node-red/editor-client/src/js/nodes.js | 13 + .../editor-client/src/js/ui/palette.js | 23 +- .../editor-client/src/js/ui/subflow.js | 12 +- .../editor-client/src/js/ui/tab-help.js | 2 +- .../editor-client/src/js/ui/tab-info.js | 30 -- .../@node-red/registry/lib/subflow.js | 12 +- test/resources/subflow/package/subflow.json | 270 +++++++++++++++++- .../subflow/test-subflow-mod-1.0.1.tgz | Bin 1449 -> 1682 bytes 9 files changed, 304 insertions(+), 59 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json index c3ab1f8e0..7894f1ed2 100755 --- a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json +++ b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json @@ -342,6 +342,7 @@ "module": "Module", "license": "License", "licenseOther": "Other", + "type": "Node Type", "version": "Version", "versionPlaceholder": "x.y.z", "keys": "Keywords", diff --git a/packages/node_modules/@node-red/editor-client/src/js/nodes.js b/packages/node_modules/@node-red/editor-client/src/js/nodes.js index 7b5bbe471..3e513de08 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/nodes.js +++ b/packages/node_modules/@node-red/editor-client/src/js/nodes.js @@ -1921,6 +1921,18 @@ RED.nodes = (function() { RED.events.emit("groups:remove",group); } + function getNodeHelp(type) { + var helpContent = ""; + var helpElement = $("script[data-help-name='"+type+"']"); + if (helpElement) { + helpContent = helpElement.html(); + var helpType = helpElement.attr("type"); + if (helpType === "text/markdown") { + helpContent = RED.utils.renderMarkdown(helpContent); + } + } + return helpContent; + } return { init: function() { @@ -2000,6 +2012,7 @@ RED.nodes = (function() { registerType: registry.registerNodeType, getType: registry.getNodeType, + getNodeHelp: getNodeHelp, convertNode: convertNode, add: addNode, diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/palette.js b/packages/node_modules/@node-red/editor-client/src/js/ui/palette.js index ecee89d70..bd0b55cba 100755 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/palette.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/palette.js @@ -147,7 +147,7 @@ RED.palette = (function() { var popOverContent; try { var l = "

"+RED.text.bidi.enforceTextDirectionWithUCC(label)+"

"; - popOverContent = $('
').append($(l+(info?info:$("script[data-help-name='"+type+"']").html()||"

"+RED._("palette.noInfo")+"

").trim()) + popOverContent = $('
').append($(l+(info?info:RED.nodes.getNodeHelp(type)||"

"+RED._("palette.noInfo")+"

").trim()) .filter(function(n) { return (this.nodeType == 1 && this.nodeName == "P") || (this.nodeType == 3 && this.textContent.trim().length > 0) }).slice(0,2)); @@ -264,27 +264,6 @@ RED.palette = (function() { d.data('popover',popover); - // $(d).popover({ - // title:d.type, - // placement:"right", - // trigger: "hover", - // delay: { show: 750, hide: 50 }, - // html: true, - // container:'body' - // }); - // d.on("click", function() { - // RED.view.focus(); - // var helpText; - // if (nt.indexOf("subflow:") === 0) { - // helpText = RED.utils.renderMarkdown(RED.nodes.subflow(nt.substring(8)).info||"")||(''+RED._("sidebar.info.none")+''); - // } else { - // helpText = $("script[data-help-name='"+d.attr("data-palette-type")+"']").html()||(''+RED._("sidebar.info.none")+''); - // } - // // Don't look too closely. RED.sidebar.info.set will set the 'Description' - // // section of the sidebar. Pass in the title of the Help section so it looks - // // right. - // RED.sidebar.type.show(helpText,RED._("sidebar.info.nodeHelp")); - // }); var chart = $("#red-ui-workspace-chart"); var chartSVG = $("#red-ui-workspace-chart>svg").get(0); var activeSpliceLink; diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js b/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js index c8c649fac..b4cf4be08 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js @@ -52,6 +52,10 @@ RED.subflow = (function() { ''+ ''+ ''+ + '
'+ + ''+ + ''+ + '
'+ '
'+ ''+ ''+ @@ -61,7 +65,7 @@ RED.subflow = (function() { ''+ '
'+ '
'+ - ''+ + ''+ ''+ '
'+ '
'+ @@ -1767,7 +1771,7 @@ RED.subflow = (function() { } } } - } else if (/^sf-/.test(node.type)) { + } else if (node._def.subflowModule) { var keys = Object.keys(node._def.defaults); keys.forEach(function(name) { if (name !== 'name') { @@ -1954,6 +1958,7 @@ RED.subflow = (function() { var moduleProps = node.meta || {}; [ 'module', + 'type', 'version', 'author', 'desc', @@ -1962,6 +1967,8 @@ RED.subflow = (function() { ].forEach(function(property) { $("#subflow-input-module-"+property).val(moduleProps[property]||"") }) + $("#subflow-input-module-type").attr("placeholder",node.id); + setupInputValidation($("#subflow-input-module-module"), function(newValue) { newValue = newValue.trim(); var isValid = newValue.length < 215; @@ -2008,6 +2015,7 @@ RED.subflow = (function() { var moduleProps = {}; [ 'module', + 'type', 'version', 'author', 'desc', diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/tab-help.js b/packages/node_modules/@node-red/editor-client/src/js/ui/tab-help.js index c1344e755..cc86de358 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/tab-help.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/tab-help.js @@ -247,7 +247,7 @@ RED.sidebar.help = (function() { helpText = (RED.utils.renderMarkdown(subflowNode.info||"")||(''+RED._("sidebar.info.none")+'')); title = subflowNode.name || nodeType; } else { - helpText = $("script[data-help-name='"+nodeType+"']").html()||(''+RED._("sidebar.info.none")+''); + helpText = RED.nodes.getNodeHelp(nodeType)||(''+RED._("sidebar.info.none")+''); title = nodeType; } setInfoText(title, helpText, helpSection); diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info.js b/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info.js index 678356181..a8e5583cb 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info.js @@ -390,19 +390,6 @@ RED.sidebar.info = (function() { } } - // var helpText = ""; - // if (node.type === "tab" || node.type === "subflow") { - // } else { - // if (subflowNode && node.type !== "subflow") { - // // Selected a subflow instance node. - // // - The subflow template info goes into help - // helpText = (RED.utils.renderMarkdown(subflowNode.info||"")||(''+RED._("sidebar.info.none")+'')); - // } else { - // helpText = $("script[data-help-name='"+node.type+"']").html()||(''+RED._("sidebar.info.none")+''); - // } - // setInfoText(helpText, helpSection.content); - // } - var infoText = ""; if (node._def && node._def.info) { @@ -415,23 +402,6 @@ RED.sidebar.info = (function() { } var infoSectionContainer = $("
").css("padding","0 6px 6px").appendTo(propertiesPanelContent) - // var editInfo = $('').appendTo(infoSectionContainer).on("click", function(evt) { - // //.text(RED._("sidebar.info.editDescription")) - // evt.preventDefault(); - // evt.stopPropagation(); - // if (node.type === 'tab') { - // - // } else if (node.type === 'subflow') { - // - // } else if (node.type === 'group') { - // - // } else if (node._def.category !== 'config') { - // RED.editor.edit(node,"editor-tab-description"); - // } else { - // - // } - // }) - setInfoText(infoText, infoSectionContainer); $(".red-ui-sidebar-info-stack").scrollTop(0); diff --git a/packages/node_modules/@node-red/registry/lib/subflow.js b/packages/node_modules/@node-red/registry/lib/subflow.js index a398d3607..97516691e 100644 --- a/packages/node_modules/@node-red/registry/lib/subflow.js +++ b/packages/node_modules/@node-red/registry/lib/subflow.js @@ -1,5 +1,8 @@ function getSubflowType(subflow) { - return "sf-"+subflow.id + if (subflow.meta && subflow.meta.type) { + return subflow.meta.type + } + return "sf:"+subflow.id } function generateSubflowConfig(subflow) { @@ -49,8 +52,14 @@ function generateSubflowConfig(subflow) { const defaultString = JSON.stringify(defaults); const credentialsString = JSON.stringify(credentials); + let nodeHelp = ""; + if (subflow.info) { + nodeHelp = `` + } + return ` +${nodeHelp} ` } diff --git a/test/resources/subflow/package/subflow.json b/test/resources/subflow/package/subflow.json index 3a9bcfa54..e5c6b25ab 100644 --- a/test/resources/subflow/package/subflow.json +++ b/test/resources/subflow/package/subflow.json @@ -1,4 +1,268 @@ -{"id":"caf258cc.4e2c48","type":"subflow","name":"Test Subflow","info":"","category":"common","in":[{"x":120,"y":100,"wires":[{"id":"2f1d674f.a02d28"}]}],"out":[{"x":560,"y":100,"wires":[{"id":"1497236e.07f12d","port":0}]},{"x":360,"y":200,"wires":[{"id":"f4334f5f.4905c","port":0}]}],"env":[{"name":"FOO","type":"cred","ui":{"icon":"font-awesome/fa-thermometer-0"}},{"name":"BAR","type":"str","value":"1","ui":{"icon":"font-awesome/fa-thermometer-2","type":"select","opts":{"opts":[{"l":{"en-US":"option 1"},"v":"1"},{"l":{"en-US":"option 2"},"v":"2"},{"l":{"en-US":"option 3"},"v":"3"}]}}},{"name":"onewithaverylongname","type":"str","value":""},{"name":"BARRY","type":"bool","value":"true","ui":{"icon":"font-awesome/fa-thermometer-4","type":"checkbox"}},{"name":"WILMA","type":"num","value":"10","ui":{"icon":"font-awesome/fbomb","type":"spinner"}},{"name":"awg","type":"num","value":"","ui":{"icon":"font-awesome/fa-address-book-o","type":"spinner"}},{"name":"awf","type":"str","value":"","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"one"},"v":"1"},{"l":{"en-US":"two"},"v":"2"},{"l":{"en-US":"three"},"v":"3"}]}}},{"name":"aawf","type":"bool","value":"true","ui":{"type":"checkbox"}},{"name":"awgawgawg","type":"str","value":"","ui":{"type":"none"}},{"name":"seagseg","type":"str","value":"","ui":{"type":"hide"}}],"meta":{},"color":"#A6BBCF","icon":"font-awesome/fa-space-shuttle","status":{"x":500,"y":300,"wires":[{"id":"8252d1cc.54f94","port":0}]}, -"flow": - [{"id":"2f1d674f.a02d28","type":"function","z":"caf258cc.4e2c48","name":"","func":"node.error(\"subflow error \"+msg.payload,msg);\nmsg.payload = {\n FOO: env.get(\"FOO\"),\n BAR: env.get(\"BAR\"),\n WILMA: env.get(\"WILMA\"),\n BARRY: env.get(\"BARRY\")\n}\nnode.warn(\"warning\");\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":100,"wires":[["1497236e.07f12d"]]},{"id":"f4334f5f.4905c","type":"catch","z":"caf258cc.4e2c48","name":"","scope":null,"uncaught":false,"x":220,"y":200,"wires":[["8252d1cc.54f94"]]},{"id":"8252d1cc.54f94","type":"change","z":"caf258cc.4e2c48","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"error.message","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":300,"wires":[[]]},{"id":"1497236e.07f12d","type":"random","z":"caf258cc.4e2c48","name":"","low":"1","high":"10","inte":"true","property":"random","x":420,"y":100,"wires":[[]]},{"id":"876fc49e.f15268","type":"subflow:caf258cc.4e2c48","z":"d607ce33.4fa5a","name":"","x":200,"y":760,"wires":[[],[]]}] +{ + "id": "caf258cc.4e2c48", + "type": "subflow", + "name": "Test Subflow", + "info":"This is my exportable module subflow\n\nI hope this shows as help!", + "category": "common", + "in": [ + { + "x": 120, + "y": 100, + "wires": [ + { + "id": "2f1d674f.a02d28" + } + ] + } + ], + "out": [ + { + "x": 560, + "y": 100, + "wires": [ + { + "id": "1497236e.07f12d", + "port": 0 + } + ] + }, + { + "x": 360, + "y": 200, + "wires": [ + { + "id": "f4334f5f.4905c", + "port": 0 + } + ] + } + ], + "env": [ + { + "name": "FOO", + "type": "cred", + "ui": { + "icon": "font-awesome/fa-thermometer-0" + } + }, + { + "name": "BAR", + "type": "str", + "value": "1", + "ui": { + "icon": "font-awesome/fa-thermometer-2", + "type": "select", + "opts": { + "opts": [ + { + "l": { + "en-US": "option 1" + }, + "v": "1" + }, + { + "l": { + "en-US": "option 2" + }, + "v": "2" + }, + { + "l": { + "en-US": "option 3" + }, + "v": "3" + } + ] + } + } + }, + { + "name": "onewithaverylongname", + "type": "str", + "value": "" + }, + { + "name": "BARRY", + "type": "bool", + "value": "true", + "ui": { + "icon": "font-awesome/fa-thermometer-4", + "type": "checkbox" + } + }, + { + "name": "WILMA", + "type": "num", + "value": "10", + "ui": { + "icon": "font-awesome/fbomb", + "type": "spinner" + } + }, + { + "name": "awg", + "type": "num", + "value": "", + "ui": { + "icon": "font-awesome/fa-address-book-o", + "type": "spinner" + } + }, + { + "name": "awf", + "type": "str", + "value": "", + "ui": { + "type": "select", + "opts": { + "opts": [ + { + "l": { + "en-US": "one" + }, + "v": "1" + }, + { + "l": { + "en-US": "two" + }, + "v": "2" + }, + { + "l": { + "en-US": "three" + }, + "v": "3" + } + ] + } + } + }, + { + "name": "aawf", + "type": "bool", + "value": "true", + "ui": { + "type": "checkbox" + } + }, + { + "name": "awgawgawg", + "type": "str", + "value": "", + "ui": { + "type": "none" + } + }, + { + "name": "seagseg", + "type": "str", + "value": "", + "ui": { + "type": "hide" + } + } + ], + "meta": { + "type": "fly-a-plane" + }, + "color": "#A6BBCF", + "icon": "font-awesome/fa-space-shuttle", + "status": { + "x": 500, + "y": 300, + "wires": [ + { + "id": "8252d1cc.54f94", + "port": 0 + } + ] + }, + "flow": [ + { + "id": "2f1d674f.a02d28", + "type": "function", + "z": "caf258cc.4e2c48", + "name": "", + "func": "node.error(\"subflow error \"+msg.payload,msg);\nmsg.payload = {\n FOO: env.get(\"FOO\"),\n BAR: env.get(\"BAR\"),\n WILMA: env.get(\"WILMA\"),\n BARRY: env.get(\"BARRY\")\n}\nnode.warn(\"warning\");\n\nreturn msg;", + "outputs": 1, + "noerr": 0, + "initialize": "", + "finalize": "", + "x": 240, + "y": 100, + "wires": [ + [ + "1497236e.07f12d" + ] + ] + }, + { + "id": "f4334f5f.4905c", + "type": "catch", + "z": "caf258cc.4e2c48", + "name": "", + "scope": null, + "uncaught": false, + "x": 220, + "y": 200, + "wires": [ + [ + "8252d1cc.54f94" + ] + ] + }, + { + "id": "8252d1cc.54f94", + "type": "change", + "z": "caf258cc.4e2c48", + "name": "", + "rules": [ + { + "t": "set", + "p": "payload", + "pt": "msg", + "to": "error.message", + "tot": "msg" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 350, + "y": 300, + "wires": [ + [] + ] + }, + { + "id": "1497236e.07f12d", + "type": "random", + "z": "caf258cc.4e2c48", + "name": "", + "low": "1", + "high": "10", + "inte": "true", + "property": "random", + "x": 420, + "y": 100, + "wires": [ + [] + ] + }, + { + "id": "876fc49e.f15268", + "type": "subflow:caf258cc.4e2c48", + "z": "d607ce33.4fa5a", + "name": "", + "x": 200, + "y": 760, + "wires": [ + [], + [] + ] + } + ] } \ No newline at end of file diff --git a/test/resources/subflow/test-subflow-mod-1.0.1.tgz b/test/resources/subflow/test-subflow-mod-1.0.1.tgz index 235dad158834eb01d00478f69ab57ba9b3160129..daa53b77a4d73bc6ca062f72c7559485d30bc892 100644 GIT binary patch literal 1682 zcmV;D25tEtiwFP!000006YUynZ`(GopZzO1?L(5yk|kNT6BqrEwkg)3U4}TtP}D)e zP?V)bCN+|Z;}-t!BPGkRUQS{=>DrkvVCn93ygS~5uLz(7=QC;TW_Xm zb{z*)!Bw-{7I@a~bWO|Zc1=kqAM9RR{%>EDa*MfuOp3B8pHvsH`2S8?V@%yR#0I{J zC=(pK0A5Ux2q@VQ95B4U z=kdJ*NeJCHL5K%af)*$(g2LAhjK66>_CJ4i14iH&H?>>uqeMH9tug!7hWVegXdeIb z|6~NV-NzmA-%&ANi2sh$*~R};G!@^P3PP<9G=aI$=dq~E#Go}5_8K!T^MN9;4AZbu zs7wZk1(BFzQs5PyPAGG^gnYV4AYp(o;R*M*gI6h)$|O3&t^}s(We(#@fCRWKkK%Bf zCbT)(teG)zafFGB2?`QEpO*P#9qQ==BrY9i94;DjE=3MG(Mn%SX?{^GW{p|nTaV!; zEh^RjCysxsV>#vc?>g2l{-2_yUakcy7&QbvyK{(;;b0p%hguq3nwUm-Df}{UmNm|0 zl!8GX7Z8tXeeK*2IFP^b6r>Xjco|}lPC3Aw-H;5)Tj0|O1EI*dPbVBe4tyL&KV=LN z6n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