From d9350b23629449ada5a71c3042d45c4dcb41884f Mon Sep 17 00:00:00 2001 From: Kazuki-Nakanishi Date: Wed, 14 Mar 2018 13:51:50 +0900 Subject: [PATCH] Enable user defined icon for subflow --- editor/js/history.js | 2 ++ editor/js/nodes.js | 8 ++++++-- editor/js/ui/editor.js | 33 ++++++++++++++++++++++++++++----- editor/js/ui/palette.js | 7 +++++++ editor/js/ui/utils.js | 23 ++++++++++++++++++----- 5 files changed, 61 insertions(+), 12 deletions(-) diff --git a/editor/js/history.js b/editor/js/history.js index 12650c9a2..20e1cb52f 100644 --- a/editor/js/history.js +++ b/editor/js/history.js @@ -229,10 +229,12 @@ RED.history = (function() { } }); } + RED.editor.validateNode(ev.node); RED.nodes.filterNodes({type:"subflow:"+ev.node.id}).forEach(function(n) { n.inputs = ev.node.in.length; n.outputs = ev.node.out.length; RED.editor.updateNodeProperties(n); + RED.editor.validateNode(n); }); } else { var outputMap; diff --git a/editor/js/nodes.js b/editor/js/nodes.js index b3c39fff1..8c8210c54 100644 --- a/editor/js/nodes.js +++ b/editor/js/nodes.js @@ -355,7 +355,7 @@ RED.nodes = (function() { RED.nodes.registerType("subflow:"+sf.id, { defaults:{name:{value:""}}, info: sf.info, - icon:"subflow.png", + icon: function() { return sf.icon||"subflow.png" }, category: "subflows", inputs: sf.in.length, outputs: sf.out.length, @@ -550,7 +550,11 @@ RED.nodes = (function() { if (node.out.length > 0 && n.outputLabels && !/^\s*$/.test(n.outputLabels.join(""))) { node.outputLabels = n.outputLabels.slice(); } - + if (n.icon) { + if (n.icon !== "node-red/subflow.png") { + node.icon = n.icon; + } + } return node; } diff --git a/editor/js/ui/editor.js b/editor/js/ui/editor.js index c3f0d4ea5..c90d3729b 100644 --- a/editor/js/ui/editor.js +++ b/editor/js/ui/editor.js @@ -48,7 +48,7 @@ RED.editor = (function() { isValid = validateNode(subflow); hasChanged = subflow.changed; } - node.valid = isValid; + node.valid = isValid && validateNodeProperties(node, node._def.defaults, node); node.changed = node.changed || hasChanged; } else if (node._def) { node.valid = validateNodeProperties(node, node._def.defaults, node); @@ -170,6 +170,10 @@ RED.editor = (function() { } } } + validateIcon(node); + } + + function validateIcon(node) { if (node._def.hasOwnProperty("defaults") && !node._def.defaults.hasOwnProperty("icon") && node.icon) { var iconPath = RED.utils.separateIconPath(node.icon); var iconSets = RED.nodes.getIconSets(); @@ -188,6 +192,7 @@ RED.editor = (function() { } } } + function validateNodeEditorProperty(node,defaults,property,prefix) { var input = $("#"+prefix+"-"+property); if (input.length > 0) { @@ -742,7 +747,7 @@ RED.editor = (function() { buildLabelRow().appendTo(outputsDiv); } - if ((!node._def.defaults || !node._def.defaults.hasOwnProperty("icon")) && node.type !== "subflow") { + if ((!node._def.defaults || !node._def.defaults.hasOwnProperty("icon"))) { $('
').appendTo(dialogForm); var iconDiv = $("#node-settings-icon"); $('