diff --git a/editor/js/history.js b/editor/js/history.js index a0002b63a..b2dd473d7 100644 --- a/editor/js/history.js +++ b/editor/js/history.js @@ -191,7 +191,7 @@ RED.history = (function() { } else if (ev.t == "edit") { for (i in ev.changes) { if (ev.changes.hasOwnProperty(i)) { - if (ev.node._def.defaults[i].type) { + if (ev.node._def.defaults[i] && ev.node._def.defaults[i].type) { // This is a config node property var currentConfigNode = RED.nodes.node(ev.node[i]); if (currentConfigNode) { @@ -239,7 +239,7 @@ RED.history = (function() { if (ev.outputMap) { outputMap = {}; for (var port in ev.outputMap) { - if (ev.outputMap.hasOwnProperty(port) && ev.outputMap[port] !== -1) { + if (ev.outputMap.hasOwnProperty(port) && ev.outputMap[port] !== "-1") { outputMap[ev.outputMap[port]] = port; } } diff --git a/editor/js/ui/editor.js b/editor/js/ui/editor.js index 0b1b4b7b9..f3c8de8d2 100644 --- a/editor/js/ui/editor.js +++ b/editor/js/ui/editor.js @@ -191,7 +191,7 @@ RED.editor = (function() { if (outputMap) { RED.nodes.eachLink(function(l) { if (l.source === node && outputMap.hasOwnProperty(l.sourcePort)) { - if (outputMap[l.sourcePort] === -1) { + if (outputMap[l.sourcePort] === "-1") { removedLinks.push(l); } else { l.sourcePort = outputMap[l.sourcePort]; @@ -549,17 +549,10 @@ RED.editor = (function() { } function refreshLabelForm(container,node) { - var inputCount = node.inputs || node._def.inputs || 0; - var outputCount; - var i; - var formOutputs = parseInt($("#node-input-outputs").val()); - if (isNaN(formOutputs)) { - outputCount = node.outputs || node._def.outputs || 0; - } else { - outputCount = Math.max(0,formOutputs); - } var inputsDiv = $("#node-label-form-inputs"); var outputsDiv = $("#node-label-form-outputs"); + + var inputCount = node.inputs || node._def.inputs || 0; var children = inputsDiv.children(); if (children.length < inputCount) { for (i = children.length;i outputCount) { for (i=outputCount;i'); + var result = $('
',{style:"margin: 5px 0px"}); var id = "node-label-form-"+type+"-"+index; - $('
').appendTo(dialogForm); + $('
').appendTo(dialogForm); + var outputsDiv = $("#node-label-form-outputs"); if (outputCount > 0) { for (i=0;i 0) { - changed = true; - } - } + // if (editing_node.hasOwnProperty("_outputs")) { + // outputMap = editing_node._outputs; + // delete editing_node._outputs; + // if (Object.keys(outputMap).length > 0) { + // changed = true; + // } + // } var removedLinks = updateNodeProperties(editing_node,outputMap); var inputLabels = $("#node-label-form-inputs").children().find("input"); var outputLabels = $("#node-label-form-outputs").children().find("input"); - editing_node.inputLabels = inputLabels.map(function() { return $(this).val();}).toArray(); - editing_node.outputLabels = outputLabels.map(function() { return $(this).val();}).toArray(); + newValue = inputLabels.map(function() { return $(this).val();}).toArray().slice(0,editing_node.inputs); + if (JSON.stringify(newValue) !== JSON.stringify(editing_node.inputLabels)) { + changes.inputLabels = editing_node.inputLabels; + editing_node.inputLabels = newValue; + changed = true; + } + newValue = outputLabels.map(function() { return $(this).val();}).toArray().slice(0,editing_node.outputs); + if (JSON.stringify(newValue) !== JSON.stringify(editing_node.outputLabels)) { + changes.outputLabels = editing_node.outputLabels; + editing_node.outputLabels = newValue; + changed = true; + } if (changed) { var wasChanged = editing_node.changed; @@ -872,11 +941,11 @@ RED.editor = (function() { singleExpanded: true }); var nodeProperties = stack.add({ - title: "node properties", + title: RED._("editor.nodeProperties"), expanded: true }); var portLabels = stack.add({ - title: "port labels", + title: RED._("editor.portLabels"), onexpand: function() { refreshLabelForm(this.content,node); } diff --git a/nodes/core/logic/10-switch.html b/nodes/core/logic/10-switch.html index e584f73f0..bfb211b1d 100644 --- a/nodes/core/logic/10-switch.html +++ b/nodes/core/logic/10-switch.html @@ -22,6 +22,7 @@
+
    @@ -115,7 +116,7 @@ var previousValueType = {value:"prev",label:this._("inject.previous"),hasValue:false}; $("#node-input-property").typedInput({default:this.propertyType||'msg',types:['msg','flow','global','jsonata']}); - + var outputCount = $("#node-input-outputs").val("{}"); var andLabel = this._("switch.and"); var caseLabel = this._("switch.ignorecase"); @@ -157,6 +158,9 @@ if (!rule.hasOwnProperty('t')) { rule.t = 'eq'; } + if (!opt.hasOwnProperty('i')) { + opt._i = Math.floor((0x99999-0x10000)*Math.random()).toString(16) + } var row = $('
    ').appendTo(container); var row2 = $('
    ',{style:"padding-top: 5px; padding-left: 175px;"}).appendTo(container); var row3 = $('
    ',{style:"padding-top: 5px; padding-left: 102px;"}).appendTo(container); @@ -213,21 +217,36 @@ caseSensitive.prop('checked',false); } selectField.change(); + + var currentOutputs = JSON.parse(outputCount.val()||"{}"); + currentOutputs[opt.hasOwnProperty('i')?opt.i:opt._i] = i; + outputCount.val(JSON.stringify(currentOutputs)); }, removeItem: function(opt) { + var currentOutputs = JSON.parse(outputCount.val()||"{}"); if (opt.hasOwnProperty('i')) { - var removedList = $("#node-input-rule-container").data('removedList')||[]; - removedList.push(opt.i); - $("#node-input-rule-container").data('removedList',removedList); + currentOutputs[opt.i] = -1; + } else { + delete currentOutputs[opt._i]; } - var rules = $("#node-input-rule-container").editableList('items'); - rules.each(function(i) { $(this).find(".node-input-rule-index").html(i+1); }); + rules.each(function(i) { + $(this).find(".node-input-rule-index").html(i+1); + var data = $(this).data('data'); + currentOutputs[data.hasOwnProperty('i')?data.i:data._i] = i; + }); + outputCount.val(JSON.stringify(currentOutputs)); }, resizeItem: resizeRule, sortItems: function(rules) { + var currentOutputs = JSON.parse(outputCount.val()||"{}"); var rules = $("#node-input-rule-container").editableList('items'); - rules.each(function(i) { $(this).find(".node-input-rule-index").html(i+1); }); + rules.each(function(i) { + $(this).find(".node-input-rule-index").html(i+1); + var data = $(this).data('data'); + currentOutputs[data.hasOwnProperty('i')?data.i:data._i] = i; + }); + outputCount.val(JSON.stringify(currentOutputs)); }, sortable: true, removable: true @@ -243,11 +262,6 @@ var ruleset; var node = this; node.rules = []; - var changedOutputs = {}; - var removedList = $("#node-input-rule-container").data('removedList')||[]; - removedList.forEach(function(i) { - changedOutputs[i] = -1; - }); rules.each(function(i) { var ruleData = $(this).data('data'); var rule = $(this); @@ -267,16 +281,10 @@ r.case = rule.find(".node-input-rule-case").prop("checked"); } } - if (ruleData.hasOwnProperty('i')) { - if (ruleData.i !== i) { - changedOutputs[ruleData.i] = i; - } - } node.rules.push(r); }); - this._outputs = changedOutputs; - this.outputs = node.rules.length; this.propertyType = $("#node-input-property").typedInput('type'); + console.log(JSON.parse($("#node-input-outputs").val()||"{}")); }, oneditresize: function(size) { var rows = $("#dialog-form>div:not(.node-input-rule-container-row)"); diff --git a/red/api/locales/en-US/editor.json b/red/api/locales/en-US/editor.json index 93e5c115a..06cce1a04 100644 --- a/red/api/locales/en-US/editor.json +++ b/red/api/locales/en-US/editor.json @@ -185,6 +185,11 @@ "editNode": "Edit __type__ node", "editConfig": "Edit __type__ config node", "addNewType": "Add new __type__...", + "nodeProperties": "node properties", + "portLabels": "port labels", + "labelInputs": "Inputs", + "labelOutputs": "Outputs", + "errors": { "scopeChange": "Changing the scope will make it unavailable to nodes in other flows that use it" }