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>
|
2020-06-03 16:54:51 +02:00
|
|
|
<div style="position:relative; height: 30px; text-align: right;"><div style="display:inline-block"><input type="text" id="node-input-link-target-filter"></div></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">
|
2021-09-29 11:45:00 +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">
|
|
|
|
<label for="node-input-mode"><span data-i18n="link.outMode"></span></label>
|
|
|
|
<select id="node-input-mode" style="width: 70%">
|
|
|
|
<option value="link" selected data-i18n="link.sendToAll"></option>
|
|
|
|
<option value="return" data-i18n="link.returnToCaller"></option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="node-input-link-rows" style="position:relative; height: 30px; text-align: right;"><div style="display:inline-block"><input type="text" id="node-input-link-target-filter"></div></div>
|
|
|
|
<div class="form-row node-input-link-row node-input-link-rows"></div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/html" data-template-name="link call">
|
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>
|
2021-09-29 15:28:12 +02:00
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-input-timeout"><span data-i18n="exec.label.timeout"></span></label>
|
|
|
|
<input type="text" id="node-input-timeout" placeholder="30" style="width: 70px; margin-right: 5px;"><span data-i18n="inject.seconds"></span>
|
|
|
|
</div>
|
2022-02-24 20:46:21 +01:00
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-input-linkType" data-i18n="link.linkCallType"></label>
|
|
|
|
<select id="node-input-linkType" style="width: 70%">
|
|
|
|
<option value="static" data-i18n="link.staticLinkCall"></option>
|
|
|
|
<option value="dynamic" data-i18n="link.dynamicLinkCall"></option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="link-call-target-tree" style="position:relative; height: 30px; text-align: right;">
|
|
|
|
<div style="display:inline-block"><input type="text" id="node-input-link-target-filter"></div>
|
|
|
|
</div>
|
|
|
|
<div class="form-row node-input-link-row link-call-target-tree"></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() {
|
|
|
|
|
2022-04-12 23:11:34 +02:00
|
|
|
let treeList;
|
2016-05-17 10:16:58 +02:00
|
|
|
|
|
|
|
function onEditPrepare(node,targetType) {
|
|
|
|
if (!node.links) {
|
|
|
|
node.links = [];
|
|
|
|
}
|
|
|
|
node.oldLinks = [];
|
|
|
|
|
2022-04-12 23:11:34 +02:00
|
|
|
const activeSubflow = RED.nodes.subflow(node.z);
|
2018-12-20 14:15:42 +01:00
|
|
|
|
|
|
|
treeList = $("<div>")
|
|
|
|
.css({width: "100%", height: "100%"})
|
|
|
|
.appendTo(".node-input-link-row")
|
2021-10-18 10:32:00 +02:00
|
|
|
.treeList({autoSelect:false})
|
2018-12-20 14:15:42 +01:00
|
|
|
.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
|
|
|
}
|
|
|
|
});
|
2022-04-12 23:11:34 +02:00
|
|
|
const candidateNodes = RED.nodes.filterNodes({type:targetType});
|
|
|
|
let candidateNodesCount = 0;
|
2021-10-13 15:23:43 +02:00
|
|
|
|
2022-04-12 23:11:34 +02:00
|
|
|
const search = $("#node-input-link-target-filter").searchBox({
|
2020-06-03 16:54:51 +02:00
|
|
|
style: "compact",
|
|
|
|
delay: 300,
|
|
|
|
change: function() {
|
2020-06-05 17:00:02 +02:00
|
|
|
var val = $(this).val().trim().toLowerCase();
|
2020-06-03 16:54:51 +02:00
|
|
|
if (val === "") {
|
|
|
|
treeList.treeList("filter", null);
|
|
|
|
search.searchBox("count","");
|
|
|
|
} else {
|
2022-04-12 23:11:34 +02:00
|
|
|
const count = treeList.treeList("filter", function(item) {
|
2020-06-05 17:20:40 +02:00
|
|
|
return item.label.toLowerCase().indexOf(val) > -1 || (item.node && item.node.type.toLowerCase().indexOf(val) > -1)
|
2020-06-03 16:54:51 +02:00
|
|
|
});
|
2021-10-13 15:23:43 +02:00
|
|
|
search.searchBox("count",count+" / "+candidateNodesCount);
|
2020-06-03 16:54:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-04-12 23:11:34 +02:00
|
|
|
const flows = [];
|
|
|
|
const flowMap = {};
|
2018-12-20 14:15:42 +01:00
|
|
|
|
|
|
|
if (activeSubflow) {
|
|
|
|
flowMap[activeSubflow.id] = {
|
|
|
|
id: activeSubflow.id,
|
2019-04-29 23:38:14 +02:00
|
|
|
class: 'red-ui-palette-header',
|
2022-04-12 23:11:34 +02:00
|
|
|
label: "Subflow : " + (activeSubflow.name || activeSubflow.id),
|
2018-12-20 14:15:42 +01:00
|
|
|
expanded: true,
|
|
|
|
children: []
|
|
|
|
};
|
|
|
|
flows.push(flowMap[activeSubflow.id])
|
2022-04-12 23:11:34 +02:00
|
|
|
}
|
|
|
|
if (!activeSubflow || node.type === "link call") {
|
|
|
|
// Only "Link Call" can look outside of its own subflow
|
|
|
|
// Link In and Link Out nodes outside of a subflow should be ignored
|
|
|
|
RED.nodes.eachWorkspace(function (ws) {
|
2018-12-20 14:15:42 +01:00
|
|
|
flowMap[ws.id] = {
|
|
|
|
id: ws.id,
|
2019-04-29 23:38:14 +02:00
|
|
|
class: 'red-ui-palette-header',
|
2022-04-12 23:11:34 +02:00
|
|
|
label: (ws.label || ws.id) + (node.z === ws.id ? " *" : ""),
|
2019-02-06 16:38:35 +01:00
|
|
|
expanded: true,
|
2018-12-20 14:15:42 +01:00
|
|
|
children: []
|
|
|
|
}
|
|
|
|
flows.push(flowMap[ws.id])
|
|
|
|
})
|
|
|
|
}
|
2016-05-17 10:16:58 +02:00
|
|
|
|
2022-04-12 23:11:34 +02:00
|
|
|
candidateNodes.forEach(function (n) {
|
2018-12-20 14:15:42 +01:00
|
|
|
if (flowMap[n.z]) {
|
2021-10-13 15:23:43 +02:00
|
|
|
if (targetType === "link out" && n.mode === 'return') {
|
|
|
|
// Link In nodes looking for Link Out nodes should not
|
|
|
|
// include return-mode nodes.
|
2022-04-12 23:11:34 +02:00
|
|
|
return;
|
2021-10-13 15:23:43 +02:00
|
|
|
}
|
2022-04-12 23:11:34 +02:00
|
|
|
const isChecked = (node.links.indexOf(n.id) !== -1) || (n.links || []).indexOf(node.id) !== -1;
|
2018-12-20 14:15:42 +01:00
|
|
|
if (isChecked) {
|
|
|
|
node.oldLinks.push(n.id);
|
|
|
|
}
|
|
|
|
flowMap[n.z].children.push({
|
|
|
|
id: n.id,
|
|
|
|
node: n,
|
2022-04-12 23:11:34 +02:00
|
|
|
label: n.name || n.id,
|
2020-05-21 11:39:49 +02:00
|
|
|
selected: isChecked,
|
2021-09-29 11:45:00 +02:00
|
|
|
checkbox: node.type !== "link call",
|
|
|
|
radio: node.type === "link call"
|
2018-12-20 14:15:42 +01:00
|
|
|
})
|
2021-10-13 15:23:43 +02:00
|
|
|
candidateNodesCount++;
|
2018-12-20 14:15:42 +01:00
|
|
|
}
|
2016-05-17 10:16:58 +02:00
|
|
|
});
|
2022-04-12 23:11:34 +02:00
|
|
|
const flowsFiltered = flows.filter(function(f) { return f.children.length > 0 })
|
|
|
|
treeList.treeList('data',flowsFiltered);
|
2019-02-06 16:38:35 +01:00
|
|
|
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 = [];
|
2021-10-18 10:32:00 +02:00
|
|
|
if (node.type !== "link out" || $("#node-input-mode").val() === 'link') {
|
2021-09-29 11:45:00 +02:00
|
|
|
flows.forEach(function(f) {
|
|
|
|
f.children.forEach(function(n) {
|
|
|
|
if (n.selected) {
|
|
|
|
node.links.push(n.id);
|
|
|
|
}
|
|
|
|
})
|
2018-12-20 14:15:42 +01:00
|
|
|
})
|
2021-09-29 11:45:00 +02:00
|
|
|
}
|
2016-05-17 10:16:58 +02:00
|
|
|
node.oldLinks.sort();
|
|
|
|
node.links.sort();
|
2021-09-29 11:45:00 +02:00
|
|
|
|
|
|
|
if (node.type === "link call") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-05-17 10:16:58 +02:00
|
|
|
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() {
|
2022-04-25 21:30:05 +02:00
|
|
|
if (this.name === '_DEFAULT_') {
|
2022-04-19 20:17:41 +02:00
|
|
|
this.name = ''
|
2022-06-26 10:08:26 +02:00
|
|
|
RED.actions.invoke("core:generate-node-names", this, {generateHistory: false})
|
2022-04-19 20:17:41 +02:00
|
|
|
}
|
2016-05-18 17:48:16 +02:00
|
|
|
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: {
|
2022-04-25 21:30:05 +02:00
|
|
|
name: { value: "_DEFAULT_" },
|
2021-01-08 15:19:12 +01:00
|
|
|
links: { value: [], type:"link out[]" }
|
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");
|
|
|
|
},
|
2021-09-29 11:45:00 +02:00
|
|
|
showLabel: false,
|
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);
|
2021-10-14 13:00:27 +02:00
|
|
|
// In case the name has changed, ensure any link call nodes on this
|
|
|
|
// tab are redrawn with the updated name
|
|
|
|
var localCallNodes = RED.nodes.filterNodes({z:RED.workspaces.active(), type:"link call"});
|
|
|
|
localCallNodes.forEach(function(node) {
|
|
|
|
node.dirty = true;
|
|
|
|
});
|
2016-05-17 10:16:58 +02:00
|
|
|
},
|
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
|
|
|
});
|
|
|
|
|
2021-09-29 11:45:00 +02:00
|
|
|
RED.nodes.registerType('link call',{
|
|
|
|
category: 'common',
|
|
|
|
color:"#ddd",//"#87D8CF",
|
|
|
|
defaults: {
|
2022-04-25 21:30:05 +02:00
|
|
|
name: { value: "" },
|
2022-04-19 20:17:41 +02:00
|
|
|
links: { value: [], type:"link in[]" },
|
|
|
|
linkType: { value:"static" },
|
2022-04-26 14:53:35 +02:00
|
|
|
timeout: {
|
|
|
|
value: "30",
|
|
|
|
label: RED._("node-red:link.timeout"),
|
|
|
|
validate:RED.validators.number(true)
|
|
|
|
}
|
2021-09-29 11:45:00 +02:00
|
|
|
},
|
|
|
|
inputs: 1,
|
|
|
|
outputs: 1,
|
|
|
|
icon: "link-call.svg",
|
|
|
|
inputLabels: function(i) {
|
|
|
|
return this.name||this._("link.linkCall");
|
|
|
|
},
|
|
|
|
label: function() {
|
|
|
|
if (this.name) {
|
|
|
|
return this.name;
|
|
|
|
}
|
2022-02-24 20:46:21 +01:00
|
|
|
if (this.linkType === "dynamic") {
|
|
|
|
return this._("link.dynamicLinkLabel");
|
|
|
|
} else if (this.links.length > 0) {
|
2021-09-29 11:45:00 +02:00
|
|
|
var targetNode = RED.nodes.node(this.links[0]);
|
2021-10-14 13:00:27 +02:00
|
|
|
return targetNode && (targetNode.name || this._("link.linkCall"));
|
2021-09-29 11:45:00 +02:00
|
|
|
}
|
2021-10-14 13:00:27 +02:00
|
|
|
return this._("inject.none");
|
2021-09-29 11:45:00 +02:00
|
|
|
},
|
|
|
|
labelStyle: function() {
|
2021-10-14 13:00:27 +02:00
|
|
|
return this.name?"node_label_italic":"";
|
2021-09-29 11:45:00 +02:00
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
2022-02-24 20:46:21 +01:00
|
|
|
const updateVisibility = function() {
|
|
|
|
const static = $('#node-input-linkType').val() !== "dynamic";
|
|
|
|
if(static) {
|
|
|
|
$("div.link-call-target-tree").show();
|
|
|
|
} else {
|
|
|
|
$("div.link-call-target-tree").hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$("#node-input-linkType").on("change",function(d){
|
|
|
|
updateVisibility();
|
|
|
|
});
|
2022-02-28 20:00:58 +01:00
|
|
|
if (["static","dynamic"].indexOf(this.linkType) < 0) {
|
2022-03-01 17:48:31 +01:00
|
|
|
$("#node-input-linkType").val('static');
|
2022-02-28 20:00:58 +01:00
|
|
|
}
|
2022-02-24 20:46:21 +01:00
|
|
|
updateVisibility();
|
2021-09-29 11:45:00 +02:00
|
|
|
onEditPrepare(this,"link in");
|
|
|
|
},
|
|
|
|
oneditsave: function() {
|
|
|
|
onEditSave(this);
|
|
|
|
},
|
|
|
|
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: {
|
2022-04-25 21:30:05 +02:00
|
|
|
name: { value:"_DEFAULT_" },
|
2021-09-29 11:45:00 +02:00
|
|
|
mode: { value: "link" },// link || return
|
2022-04-19 20:17:41 +02:00
|
|
|
links: { value: [], type:"link in[]" }
|
2016-02-13 00:18:08 +01:00
|
|
|
},
|
|
|
|
align:"right",
|
|
|
|
inputs:1,
|
|
|
|
outputs:0,
|
2021-09-29 11:45:00 +02:00
|
|
|
icon: function() {
|
|
|
|
if (this.mode === "return") {
|
|
|
|
return "link-return.svg";
|
|
|
|
} else {
|
|
|
|
return "link-out.svg";
|
|
|
|
}
|
|
|
|
},
|
2017-03-03 00:12:06 +01:00
|
|
|
inputLabels: function(i) {
|
2021-09-29 11:45:00 +02:00
|
|
|
return this.name||(this.mode === "return" ?this._("link.linkOutReturn"):this._("link.linkOut"));
|
2017-03-03 00:12:06 +01:00
|
|
|
},
|
2021-09-29 11:45:00 +02:00
|
|
|
showLabel: false,
|
2016-02-13 00:18:08 +01:00
|
|
|
label: function() {
|
2021-09-29 11:45:00 +02:00
|
|
|
return this.name||(this.mode === "return" ?this._("link.linkOutReturn"):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");
|
2021-09-29 11:45:00 +02:00
|
|
|
$("#node-input-mode").on("change", function() {
|
|
|
|
$(".node-input-link-rows").toggle(this.value === "link")
|
|
|
|
})
|
|
|
|
if (!this.mode) {
|
|
|
|
$("#node-input-mode").val('link').trigger("change");
|
|
|
|
}
|
|
|
|
|
2016-05-17 10:16:58 +02:00
|
|
|
},
|
|
|
|
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
|
|
|
});
|
2021-09-29 11:45:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-17 10:16:58 +02:00
|
|
|
})();
|
2016-02-13 00:18:08 +01:00
|
|
|
</script>
|