2016-02-13 00:18:08 +01:00
|
|
|
|
2020-01-15 03:40:48 +01:00
|
|
|
<script type="text/html" data-template-name="link in">
|
2016-02-13 00:18:08 +01:00
|
|
|
<div class="form-row">
|
2016-05-17 10:16:58 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
2016-02-13 00:18:08 +01:00
|
|
|
</div>
|
2016-05-17 10:16:58 +02:00
|
|
|
<div class="form-row node-input-link-row"></div>
|
|
|
|
</script>
|
2020-01-15 03:40:48 +01:00
|
|
|
<script type="text/html" data-template-name="link out">
|
2016-05-17 10:16:58 +02:00
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
|
|
|
</div>
|
|
|
|
<div class="form-row node-input-link-row"></div>
|
2016-02-13 00:18:08 +01:00
|
|
|
</script>
|
2018-11-30 14:02:15 +01:00
|
|
|
|
2016-02-13 00:18:08 +01:00
|
|
|
<script type="text/javascript">
|
2016-05-17 10:16:58 +02:00
|
|
|
(function() {
|
|
|
|
|
2018-12-20 14:15:42 +01:00
|
|
|
var treeList;
|
2016-05-17 10:16:58 +02:00
|
|
|
|
|
|
|
function onEditPrepare(node,targetType) {
|
|
|
|
if (!node.links) {
|
|
|
|
node.links = [];
|
|
|
|
}
|
|
|
|
node.oldLinks = [];
|
|
|
|
|
2018-12-20 14:15:42 +01:00
|
|
|
var activeSubflow = RED.nodes.subflow(node.z);
|
|
|
|
|
|
|
|
treeList = $("<div>")
|
|
|
|
.css({width: "100%", height: "100%"})
|
|
|
|
.appendTo(".node-input-link-row")
|
|
|
|
.treeList({})
|
|
|
|
.on('treelistitemmouseover',function(e,item) {
|
|
|
|
if (item.node) {
|
|
|
|
item.node.highlighted = true;
|
|
|
|
item.node.dirty = true;
|
|
|
|
RED.view.redraw();
|
2016-05-17 10:16:58 +02:00
|
|
|
}
|
2018-12-20 14:15:42 +01:00
|
|
|
})
|
|
|
|
.on('treelistitemmouseout',function(e,item) {
|
|
|
|
if (item.node) {
|
|
|
|
item.node.highlighted = false;
|
|
|
|
item.node.dirty = true;
|
|
|
|
RED.view.redraw();
|
2016-05-17 10:16:58 +02:00
|
|
|
}
|
|
|
|
});
|
2018-12-20 14:15:42 +01:00
|
|
|
var candidateNodes = RED.nodes.filterNodes({type:targetType});
|
2016-05-17 10:16:58 +02:00
|
|
|
|
2018-12-20 14:15:42 +01:00
|
|
|
var flows = [];
|
|
|
|
var flowMap = {};
|
|
|
|
|
|
|
|
if (activeSubflow) {
|
|
|
|
flowMap[activeSubflow.id] = {
|
|
|
|
id: activeSubflow.id,
|
2019-04-29 23:38:14 +02:00
|
|
|
class: 'red-ui-palette-header',
|
2019-04-25 12:58:23 +02:00
|
|
|
label: "Subflow : "+(activeSubflow.name || activeSubflow.id),
|
2018-12-20 14:15:42 +01:00
|
|
|
expanded: true,
|
|
|
|
children: []
|
|
|
|
};
|
|
|
|
flows.push(flowMap[activeSubflow.id])
|
|
|
|
} else {
|
|
|
|
RED.nodes.eachWorkspace(function(ws) {
|
|
|
|
flowMap[ws.id] = {
|
|
|
|
id: ws.id,
|
2019-04-29 23:38:14 +02:00
|
|
|
class: 'red-ui-palette-header',
|
2019-02-06 16:38:35 +01:00
|
|
|
label: (ws.label || ws.id)+(node.z===ws.id ? " *":""),
|
|
|
|
expanded: true,
|
2018-12-20 14:15:42 +01:00
|
|
|
children: []
|
|
|
|
}
|
|
|
|
flows.push(flowMap[ws.id])
|
|
|
|
})
|
|
|
|
}
|
2016-05-17 10:16:58 +02:00
|
|
|
|
2018-12-20 14:15:42 +01:00
|
|
|
candidateNodes.forEach(function(n) {
|
|
|
|
if (flowMap[n.z]) {
|
|
|
|
var isChecked = false;
|
|
|
|
isChecked = (node.links.indexOf(n.id) !== -1) || (n.links||[]).indexOf(node.id) !== -1;
|
|
|
|
if (isChecked) {
|
|
|
|
node.oldLinks.push(n.id);
|
|
|
|
}
|
|
|
|
flowMap[n.z].children.push({
|
|
|
|
id: n.id,
|
|
|
|
node: n,
|
|
|
|
label: n.name||n.id,
|
|
|
|
selected: isChecked
|
|
|
|
})
|
|
|
|
}
|
2016-05-17 10:16:58 +02:00
|
|
|
});
|
2018-12-20 14:15:42 +01:00
|
|
|
flows = flows.filter(function(f) { return f.children.length > 0 })
|
2019-02-06 16:38:35 +01:00
|
|
|
treeList.treeList('data',flows);
|
|
|
|
setTimeout(function() {
|
|
|
|
treeList.treeList('show',node.z);
|
|
|
|
},100);
|
2016-05-17 10:16:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function resizeNodeList() {
|
|
|
|
var rows = $("#dialog-form>div:not(.node-input-link-row)");
|
|
|
|
var height = $("#dialog-form").height();
|
2019-04-29 12:50:15 +02:00
|
|
|
for (var i=0;i<rows.length;i++) {
|
2016-05-17 10:16:58 +02:00
|
|
|
height -= $(rows[i]).outerHeight(true);
|
|
|
|
}
|
|
|
|
var editorRow = $("#dialog-form>div.node-input-link-row");
|
|
|
|
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
|
2018-12-20 14:15:42 +01:00
|
|
|
$(".node-input-link-row").css("height",height+"px");
|
2016-05-17 10:16:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onEditSave(node) {
|
2018-12-20 14:15:42 +01:00
|
|
|
var flows = treeList.treeList('data');
|
2016-05-17 10:16:58 +02:00
|
|
|
node.links = [];
|
2018-12-20 14:15:42 +01:00
|
|
|
flows.forEach(function(f) {
|
|
|
|
f.children.forEach(function(n) {
|
|
|
|
if (n.selected) {
|
|
|
|
node.links.push(n.id);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2016-05-17 10:16:58 +02:00
|
|
|
node.oldLinks.sort();
|
|
|
|
node.links.sort();
|
|
|
|
var nodeMap = {};
|
|
|
|
var length = Math.max(node.oldLinks.length,node.links.length);
|
|
|
|
for (var i=0;i<length;i++) {
|
|
|
|
if (i<node.oldLinks.length) {
|
|
|
|
nodeMap[node.oldLinks[i]] = nodeMap[node.oldLinks[i]]||{};
|
|
|
|
nodeMap[node.oldLinks[i]].old = true;
|
|
|
|
}
|
|
|
|
if (i<node.links.length) {
|
|
|
|
nodeMap[node.links[i]] = nodeMap[node.links[i]]||{};
|
|
|
|
nodeMap[node.links[i]].new = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var n;
|
|
|
|
for (var id in nodeMap) {
|
|
|
|
if (nodeMap.hasOwnProperty(id)) {
|
|
|
|
n = RED.nodes.node(id);
|
|
|
|
if (n) {
|
|
|
|
if (nodeMap[id].old && !nodeMap[id].new) {
|
|
|
|
// Removed id
|
|
|
|
i = n.links.indexOf(node.id);
|
|
|
|
if (i > -1) {
|
|
|
|
n.links.splice(i,1);
|
|
|
|
}
|
2017-03-03 00:12:06 +01:00
|
|
|
} else if (!nodeMap[id].old && nodeMap[id].new) {
|
2016-05-17 10:16:58 +02:00
|
|
|
// Added id
|
|
|
|
i = n.links.indexOf(id);
|
|
|
|
if (i === -1) {
|
|
|
|
n.links.push(node.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 17:48:16 +02:00
|
|
|
function onAdd() {
|
|
|
|
for (var i=0;i<this.links.length;i++) {
|
|
|
|
var n = RED.nodes.node(this.links[i]);
|
2017-07-05 00:40:37 +02:00
|
|
|
if (n && n.links.indexOf(this.id) === -1) {
|
2016-05-18 17:48:16 +02:00
|
|
|
n.links.push(this.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-13 00:18:08 +01:00
|
|
|
RED.nodes.registerType('link in',{
|
2019-07-09 21:26:26 +02:00
|
|
|
category: 'common',
|
2016-05-17 10:16:58 +02:00
|
|
|
color:"#ddd",//"#87D8CF",
|
2016-02-13 00:18:08 +01:00
|
|
|
defaults: {
|
2016-05-17 10:16:58 +02:00
|
|
|
name: {value:""},
|
|
|
|
links: { value: [] }
|
2016-02-13 00:18:08 +01:00
|
|
|
},
|
|
|
|
inputs:0,
|
|
|
|
outputs:1,
|
2019-06-21 13:36:20 +02:00
|
|
|
icon: "link-out.svg",
|
2017-03-03 00:12:06 +01:00
|
|
|
outputLabels: function(i) {
|
|
|
|
return this.name||this._("link.linkIn");
|
|
|
|
},
|
2016-02-13 00:18:08 +01:00
|
|
|
label: function() {
|
2016-05-17 10:16:58 +02:00
|
|
|
return this.name||this._("link.linkIn");
|
2016-02-13 00:18:08 +01:00
|
|
|
},
|
|
|
|
labelStyle: function() {
|
2016-05-17 10:16:58 +02:00
|
|
|
return this.name?"node_label_italic":"";
|
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
|
|
|
onEditPrepare(this,"link out");
|
|
|
|
},
|
|
|
|
oneditsave: function() {
|
|
|
|
onEditSave(this);
|
|
|
|
},
|
2016-05-18 17:48:16 +02:00
|
|
|
onadd: onAdd,
|
2016-05-17 10:16:58 +02:00
|
|
|
oneditresize: resizeNodeList
|
2016-02-13 00:18:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
RED.nodes.registerType('link out',{
|
2019-07-09 21:26:26 +02:00
|
|
|
category: 'common',
|
2016-05-17 10:16:58 +02:00
|
|
|
color:"#ddd",//"#87D8CF",
|
2016-02-13 00:18:08 +01:00
|
|
|
defaults: {
|
2016-05-17 10:16:58 +02:00
|
|
|
name: {value:""},
|
|
|
|
links: { value: []}
|
2016-02-13 00:18:08 +01:00
|
|
|
},
|
|
|
|
align:"right",
|
|
|
|
inputs:1,
|
|
|
|
outputs:0,
|
2019-06-21 13:36:20 +02:00
|
|
|
icon: "link-out.svg",
|
2017-03-03 00:12:06 +01:00
|
|
|
inputLabels: function(i) {
|
|
|
|
return this.name||this._("link.linkOut");
|
|
|
|
},
|
2016-02-13 00:18:08 +01:00
|
|
|
label: function() {
|
2016-05-17 10:16:58 +02:00
|
|
|
return this.name||this._("link.linkOut");
|
2016-02-13 00:18:08 +01:00
|
|
|
},
|
|
|
|
labelStyle: function() {
|
2016-05-17 10:16:58 +02:00
|
|
|
return this.name?"node_label_italic":"";
|
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
|
|
|
onEditPrepare(this,"link in");
|
|
|
|
},
|
|
|
|
oneditsave: function() {
|
|
|
|
onEditSave(this);
|
|
|
|
},
|
2016-05-18 17:48:16 +02:00
|
|
|
onadd: onAdd,
|
2016-05-17 10:16:58 +02:00
|
|
|
oneditresize: resizeNodeList
|
2016-02-13 00:18:08 +01:00
|
|
|
});
|
2016-05-17 10:16:58 +02:00
|
|
|
})();
|
2016-02-13 00:18:08 +01:00
|
|
|
</script>
|