mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
update according to comments
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
<ul style="min-width: 600px; margin-bottom: 20px;" id="func-tabs"></ul>
|
||||
</div>
|
||||
|
||||
<div id="func-tabs-content" style="min-height: calc(100% - 80px);">
|
||||
<div id="func-tabs-content" style="min-height: calc(100% - 95px);">
|
||||
|
||||
<div id="func-tab-init" style="display:none">
|
||||
<div class="form-row" style="margin-bottom: 0px;">
|
||||
@@ -17,8 +17,8 @@
|
||||
</div>
|
||||
|
||||
<div class="form-row node-text-editor-row" style="position:relative">
|
||||
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-init-editor" ></div>
|
||||
<div style="position: absolute; right:0; margin-top:5px;"><button id="node-init-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
|
||||
<div style="position: absolute; right:0; bottom: calc(100% + 3px);"><button id="node-init-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
|
||||
<div style="height: 250px; min-height:150px; margin-top: 30px;" class="node-text-editor" id="node-input-init-editor" ></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
</div>
|
||||
|
||||
<div class="form-row node-text-editor-row" style="position:relative">
|
||||
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-func-editor" ></div>
|
||||
<div style="position: absolute; right:0; margin-top:5px;"><button id="node-function-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
|
||||
<div style="position: absolute; right:0; bottom: calc(100% + 3px);"><button id="node-function-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
|
||||
<div style="height: 220px; min-height:120px; margin-top: 30px;" class="node-text-editor" id="node-input-func-editor" ></div>
|
||||
</div>
|
||||
|
||||
<div class="form-row" style="margin-bottom: 0px">
|
||||
@@ -45,8 +45,8 @@
|
||||
<input type="hidden" id="node-input-finalize" autofocus="autofocus">
|
||||
</div>
|
||||
<div class="form-row node-text-editor-row" style="position:relative">
|
||||
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-finalize-editor" ></div>
|
||||
<div style="position: absolute; right:0; margin-top:5px;"><button id="node-finalize-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
|
||||
<div style="position: absolute; right:0; bottom: calc(100% + 3px);"><button id="node-finalize-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
|
||||
<div style="height: 250px; min-height:150px; margin-top: 30px;" class="node-text-editor" id="node-input-finalize-editor" ></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -129,19 +129,34 @@
|
||||
value: $("#node-input-func").val(),
|
||||
globals: globals
|
||||
});
|
||||
var initCode = $("#node-input-initialize").val();
|
||||
var initText = RED._("node-red:function.text.initialize");
|
||||
var isEmptyInitCode = (initCode === "");
|
||||
this.initEditor = RED.editor.createEditor({
|
||||
id: 'node-input-init-editor',
|
||||
mode: 'ace/mode/nrjavascript',
|
||||
value: $("#node-input-initialize").val(),
|
||||
value: (isEmptyInitCode ? initText : initCode),
|
||||
globals: globals
|
||||
});
|
||||
if (isEmptyInitCode) {
|
||||
var count = initText.split("\n").length;
|
||||
this.initEditor.moveCursorTo(count -1, 0);
|
||||
}
|
||||
|
||||
var finalCode = $("#node-input-finalize").val();
|
||||
var finalText = RED._("node-red:function.text.finalize");
|
||||
var isEmptyFinalCode = (finalCode === "");
|
||||
this.finalizeEditor = RED.editor.createEditor({
|
||||
id: 'node-input-finalize-editor',
|
||||
mode: 'ace/mode/nrjavascript',
|
||||
value: $("#node-input-finalize").val(),
|
||||
value: (isEmptyFinalCode ? finalText : finalCode),
|
||||
globals: globals
|
||||
});
|
||||
if (isEmptyFinalCode) {
|
||||
var count = finalText.split("\n").length;
|
||||
this.finalizeEditor.moveCursorTo(count -1, 0);
|
||||
}
|
||||
|
||||
|
||||
RED.library.create({
|
||||
url:"functions", // where to get the data from
|
||||
@@ -266,11 +281,19 @@
|
||||
node.editor.destroy();
|
||||
delete node.editor;
|
||||
|
||||
$("#node-input-initialize").val(node.initEditor.getValue());
|
||||
var initCode = node.initEditor.getValue();
|
||||
if (initCode === RED._("node-red:function.text.initialize")) {
|
||||
initCode = "";
|
||||
}
|
||||
$("#node-input-initialize").val(initCode);
|
||||
node.initEditor.destroy();
|
||||
delete node.initEditor;
|
||||
|
||||
$("#node-input-finalize").val(node.finalizeEditor.getValue());
|
||||
var finalCode = node.finalizeEditor.getValue();
|
||||
if (finalCode === RED._("node-red:function.text.finalize")) {
|
||||
finalCode = "";
|
||||
}
|
||||
$("#node-input-finalize").val(finalCode);
|
||||
node.finalizeEditor.destroy();
|
||||
delete node.finalizeEditor;
|
||||
},
|
||||
@@ -298,9 +321,9 @@
|
||||
this.editor.resize();
|
||||
|
||||
var height = size.height;
|
||||
$("#node-input-init-editor").css("height", (height -100)+"px");
|
||||
$("#node-input-func-editor").css("height", (height -120)+"px");
|
||||
$("#node-input-finalize-editor").css("height", (height -100)+"px");
|
||||
$("#node-input-init-editor").css("height", (height -105)+"px");
|
||||
$("#node-input-func-editor").css("height", (height -140)+"px");
|
||||
$("#node-input-finalize-editor").css("height", (height -105)+"px");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@@ -92,8 +92,8 @@ module.exports = function(RED) {
|
||||
var node = this;
|
||||
node.name = n.name;
|
||||
node.func = n.func;
|
||||
node.ini = n.initialize;
|
||||
node.fin = n.finalize;
|
||||
node.ini = n.initialize ? n.initialize : "";
|
||||
node.fin = n.finalize ? n.finalize : "";
|
||||
|
||||
var handleNodeDoneCall = true;
|
||||
|
||||
@@ -122,14 +122,11 @@ module.exports = function(RED) {
|
||||
"};\n"+
|
||||
node.func+"\n"+
|
||||
"})(msg,send,done);";
|
||||
var iniText = "(async function () {\n"+node.ini +"\n})();";
|
||||
var finText = "(function () {\n"+node.fin +"\n})();";
|
||||
var finScript = null;
|
||||
var finOpt = null;
|
||||
node.topic = n.topic;
|
||||
node.outstandingTimers = [];
|
||||
node.outstandingIntervals = [];
|
||||
var initValue = undefined;
|
||||
var sandbox = {
|
||||
console:console,
|
||||
util:util,
|
||||
@@ -256,9 +253,6 @@ module.exports = function(RED) {
|
||||
if (index > -1) {
|
||||
node.outstandingIntervals.splice(index,1);
|
||||
}
|
||||
},
|
||||
getInitValue: function() {
|
||||
return initValue;
|
||||
}
|
||||
};
|
||||
if (util.hasOwnProperty('promisify')) {
|
||||
@@ -273,13 +267,15 @@ module.exports = function(RED) {
|
||||
try {
|
||||
var iniScript = null;
|
||||
var iniOpt = null;
|
||||
if (iniText || (iniText === "")) {
|
||||
if (node.ini && (node.ini !== "")) {
|
||||
var iniText = "(async function () {\n"+node.ini +"\n})();";
|
||||
iniOpt = createVMOpt(node, " setup");
|
||||
iniScript = new vm.Script(iniText, iniOpt);
|
||||
}
|
||||
node.script = vm.createScript(functionText, createVMOpt(node, ""));
|
||||
if (finText || (finText === "")) {
|
||||
finOpt = createVMOpt(node, "cleanup");
|
||||
if (node.fin && (node.fin !== "")) {
|
||||
var finText = "(function () {\n"+node.fin +"\n})();";
|
||||
finOpt = createVMOpt(node, " cleanup");
|
||||
finScript = new vm.Script(finText, finOpt);
|
||||
}
|
||||
var promise = Promise.resolve();
|
||||
@@ -380,7 +376,6 @@ module.exports = function(RED) {
|
||||
});
|
||||
|
||||
promise.then(function (v) {
|
||||
initValue = v;
|
||||
var msgs = messages;
|
||||
messages = [];
|
||||
while (msgs.length > 0) {
|
||||
|
Reference in New Issue
Block a user