mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add support of subflow env var
This commit is contained in:
@@ -901,6 +901,7 @@
|
||||
"editor-tab": {
|
||||
"properties": "Properties",
|
||||
"description": "Description",
|
||||
"appearance": "Appearance"
|
||||
"appearance": "Appearance",
|
||||
"env": "Env Var"
|
||||
}
|
||||
}
|
||||
|
@@ -901,6 +901,7 @@
|
||||
"editor-tab": {
|
||||
"properties": "プロパティ",
|
||||
"description": "説明",
|
||||
"appearance": "外観"
|
||||
"appearance": "外観",
|
||||
"env": "環境変数"
|
||||
}
|
||||
}
|
||||
|
@@ -358,7 +358,10 @@ RED.nodes = (function() {
|
||||
}
|
||||
subflows[sf.id] = sf;
|
||||
RED.nodes.registerType("subflow:"+sf.id, {
|
||||
defaults:{name:{value:""}},
|
||||
defaults:{
|
||||
name:{value:""},
|
||||
env:{value:[]}
|
||||
},
|
||||
icon: function() { return sf.icon||"subflow.png" },
|
||||
category: sf.category || "subflows",
|
||||
inputs: sf.in.length,
|
||||
@@ -535,6 +538,7 @@ RED.nodes = (function() {
|
||||
node.category = n.category;
|
||||
node.in = [];
|
||||
node.out = [];
|
||||
node.env = n.env;
|
||||
|
||||
n.in.forEach(function(p) {
|
||||
var nIn = {x:p.x,y:p.y,wires:[]};
|
||||
@@ -1018,6 +1022,7 @@ RED.nodes = (function() {
|
||||
node.name = n.name;
|
||||
node.outputs = subflow.out.length;
|
||||
node.inputs = subflow.in.length;
|
||||
node.env = n.env;
|
||||
} else {
|
||||
if (!node._def) {
|
||||
if (node.x && node.y) {
|
||||
|
@@ -540,7 +540,113 @@ RED.editor = (function() {
|
||||
return label;
|
||||
}
|
||||
|
||||
function buildEditForm(container,formId,type,ns) {
|
||||
function buildEnvForm(container, node) {
|
||||
var env_container = $('#node-input-env-container');
|
||||
env_container
|
||||
.css('min-height','250px').css('min-width','450px')
|
||||
.editableList({
|
||||
addItem: function(container, i, opt) {
|
||||
var row = $('<div/>').appendTo(container);
|
||||
var nameField = $('<input/>', {
|
||||
class: "node-input-env-name",
|
||||
type: "text",
|
||||
style: "margin-length: 5px; width: 32%;"
|
||||
}).appendTo(row);
|
||||
var valueField = $('<input/>',{
|
||||
class: "node-input-env-value",
|
||||
type: "text",
|
||||
style: "margin-left: 5px; width: 65%;"
|
||||
}).appendTo(row)
|
||||
valueField.typedInput({default:'str',
|
||||
types:['str','num','bool','json','bin','re','date']
|
||||
});
|
||||
if (opt) {
|
||||
nameField.val(opt.name);
|
||||
valueField.typedInput('type', opt.type);
|
||||
valueField.typedInput('value', opt.value);
|
||||
}
|
||||
},
|
||||
sortable: true,
|
||||
removable: true
|
||||
});
|
||||
var envs = node.env;
|
||||
if (envs) {
|
||||
for (var i = 0; i < envs.length; i++) {
|
||||
var env = envs[i];
|
||||
env_container.editableList('addItem', env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function convEnv(editable_list) {
|
||||
if (editable_list) {
|
||||
var env = [];
|
||||
editable_list.each(function(i) {
|
||||
var entry = $(this);
|
||||
var nf = entry.find(".node-input-env-name");
|
||||
var vf = entry.find(".node-input-env-value");
|
||||
var name = nf.val();
|
||||
var value = vf.typedInput("value");
|
||||
var type = vf.typedInput("type");
|
||||
var info = {
|
||||
name: name,
|
||||
label: "",
|
||||
value: value,
|
||||
type: type,
|
||||
target_type: "env var",
|
||||
target: name
|
||||
};
|
||||
var item = {
|
||||
name: name,
|
||||
type: type,
|
||||
value: value,
|
||||
info: info
|
||||
};
|
||||
env.push(item);
|
||||
});
|
||||
return env;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isSameEnv(env0, env1) {
|
||||
function isSameInfo(info0, info1) {
|
||||
if (info0 && info1 &&
|
||||
(info0.name === info1.name) &&
|
||||
(info0.label === info1.label) &&
|
||||
(info0.value === info1.value) &&
|
||||
(info0.type === info1.type) &&
|
||||
(info0.target_type === info1.target_type) &&
|
||||
(info0.target === info1.target)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function inEnv(env, item) {
|
||||
for(var i = 0; i < env.length; i++) {
|
||||
var item1 = env[i];
|
||||
if ((item1.name !== item.name) ||
|
||||
(item1.type !== item.type) ||
|
||||
(item1.value !== item.value) ||
|
||||
!isSameInfo(item1.info, item.info)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (env0 && env1 && (env0.length === env1.length)) {
|
||||
for (var i = 0; i < env0.length; i++) {
|
||||
var item0 = env0[i];
|
||||
if (!inEnv(env1, item0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function buildEditForm(container,formId,type,ns,node) {
|
||||
var dialogForm = $('<form id="'+formId+'" class="form-horizontal" autocomplete="off"></form>').appendTo(container);
|
||||
dialogForm.html($("script[data-template-name='"+type+"']").html());
|
||||
ns = ns||"node-red";
|
||||
@@ -561,6 +667,11 @@ RED.editor = (function() {
|
||||
}
|
||||
$(this).attr("data-i18n",keys.join(";"));
|
||||
});
|
||||
|
||||
if ((type === "subflow") || (type === "subflow-template")) {
|
||||
buildEnvForm(dialogForm, node);
|
||||
}
|
||||
|
||||
// Add dummy fields to prevent 'Enter' submitting the form in some
|
||||
// cases, and also prevent browser auto-fill of password
|
||||
// Add in reverse order as they are prepended...
|
||||
@@ -1268,6 +1379,16 @@ RED.editor = (function() {
|
||||
}
|
||||
}
|
||||
|
||||
if (type === "subflow") {
|
||||
var old_env = editing_node.env;
|
||||
var new_env = convEnv($("#node-input-env-container").editableList("items"));
|
||||
if (!isSameEnv(old_env, new_env)) {
|
||||
editing_node.env = new_env;
|
||||
changes.env = editing_node.env;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
var wasChanged = editing_node.changed;
|
||||
editing_node.changed = true;
|
||||
@@ -1373,7 +1494,7 @@ RED.editor = (function() {
|
||||
content: $('<div>', {class:"editor-tray-content"}).appendTo(editorContent).hide(),
|
||||
iconClass: "fa fa-cog"
|
||||
};
|
||||
buildEditForm(nodePropertiesTab.content,"dialog-form",type,ns);
|
||||
buildEditForm(nodePropertiesTab.content,"dialog-form",type,ns,node);
|
||||
editorTabs.addTab(nodePropertiesTab);
|
||||
|
||||
if (!node._def.defaults || !node._def.defaults.hasOwnProperty('info')) {
|
||||
@@ -1986,6 +2107,14 @@ RED.editor = (function() {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
var old_env = editing_node.env;
|
||||
var new_env = convEnv($("#node-input-env-container").editableList("items"));
|
||||
if (!isSameEnv(old_env, new_env)) {
|
||||
editing_node.env = new_env;
|
||||
changes.env = editing_node.env;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
RED.palette.refresh();
|
||||
|
||||
if (changed) {
|
||||
@@ -2063,7 +2192,7 @@ RED.editor = (function() {
|
||||
content: $('<div>', {class:"editor-tray-content"}).appendTo(editorContent).hide(),
|
||||
iconClass: "fa fa-cog"
|
||||
};
|
||||
buildEditForm(nodePropertiesTab.content,"dialog-form","subflow-template");
|
||||
buildEditForm(nodePropertiesTab.content,"dialog-form","subflow-template", undefined, editing_node);
|
||||
editorTabs.addTab(nodePropertiesTab);
|
||||
|
||||
var descriptionTab = {
|
||||
|
@@ -17,10 +17,16 @@
|
||||
RED.subflow = (function() {
|
||||
|
||||
|
||||
var _subflowEditTemplate = '<script type="text/x-red" data-template-name="subflow"><div class="form-row"><label for="node-input-name" data-i18n="[append]editor:common.label.name"><i class="fa fa-tag"></i> </label><input type="text" id="node-input-name"></div></script>';
|
||||
var _subflowEditTemplate = '<script type="text/x-red" data-template-name="subflow">'+
|
||||
'<div class="form-row"><label for="node-input-name" data-i18n="[append]editor:common.label.name"><i class="fa fa-tag"></i> </label><input type="text" id="node-input-name"></div>'+
|
||||
'<div class="form-row"><label data-i18n="[append]editor:editor-tab.env"><i class="fa fa-th-list"></i> </label></div>'+
|
||||
'<div class="form-row node-input-env-container-row"><ol id="node-input-env-container"></ol></div>'+
|
||||
'</script>';
|
||||
var _subflowTemplateEditTemplate = '<script type="text/x-red" data-template-name="subflow-template">'+
|
||||
'<div class="form-row"><i class="fa fa-tag"></i> <label for="subflow-input-name" data-i18n="common.label.name"></label><input type="text" id="subflow-input-name"></div>'+
|
||||
'<div class="form-row"><i class="fa fa-folder-o"></i> <label for="subflow-input-category" data-i18n="editor:subflow.category"></label><select style="width: 250px;" id="subflow-input-category"></select><input style="display:none; margin-left: 10px; width:calc(100% - 250px)" type="text" id="subflow-input-custom-category"></div>'+
|
||||
'<div class="form-row"><label data-i18n="[append]editor:editor-tab.env"><i class="fa fa-th-list"></i> </label></div>'+
|
||||
'<div class="form-row node-input-env-container-row"><ol id="node-input-env-container"></ol></div>'+
|
||||
'<div class="form-row form-tips" id="subflow-dialog-user-count"></div>'+
|
||||
'</script>';
|
||||
|
||||
|
Reference in New Issue
Block a user