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 * - it uses `<paletteLabel> <N>` - where N is the next available integer that
* doesn't clash with any existing nodes of that type * 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 {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) { function generateNodeNames(node, options) {
options = options || { options = Object.assign({
renameBlank: true, renameBlank: true,
renameClash: true, renameClash: true,
generateHistory: true generateHistory: true
} }, options)
let nodes = node; let nodes = node;
if (node) { if (node) {
if (!Array.isArray(node)) { if (!Array.isArray(node)) {

View File

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

View File

@ -54,7 +54,7 @@
} }
.red-ui-search-results-container { .red-ui-search-results-container {
display: none; display: none;
height: 150px; height: 195px;
.red-ui-editableList-container { .red-ui-editableList-container {
border: 1px dashed $primary-border-color; border: 1px dashed $primary-border-color;
border-top: 1px solid $secondary-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 { .red-ui-palette-node {
overflow: hidden; overflow: hidden;
cursor: default;
&.selected { &.selected {
border-color: transparent; border-color: transparent;
box-shadow: 0 0 0 2px $node-selected-color; 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 { .red-ui-palette-icon-container {
font-size: 12px; font-size: 12px;
line-height: 30px; line-height: 30px;
background-color: $node-icon-background-color; background-color: $node-port-background;
border-top-right-radius: 4px; border-top-right-radius: 4px;
border-bottom-right-radius: 4px; border-bottom-right-radius: 4px;
a { a {
@ -68,6 +68,7 @@ ul.red-ui-sidebar-node-config-list {
left: 0; left: 0;
right: 0; right: 0;
color: $node-port-label-color; color: $node-port-label-color;
cursor: pointer;
&:hover { &:hover {
text-decoration: none; text-decoration: none;
background: $node-port-background-hover; background: $node-port-background-hover;

View File

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

View File

@ -558,7 +558,7 @@
onadd: function() { onadd: function() {
if (this.name === '_DEFAULT_') { if (this.name === '_DEFAULT_') {
this.name = '' 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() { function onAdd() {
if (this.name === '_DEFAULT_') { if (this.name === '_DEFAULT_') {
this.name = '' 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++) { for (var i=0;i<this.links.length;i++) {
var n = RED.nodes.node(this.links[i]); var n = RED.nodes.node(this.links[i]);

View File

@ -639,7 +639,7 @@
onadd: function() { onadd: function() {
if (this.name === '_DEFAULT_') { if (this.name === '_DEFAULT_') {
this.name = '' 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; 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 * Custom Mustache Context capable to collect message property and node
* flow and global context * flow and global context
@ -74,6 +82,11 @@ module.exports = function(RED) {
return value; return value;
} }
// try env
if (parseEnv(name)) {
return this.cachedContextTokens[name];
}
// try flow/global context: // try flow/global context:
var context = parseContext(name); var context = parseContext(name);
if (context) { if (context) {
@ -156,6 +169,17 @@ module.exports = function(RED) {
var tokens = extractTokens(mustache.parse(template)); var tokens = extractTokens(mustache.parse(template));
var resolvedTokens = {}; var resolvedTokens = {};
tokens.forEach(function(name) { 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); var context = parseContext(name);
if (context) { if (context) {
var type = context.type; var type = context.type;

View File

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

View File

@ -359,6 +359,7 @@ function loadNodeSet(node) {
try { try {
var loadPromise = null; var loadPromise = null;
var r = require(node.file); var r = require(node.file);
r = r.__esModule ? r.default : r
if (typeof r === "function") { if (typeof r === "function") {
var red = registryUtil.createNodeApi(node); 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 * packages/node_modules/@node-red/editor-client/src/vendor/monaco/dist/theme
* e.g. "tomorrow-night", "upstream-sunburst", "github", "my-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. /** 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 * 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) { 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"}]; 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() { helper.load(templateNode, flow, function() {