1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge remote-tracking branch 'upstream/master' into stop-start-flows

This commit is contained in:
Steve-Mcl 2022-06-27 18:07:49 +01:00
commit 1e57190b8c
13 changed files with 65 additions and 13 deletions

View File

@ -979,13 +979,14 @@ RED.view.tools = (function() {
* - it uses `<paletteLabel> <N>` - where N is the next available integer that
* doesn't clash with any existing nodes of that type
* @param {Object} node The node to set the name of - if not provided, uses current selection
* @param {{ renameBlank: boolean, renameClash: boolean, generateHistory: boolean }} options Possible options are `renameBlank`, `renameClash` and `generateHistory`
*/
function generateNodeNames(node, options) {
options = options || {
options = Object.assign({
renameBlank: true,
renameClash: true,
generateHistory: true
}
}, options)
let nodes = node;
if (node) {
if (!Array.isArray(node)) {

View File

@ -5875,6 +5875,7 @@ RED.view = (function() {
* @private
*/
function createNode(type, x, y, z) {
const wasDirty = RED.nodes.dirty()
var m = /^subflow:(.+)$/.exec(type);
var activeSubflow = z ? RED.nodes.subflow(z) : null;
if (activeSubflow && m) {
@ -5933,7 +5934,7 @@ RED.view = (function() {
var historyEvent = {
t: "add",
nodes: [nn.id],
dirty: RED.nodes.dirty()
dirty: wasDirty
}
if (activeSubflow) {
var subflowRefresh = RED.subflow.refresh(true);

View File

@ -54,7 +54,7 @@
}
.red-ui-search-results-container {
display: none;
height: 150px;
height: 195px;
.red-ui-editableList-container {
border: 1px dashed $primary-border-color;
border-top: 1px solid $secondary-border-color;

View File

@ -37,7 +37,7 @@ ul.red-ui-sidebar-node-config-list {
}
.red-ui-palette-node {
overflow: hidden;
cursor: default;
&.selected {
border-color: transparent;
box-shadow: 0 0 0 2px $node-selected-color;
@ -58,7 +58,7 @@ ul.red-ui-sidebar-node-config-list {
.red-ui-palette-icon-container {
font-size: 12px;
line-height: 30px;
background-color: $node-icon-background-color;
background-color: $node-port-background;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
a {
@ -68,6 +68,7 @@ ul.red-ui-sidebar-node-config-list {
left: 0;
right: 0;
color: $node-port-label-color;
cursor: pointer;
&:hover {
text-decoration: none;
background: $node-port-background-hover;

View File

@ -118,7 +118,7 @@
.inject-time-row {
padding-left: 110px;
}
.inject-time-row select {
.inject-time-row:not(#inject-time-row-interval) select {
margin: 3px 0;
}
.inject-time-days label {

View File

@ -558,7 +558,7 @@
onadd: function() {
if (this.name === '_DEFAULT_') {
this.name = ''
RED.actions.invoke("core:generate-node-names", this)
RED.actions.invoke("core:generate-node-names", this, {generateHistory: false})
}
}
});

View File

@ -221,7 +221,7 @@
function onAdd() {
if (this.name === '_DEFAULT_') {
this.name = ''
RED.actions.invoke("core:generate-node-names", this)
RED.actions.invoke("core:generate-node-names", this, {generateHistory: false})
}
for (var i=0;i<this.links.length;i++) {
var n = RED.nodes.node(this.links[i]);

View File

@ -639,7 +639,7 @@
onadd: function() {
if (this.name === '_DEFAULT_') {
this.name = ''
RED.actions.invoke("core:generate-node-names", this)
RED.actions.invoke("core:generate-node-names", this, {generateHistory: false})
}
}
});

View File

@ -44,6 +44,14 @@ module.exports = function(RED) {
return undefined;
}
function parseEnv(key) {
var match = /^env\.(.+)/.exec(key);
if (match) {
return match[1];
}
return undefined;
}
/**
* Custom Mustache Context capable to collect message property and node
* flow and global context
@ -74,6 +82,11 @@ module.exports = function(RED) {
return value;
}
// try env
if (parseEnv(name)) {
return this.cachedContextTokens[name];
}
// try flow/global context:
var context = parseContext(name);
if (context) {
@ -156,6 +169,17 @@ module.exports = function(RED) {
var tokens = extractTokens(mustache.parse(template));
var resolvedTokens = {};
tokens.forEach(function(name) {
var env_name = parseEnv(name);
if (env_name) {
var promise = new Promise((resolve, reject) => {
var val = RED.util.evaluateNodeProperty(env_name, 'env', node)
resolvedTokens[name] = val;
resolve();
});
promises.push(promise);
return;
}
var context = parseContext(name);
if (context) {
var type = context.type;

View File

@ -314,11 +314,13 @@ module.exports = function(RED) {
if (err) {
return done(err);
}
msgInfo.send({payload: result});
msgInfo.msg.payload = result;
msgInfo.send(msgInfo.msg);
done();
});
} else {
msgInfo.send({payload: result});
msgInfo.msg.payload = result;
msgInfo.send(msgInfo.msg);
done();
}
} else {

View File

@ -359,6 +359,7 @@ function loadNodeSet(node) {
try {
var loadPromise = null;
var r = require(node.file);
r = r.__esModule ? r.default : r
if (typeof r === "function") {
var red = registryUtil.createNodeApi(node);

View File

@ -414,7 +414,7 @@ module.exports = {
* packages/node_modules/@node-red/editor-client/src/vendor/monaco/dist/theme
* e.g. "tomorrow-night", "upstream-sunburst", "github", "my-theme"
*/
theme: "vs",
// theme: "vs",
/** other overrides can be set e.g. fontSize, fontFamily, fontLigatures etc.
* for the full list, see https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.IStandaloneEditorConstructionOptions.html
*/

View File

@ -144,6 +144,28 @@ describe('template node', function() {
});
});
describe('env var', function() {
before(function() {
process.env.TEST = 'xyzzy';
})
after(function() {
delete process.env.TEST;
})
it('should modify payload from env variable', function(done) {
var flow = [{id:"n1",z:"t1", type:"template", field:"payload", template:"payload={{env.TEST}}",wires:[["n2"]]},{id:"n2",z:"t1",type:"helper"}];
helper.load(templateNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('payload', 'payload=xyzzy');
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
});
it('should modify payload from flow context', function(done) {
var flow = [{id:"n1",z:"t1", type:"template", field:"payload", template:"payload={{flow.value}}",wires:[["n2"]]},{id:"n2",z:"t1",type:"helper"}];
helper.load(templateNode, flow, function() {