-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-function.html
More file actions
100 lines (97 loc) · 3.89 KB
/
python-function.html
File metadata and controls
100 lines (97 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<script type="text/javascript">
RED.nodes.registerType('python-function',{
category: 'function',
color: '#fdd0a2',
defaults: {
name: {value: ""},
func: {value: "\nreturn msg"},
outputs: {value: 1} // Ofuscated way to persist the number of outputs of the node
},
inputs: 1,
outputs: 1,
icon: "function.png",
label: function() {
return this.name;
},
oneditprepare: function() {
$( "#node-input-outputs" ).spinner({
min:1
});
var langTools = ace.require('ace/ext/language_tools');
this.editor = ace.edit('node-input-func-editor');
this.editor.getSession().setMode('ace/mode/python');
this.editor.setValue($("#node-input-func").val(), -1);
this.editor.setOptions({
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
highlightSelectedWord: true,
useSoftTabs: true,
tabSize: 4,
});
var noderedKeywords = [
'msg', 'msg.payload', 'node', 'node.send',
'node.log', 'node.warn', 'node.error', 'node.status'
];
this.editor.completers.push({
getCompletions: function (state, session, pos, prefix, callback) {
callback(null, noderedKeywords.map(function (word) {
return {
name: word,
value: word,
score: 0,
meta: 'Node-RED'
};
}));
}
});
this.editor.focus();
},
oneditsave: function() {
var annot = this.editor.getSession().getAnnotations();
this.noerr = 0;
$("#node-input-noerr").val(0);
for (var k=0; k < annot.length; k++) {
//console.log(annot[k].type,":",annot[k].text, "on line", annot[k].row);
if (annot[k].type === "error") {
$("#node-input-noerr").val(annot.length);
this.noerr = annot.length;
}
}
$("#node-input-func").val(this.editor.getValue());
delete this.editor;
},
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height",height+"px");
this.editor.resize();
}
});
</script>
<script type="text/x-red" data-template-name="python-function">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span>Name</span></label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row" style="margin-bottom: 0px;">
<label for="node-input-func"><i class="fa fa-wrench"></i> <span>Function</span></label>
<input type="hidden" id="node-input-func" autofocus="autofocus">
<input type="hidden" id="node-input-noerr">
</div>
<div class="form-row node-text-editor-row">
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-func-editor" ></div>
</div>
<div class="form-row">
<label for="node-input-outputs"><i class="fa fa-random"></i> <span>Outputs</span></label>
<input id="node-input-outputs" style="width: 60px;" value="1">
</div>
<div class="form-tips"><span>See the Info tab for help writing Python functions</span></div>
</script>
<script type="text/x-red" data-help-name="python-function">
<p>A python function node.</p>
</script>