-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-red-node-camunda-worker.html
More file actions
167 lines (136 loc) · 5.05 KB
/
node-red-node-camunda-worker.html
File metadata and controls
167 lines (136 loc) · 5.05 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<script type="text/x-red" data-template-name="camunda">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<div style="display: inline-block; width: calc(100% - 105px)"><input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"></div>
</div>
<div class="form-row">
<label for="node-input-camunda_endpoint"><i class="fa fa-globe"></i> <span data-i18n="Camunda Endpoint"></span></label>
<input id="node-input-camunda_endpoint" type="text" placeholder="http://">
</div>
<div class="form-row">
<label for="node-input-camunda_topic"><i class="fa fa-bullhorn"></i> <span data-i18n="Camunda Topic"></span></label>
<input id="node-input-camunda_topic" type="text" placeholder="Camunda subscription topic">
</div>
<div class="form-row" style="margin-bottom: 0px;">
<label for="node-input-func"><i class="fa fa-wrench"></i> <span data-i18n="function.label.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" style="position:relative">
<div style="position: absolute; right:0; bottom:calc(100% + 3px);"><button id="node-function-expand-js" class="editor-button editor-button-small"><i class="fa fa-expand"></i></button></div>
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-func-editor" ></div>
</div>
<div class="form-row" style="margin-bottom: 0px">
<label for="node-input-outputs"><i class="fa fa-random"></i> <span data-i18n="function.label.outputs"></span></label>
<input id="node-input-outputs" style="width: 60px;" value="1">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType( 'camunda', {
color:"#fbd0a0",
category: 'input',
defaults: {
name: { value: '' },
camunda_endpoint: { value: 'http://localhost:8080/engine-rest' },
camunda_topic: { value:'' },
func: { value: '\nreturn msg;' },
outputs: { value: 1 },
noerr: { value: 0, required: true, validate:function(v) { return ( (!v) || (v === 0) ) ? true : false; } }
},
inputs: 0,
outputs: 1,
icon: 'feed.png',
label: function() {
return this.name || this._( ' Camunda Worker' );
},
labelStyle: function() {
return this.name ? 'node_label_italic': '';
},
oneditprepare: function() {
var that = this;
$( '#node-input-outputs' ).spinner({
min:1,
change: function( event, ui ) {
var value = this.value;
if ( !value.match(/^\d+$/) ) { value = 1; }
else if ( value < this.min ) { value = this.min; }
if ( value !== this.value ) { $( this ).spinner( 'value', value ); }
}
});
this.editor = RED.editor.createEditor( {
id: 'node-input-func-editor',
mode: 'ace/mode/nrjavascript',
value: $( '#node-input-func' ).val(),
globals: {
msg:true,
context:true,
RED: true,
util: true,
flow: true,
global: true,
console: true,
Buffer: true,
setTimeout: true,
clearTimeout: true,
setInterval: true,
clearInterval: true
}
} );
RED.library.create( {
url: 'camunda', // where to get the data from
type: 'function', // the type of object the library is for
editor: this.editor, // the field name the main text body goes to
mode: 'ace/mode/nrjavascript',
fields:[ 'name', 'camunda_endpoint', 'camunda_topic', 'outputs' ]
});
this.editor.focus();
$( '#node-function-expand-js' ).click( function( e ) {
e.preventDefault();
var value = that.editor.getValue();
RED.editor.editJavaScript({
value: value,
width: 'Infinity',
cursor: that.editor.getCursorPosition(),
mode: 'ace/mode/nrjavascript',
complete: function( v, cursor ) {
that.editor.setValue( v, -1 );
that.editor.gotoLine( cursor.row + 1, cursor.column, false );
setTimeout( function() {
that.editor.focus();
}, 300 );
}
})
})
},
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() );
this.editor.destroy();
delete this.editor;
},
oneditcancel: function() {
this.editor.destroy();
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>