mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
fixed comments from @knolleary
This commit is contained in:
parent
2b43e3ee23
commit
f88a4b1791
@ -902,7 +902,7 @@
|
||||
"properties": "Properties",
|
||||
"description": "Description",
|
||||
"appearance": "Appearance",
|
||||
"env": "Env Var",
|
||||
"env": "Environment Variables",
|
||||
"name": "name"
|
||||
}
|
||||
}
|
||||
|
@ -611,40 +611,7 @@ RED.editor = (function() {
|
||||
}
|
||||
|
||||
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;
|
||||
return (JSON.stringify(env0) === JSON.stringify(env1));
|
||||
}
|
||||
|
||||
function buildEditForm(container,formId,type,ns,node) {
|
||||
|
@ -19,13 +19,13 @@ 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>'+
|
||||
'<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" style="margin-bottom: 0px;"><label style="width: auto;" 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" style="margin-bottom: 0px;"><label style="width: auto;" 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>';
|
||||
|
@ -158,7 +158,13 @@ module.exports = function(RED) {
|
||||
},
|
||||
env: {
|
||||
get: function(envVar) {
|
||||
return node.getenv(envVar);
|
||||
if (node && node._flow) {
|
||||
var flow = node._flow;
|
||||
if (flow) {
|
||||
return flow.getSetting(envVar);
|
||||
}
|
||||
}
|
||||
return process.env[envVar];
|
||||
}
|
||||
},
|
||||
setTimeout: function () {
|
||||
|
@ -239,22 +239,6 @@ Node.prototype.receive = function(msg) {
|
||||
}
|
||||
};
|
||||
|
||||
Node.prototype.getenv = function(name) {
|
||||
var flow = this._flow;
|
||||
if (flow) {
|
||||
var val = flow.getSetting(name);
|
||||
return val;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
Node.prototype.setenv = function(name, val) {
|
||||
var flow = this._flow;
|
||||
if (flow) {
|
||||
flow.setSetting(name, val);
|
||||
}
|
||||
};
|
||||
|
||||
function log_helper(self, level, msg) {
|
||||
var o = {
|
||||
level: level,
|
||||
|
@ -462,9 +462,6 @@ class Flow {
|
||||
console.log("==================")
|
||||
}
|
||||
|
||||
getenv(name) {
|
||||
return process.env[name];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,34 +23,6 @@ const flowUtil = require("./util");
|
||||
var Log;
|
||||
|
||||
|
||||
/**
|
||||
* Convert env var definition of subflow template and instance to env var dic
|
||||
* @param {Hash} env1 env var definition of template
|
||||
* @param {Hash} env2 env var definition of instance
|
||||
* @return {Hash} env var dic
|
||||
*/
|
||||
function env2Dic(env0, env1) {
|
||||
var dic = {};
|
||||
function add(env) {
|
||||
for(var i = 0; i < env.length; i++) {
|
||||
var item = env[i];
|
||||
var name = item.name;
|
||||
var info = Object.assign({}, item.info);
|
||||
info.name = name;
|
||||
dic[name] = item;
|
||||
dic[name+"_type"] = { value: item.type };
|
||||
dic[name+"_info"] = { value: info };
|
||||
}
|
||||
}
|
||||
if (env0) {
|
||||
add(env0);
|
||||
}
|
||||
if (env1) {
|
||||
add(env1);
|
||||
}
|
||||
return dic;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class represents a subflow - which is handled as a special type of Flow
|
||||
*/
|
||||
@ -133,14 +105,12 @@ class Subflow extends Flow {
|
||||
var self = this;
|
||||
// Create a subflow node to accept inbound messages and route appropriately
|
||||
var Node = require("../Node");
|
||||
var env = env2Dic(this.subflowDef.env, this.subflowInstance.env);
|
||||
var subflowInstanceConfig = {
|
||||
id: this.subflowInstance.id,
|
||||
type: this.subflowInstance.type,
|
||||
z: this.subflowInstance.z,
|
||||
name: this.subflowInstance.name,
|
||||
wires: [],
|
||||
env: env,
|
||||
_flow: this
|
||||
}
|
||||
if (this.subflowDef.in) {
|
||||
@ -229,11 +199,63 @@ class Subflow extends Flow {
|
||||
* @return {Object} val value of env var
|
||||
*/
|
||||
getSetting(name) {
|
||||
function lookup(env, name) {
|
||||
for(var i = 0; i < env.length; i++) {
|
||||
var item = env[i];
|
||||
if (item.name === name) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function lookupFlow0(env, name) {
|
||||
if (flow.subflowInstance) {
|
||||
var vi = lookup(flow.subflowInstance.env, name);
|
||||
if (vi) {
|
||||
return vi;
|
||||
}
|
||||
}
|
||||
if (flow.subflowDef) {
|
||||
var vt = lookup(flow.subflowDef.env, name);
|
||||
if (vt) {
|
||||
return vt;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function lookupFlow(env, name) {
|
||||
if (name.endsWith("_type")) {
|
||||
var vname = name.substring(0, 5); // len("_type")==5
|
||||
var val = lookupFlow0(env, vname);
|
||||
if (val) {
|
||||
return val.type;
|
||||
}
|
||||
}
|
||||
else if (name.endsWith("_info")) {
|
||||
var vname = name.substring(0, 5); // len("_info")==5
|
||||
var val = lookupFlow0(env, vname);
|
||||
if (val) {
|
||||
return val.info;
|
||||
}
|
||||
}
|
||||
else {
|
||||
var val = lookupFlow0(env, name);
|
||||
if (val) {
|
||||
return val.value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
var node = this.node;
|
||||
if (node) {
|
||||
var env = node.env;
|
||||
if (env && env.hasOwnProperty(name)) {
|
||||
return env[name].value;
|
||||
var flow = node._flow;
|
||||
if (flow) {
|
||||
var v = lookupFlow(flow, name);
|
||||
if (v) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
var parent = this.parent;
|
||||
|
17
packages/node_modules/@node-red/util/lib/util.js
vendored
17
packages/node_modules/@node-red/util/lib/util.js
vendored
@ -419,9 +419,12 @@ function setObjectProperty(msg,prop,value,createMissing) {
|
||||
* @param {String} name - name of variable
|
||||
* @return {String} value of env var
|
||||
*/
|
||||
function getenv(node, name) {
|
||||
if (node && node.getenv) {
|
||||
return node.getenv(name);
|
||||
function getSetting(node, name) {
|
||||
if (node && node._flow) {
|
||||
var flow = node._flow;
|
||||
if (flow) {
|
||||
return flow.getSetting(name);
|
||||
}
|
||||
}
|
||||
return process.env[name];
|
||||
}
|
||||
@ -442,16 +445,16 @@ function evaluateEnvProperty(value, node) {
|
||||
if (/^\${[^}]+}$/.test(value)) {
|
||||
// ${ENV_VAR}
|
||||
var name = value.substring(2,value.length-1);
|
||||
var val = getenv(node, name);
|
||||
var val = getSetting(node, name);
|
||||
return val ? val : "";
|
||||
} else if (!/\${\S+}/.test(value)) {
|
||||
// ENV_VAR
|
||||
var val = getenv(node, value);
|
||||
var val = getSetting(node, value);
|
||||
return val ? val : "";
|
||||
} else {
|
||||
// FOO${ENV_VAR}BAR
|
||||
return value.replace(/\${([^}]+)}/g, function(match, name) {
|
||||
var val = getenv(node, name);
|
||||
var val = getSetting(node, name);
|
||||
return (val ? val : "");
|
||||
});
|
||||
}
|
||||
@ -558,7 +561,7 @@ function prepareJSONataExpression(value,node) {
|
||||
return node.context().global.get(val);
|
||||
});
|
||||
expr.assign('env', function(name) {
|
||||
var val = getenv(node, name);
|
||||
var val = getSetting(node, name);
|
||||
return (val ? val : "");
|
||||
})
|
||||
expr.registerFunction('clone', cloneMessage, '<(oa)-:o>');
|
||||
|
Loading…
Reference in New Issue
Block a user