@gregoriusrippenstein/node-red-contrib-introspection 0.11.5 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/nodes/60-client-code.html +261 -35
- package/nodes/60-client-code.js +79 -11
- package/nodes/locales/en-US/60-client-code.json +61 -0
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
function handleMsgTracePacket(e,r){if(r.nodeid){let a=RED.nodes.node(r.nodeid);if(a){var s,r=$("#node-input-msgtracer-trace-treelist").treeList("data");let t=!1;r.forEach(e=>{e.id==a.id&&(t=!0,e.seenCounter+=1,e.sublabel=e.seenCounter+" @ "+e.workspaceLabel)}),t?$("#node-input-msgtracer-trace-treelist").treeList("data",r):(s={id:a.id,label:"",_label:RED.utils.getNodeLabel(a),seenCounter:1,workspaceLabel:(RED.nodes.workspace(a.z)||{label:a.z}).label,sublabel:"1 @ "+(RED.nodes.workspace(a.z)||{label:a.z}).label,selected:!1,checkbox:!1,node:a,icon:RED.utils.createNodeIcon(a,!0)},$("#node-input-msgtracer-trace-treelist").treeList("data",[s,...r]))}}}RED.comms.subscribe("msgtracer:node-received",(e,t)=>{try{handleMsgTracePacket(e,t)}catch(e){console.error(e)}});
|
|
4
4
|
|
|
5
|
-
function handleClientCodeFrontend(event,data){
|
|
5
|
+
function handleClientCodeFrontend(event,data){if("execfunc"==data.msg){let doSend=(e,n,t)=>{"object"==typeof e&&(e={...t,...e}),$.ajax({url:"ClientCode/"+n,type:"POST",contentType:"application/json; charset=utf-8",data:JSON.stringify(e),success:function(e){},error:function(e,t,o){RED.notify("ClientCode Communcation Failure: "+n+": "+t,{type:"error",id:n,timeout:3e3})}})},doStatus=(e,n,t)=>{$.ajax({url:"ClientCode/"+n+"/status",type:"POST",contentType:"application/json; charset=utf-8",data:JSON.stringify(e),success:function(e){},error:function(e,t,o){RED.notify("ClientCode Communcation Failure: "+n+": "+t,{type:"error",id:n,timeout:3e3})}})},doError=(e,t,o)=>{RED.notify("ClientCode Failed: "+t+": "+e,{type:"error",id:t,timeout:3e3}),console.log("ClientCode: Error with node: "+t+": "+e)},nodeid=data.nodeid,_msg=data._msg,msg=data._msg??{},cfg=data._cfg,node=(Object.keys(cfg).forEach(e=>{"overwrite"==data._ops[e]?msg[e]=cfg[e]??msg[e]:msg[e]=msg[e]??cfg[e]}),{id:data.nodeid,send:e=>{doSend(e,nodeid,_msg)},error:e=>{doError(e,nodeid,_msg)},status:e=>{doStatus(e,nodeid,_msg)}}),payload=data.payload,topic=data.topic;eval(data.func)}}RED.comms.subscribe("introspect:client-code-perform",(e,t)=>{try{handleClientCodeFrontend(e,t)}catch(e){console.error(e)}});
|
|
6
6
|
|
|
7
7
|
RED.nodes.registerType('ClientCode',{
|
|
8
8
|
color: '#e5e4ef',
|
|
@@ -18,6 +18,9 @@ function handleClientCodeFrontend(event,data){var doSend,doStatus,doError,nodeid
|
|
|
18
18
|
},
|
|
19
19
|
format: {
|
|
20
20
|
value: "javascript"
|
|
21
|
+
},
|
|
22
|
+
rules: {
|
|
23
|
+
value: [{ t: "default", p: "payload", pt: "msg", to: "", tot: "str" }]
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
26
|
inputs:1,
|
|
@@ -35,6 +38,28 @@ function handleClientCodeFrontend(event,data){var doSend,doStatus,doError,nodeid
|
|
|
35
38
|
$('#node-input-clientcode').val(this.editor.getValue());
|
|
36
39
|
this.editor.destroy();
|
|
37
40
|
delete this.editor;
|
|
41
|
+
|
|
42
|
+
var rules = $("#node-inpclientcode-defaults-container").editableList('items');
|
|
43
|
+
|
|
44
|
+
var node = this;
|
|
45
|
+
node.rules = [];
|
|
46
|
+
|
|
47
|
+
rules.each(function (i) {
|
|
48
|
+
var rule = $(this);
|
|
49
|
+
var type = rule.find(".node-input-rule-type").val();
|
|
50
|
+
|
|
51
|
+
var r = {
|
|
52
|
+
t: type,
|
|
53
|
+
p: rule.find(".node-input-rule-property-name").typedInput('value'),
|
|
54
|
+
pt: rule.find(".node-input-rule-property-name").typedInput('type')
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (type !== "notset" && type !== "debug" && type !== "set") {
|
|
58
|
+
r.to = rule.find(".node-input-rule-property-value").typedInput('value');
|
|
59
|
+
r.tot = rule.find(".node-input-rule-property-value").typedInput('type');
|
|
60
|
+
}
|
|
61
|
+
node.rules.push(r);
|
|
62
|
+
});
|
|
38
63
|
},
|
|
39
64
|
|
|
40
65
|
oneditcancel: function() {
|
|
@@ -42,16 +67,169 @@ function handleClientCodeFrontend(event,data){var doSend,doStatus,doError,nodeid
|
|
|
42
67
|
delete this.editor;
|
|
43
68
|
},
|
|
44
69
|
|
|
70
|
+
//
|
|
71
|
+
// ***********************
|
|
72
|
+
// Prepare editor panel
|
|
73
|
+
// ***********************
|
|
74
|
+
//
|
|
45
75
|
oneditprepare: function() {
|
|
46
76
|
const that = this;
|
|
77
|
+
const node = this;
|
|
47
78
|
const stateId = RED.editor.generateViewStateId("node", this, "");
|
|
48
79
|
|
|
80
|
+
var to = this._("clientcode.action.to");
|
|
81
|
+
var toValueLabel = this._("clientcode.action.toValue", to);
|
|
82
|
+
var search = this._("clientcode.action.search");
|
|
83
|
+
var replace = this._("clientcode.action.replace");
|
|
84
|
+
var regex = this._("clientcode.label.regex");
|
|
85
|
+
|
|
86
|
+
function createPropertyValue(row2_1, row2_2, defaultType) {
|
|
87
|
+
var propValInput = $('<input/>', { class: "node-input-rule-property-value", type: "text" })
|
|
88
|
+
.appendTo(row2_1)
|
|
89
|
+
.typedInput({ default: defaultType || 'str', types: ['str', 'num', 'bool', 'json', 'bin', 'date', 'jsonata'] });
|
|
90
|
+
|
|
91
|
+
propValInput.on("change", function (evt, type, val) {
|
|
92
|
+
row2_2.toggle(type === "msg" || type === "flow" || type === "global" || type === "env");
|
|
93
|
+
})
|
|
94
|
+
return [propValInput, undefined];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var tabs = RED.tabs.create({
|
|
98
|
+
id: "client-code-tabs",
|
|
99
|
+
onchange: function (tab) {
|
|
100
|
+
$("#client-code-tabs-content").children().hide();
|
|
101
|
+
$("#" + tab.id).show();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
tabs.addTab({
|
|
106
|
+
id: "client-code-tabs-default-values",
|
|
107
|
+
iconClass: "fa fa-cog",
|
|
108
|
+
label: "msg parameters"
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
tabs.addTab({
|
|
112
|
+
id: "client-code-tabs-code-editor",
|
|
113
|
+
iconClass: "fa fa-edit",
|
|
114
|
+
label: "editor"
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
tabs.activateTab("client-code-tabs-code-editor");
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
$('#node-inpclientcode-defaults-container').css('min-height', '150px').css('min-width', '450px').editableList({
|
|
121
|
+
addItem: function (container, i, opt) {
|
|
122
|
+
var rule = opt;
|
|
123
|
+
if (!rule.hasOwnProperty('t')) {
|
|
124
|
+
rule = { t: "default", p: "payload", to: "", tot: "str" };
|
|
125
|
+
}
|
|
126
|
+
container.css({
|
|
127
|
+
overflow: 'hidden',
|
|
128
|
+
whiteSpace: 'nowrap'
|
|
129
|
+
});
|
|
130
|
+
let fragment = document.createDocumentFragment();
|
|
131
|
+
var row1 = $('<div/>', { style: "display:flex; align-items: baseline" }).appendTo(fragment);
|
|
132
|
+
var row2 = $('<div/>', { style: "margin-top:8px;" }).appendTo(fragment);
|
|
133
|
+
var row3 = $('<div/>', { style: "margin-top:8px;" }).appendTo(fragment);
|
|
134
|
+
var row4 = $('<div/>', { style: "display:flex;margin-top:8px;align-items: baseline" }).appendTo(fragment);
|
|
135
|
+
|
|
136
|
+
var selectField = $('<select/>', { class: "node-input-rule-type", style: "width:110px; margin-right:10px;" }).appendTo(row1);
|
|
137
|
+
var selectOptions = [
|
|
138
|
+
{ v: "default" },
|
|
139
|
+
{ v: "overwrite" },
|
|
140
|
+
];
|
|
141
|
+
for (var i = 0; i < selectOptions.length; i++) {
|
|
142
|
+
let label = node._("clientcode.action." + (selectOptions[i].l || selectOptions[i].v))
|
|
143
|
+
selectField.append($("<option></option>").val(selectOptions[i].v).text(label));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
var propertyName = $('<input/>', { class: "node-input-rule-property-name", type: "text" })
|
|
147
|
+
.appendTo(row1)
|
|
148
|
+
.typedInput({ types: ['msg'] });
|
|
149
|
+
|
|
150
|
+
var row2_1 = $('<div/>', { style: "display:flex;align-items: baseline" }).appendTo(row2);
|
|
151
|
+
$('<div/>', { style: "display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;" })
|
|
152
|
+
.text(toValueLabel)
|
|
153
|
+
.appendTo(row2_1);
|
|
154
|
+
|
|
155
|
+
var row2_2 = $('<div/>', { style: "margin-top: 4px;" }).appendTo(row2);
|
|
156
|
+
|
|
157
|
+
var row3_1 = $('<div/>', { style: "display:flex;align-items: baseline" }).appendTo(row3);
|
|
158
|
+
$('<div/>', { style: "display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;" })
|
|
159
|
+
.text(search)
|
|
160
|
+
.appendTo(row3_1);
|
|
161
|
+
|
|
162
|
+
var row3_2 = $('<div/>', { style: "display:flex;margin-top:8px;align-items: baseline" }).appendTo(row3);
|
|
163
|
+
$('<div/>', { style: "display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;" })
|
|
164
|
+
.text(replace)
|
|
165
|
+
.appendTo(row3_2);
|
|
166
|
+
|
|
167
|
+
$('<div/>', { style: "display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;" })
|
|
168
|
+
.text(to)
|
|
169
|
+
.appendTo(row4);
|
|
170
|
+
|
|
171
|
+
let propertyValue = null;
|
|
172
|
+
let fromValue = null;
|
|
173
|
+
let toValue = null;
|
|
174
|
+
let moveValue = null;
|
|
175
|
+
|
|
176
|
+
selectField.on("change", function () {
|
|
177
|
+
var type = $(this).val();
|
|
178
|
+
if (propertyValue) {
|
|
179
|
+
propertyValue.typedInput('hide');
|
|
180
|
+
}
|
|
181
|
+
if (fromValue) {
|
|
182
|
+
fromValue.typedInput('hide');
|
|
183
|
+
}
|
|
184
|
+
if (toValue) {
|
|
185
|
+
toValue.typedInput('hide');
|
|
186
|
+
}
|
|
187
|
+
if (moveValue) {
|
|
188
|
+
moveValue.typedInput('hide');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (type != "notset" && type != "debug" && type != "set") {
|
|
192
|
+
if (!propertyValue) {
|
|
193
|
+
var parts = createPropertyValue(row2_1, row2_2);
|
|
194
|
+
propertyValue = parts[0];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
propertyValue.typedInput('show');
|
|
198
|
+
propertyValue.typedInput('value', rule.to);
|
|
199
|
+
propertyValue.typedInput('type', rule.tot);
|
|
200
|
+
|
|
201
|
+
row2.show();
|
|
202
|
+
row3.hide();
|
|
203
|
+
row4.hide();
|
|
204
|
+
} else {
|
|
205
|
+
row2.hide();
|
|
206
|
+
row3.hide();
|
|
207
|
+
row4.hide();
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
selectField.val(rule.t);
|
|
212
|
+
propertyName.typedInput('value', rule.p);
|
|
213
|
+
propertyName.typedInput('type', rule.pt);
|
|
214
|
+
selectField.change();
|
|
215
|
+
container[0].appendChild(fragment);
|
|
216
|
+
},
|
|
217
|
+
removable: true,
|
|
218
|
+
sortable: true
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
this.rules = this.rules ?? [{t: "default", p: "payload", pt: "msg", to: "", tot: "str"}]
|
|
222
|
+
for (var i = 0; i < this.rules.length; i++) {
|
|
223
|
+
var rule = this.rules[i];
|
|
224
|
+
$("#node-inpclientcode-defaults-container").editableList('addItem', rule);
|
|
225
|
+
}
|
|
226
|
+
|
|
49
227
|
this.editor = RED.editor.createEditor({
|
|
50
228
|
id: 'node-input-clientcode-editor',
|
|
51
229
|
mode: 'ace/mode/nrjavascript',
|
|
52
230
|
stateId: stateId,
|
|
53
231
|
globals: {
|
|
54
|
-
msg:true,
|
|
232
|
+
msg:true,
|
|
55
233
|
RED: true,
|
|
56
234
|
node: true,
|
|
57
235
|
alert: true,
|
|
@@ -96,22 +274,53 @@ function handleClientCodeFrontend(event,data){var doSend,doStatus,doError,nodeid
|
|
|
96
274
|
|
|
97
275
|
},
|
|
98
276
|
|
|
277
|
+
//
|
|
278
|
+
// *******************
|
|
279
|
+
// Resize event
|
|
280
|
+
// *******************
|
|
281
|
+
//
|
|
99
282
|
oneditresize: function(size) {
|
|
100
|
-
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
|
|
283
|
+
var rows = $("#dialog-form #client-code-tabs-code-editor>div:not(.node-text-editor-row)");
|
|
101
284
|
var height = $("#dialog-form").height();
|
|
102
285
|
for (var i=0; i<rows.length; i++) {
|
|
103
286
|
height -= $(rows[i]).outerHeight(true);
|
|
104
287
|
}
|
|
105
|
-
|
|
288
|
+
|
|
289
|
+
var rows = $("#dialog-form>.client-code-node-name-row");
|
|
290
|
+
for (var i=0; i<rows.length; i++) {
|
|
291
|
+
height -= $(rows[i]).outerHeight(true);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// footer
|
|
295
|
+
height -= 40;
|
|
296
|
+
|
|
297
|
+
var editorRow = $("#dialog-form #client-code-tabs-code-editor>div.node-text-editor-row");
|
|
106
298
|
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
|
|
107
299
|
$(".node-text-editor").css("height",height+"px");
|
|
300
|
+
|
|
108
301
|
this.editor.resize();
|
|
302
|
+
|
|
303
|
+
//
|
|
304
|
+
//
|
|
305
|
+
//
|
|
306
|
+
if ($('#client-code-tabs-default-values').is(":visible")) {
|
|
307
|
+
var rows = $("#dialog-form #client-code-tabs-default-values>div:not(.node-inpclientcode-defaults-container-row)");
|
|
308
|
+
var height = size.height;
|
|
309
|
+
for (var i=0; i<rows.length; i++) {
|
|
310
|
+
height -= $(rows[i]).outerHeight(true);
|
|
311
|
+
}
|
|
312
|
+
var editorRow = $("#dialog-form #client-code-tabs-default-values>div.node-input-rule-container-row");
|
|
313
|
+
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
|
|
314
|
+
$("#node-inpclientcode-defaults-container").editableList('height', height-60);
|
|
315
|
+
} else {
|
|
316
|
+
$("#node-inpclientcode-defaults-container").editableList('height', height/3);
|
|
317
|
+
}
|
|
109
318
|
}
|
|
110
319
|
});
|
|
111
320
|
</script>
|
|
112
321
|
|
|
113
322
|
<script type="text/html" data-template-name="ClientCode">
|
|
114
|
-
<div class="form-row">
|
|
323
|
+
<div class="form-row client-code-node-name-row">
|
|
115
324
|
<label for="node-input-name">
|
|
116
325
|
<i class="fa fa-tag"></i>
|
|
117
326
|
<span data-i18n="common.label.name">Name</span>
|
|
@@ -119,40 +328,56 @@ function handleClientCodeFrontend(event,data){var doSend,doStatus,doError,nodeid
|
|
|
119
328
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
120
329
|
</div>
|
|
121
330
|
|
|
122
|
-
<div class="form-row
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
331
|
+
<div class="form-row func-tabs-row">
|
|
332
|
+
<ul style="min-width: 400px; margin-bottom: 20px;" id="client-code-tabs"></ul>
|
|
333
|
+
</div>
|
|
334
|
+
|
|
335
|
+
<div id="client-code-tabs-content" style="min-height: calc(100% - 95px);">
|
|
126
336
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
<option value="handlebars">mustache</option>
|
|
131
|
-
<option value="html">HTML</option>
|
|
132
|
-
<option value="json">JSON</option>
|
|
133
|
-
<option value="javascript">JavaScript</option>
|
|
134
|
-
<option value="css">CSS</option>
|
|
135
|
-
<option value="markdown">Markdown</option>
|
|
136
|
-
<option value="php">PHP</option>
|
|
137
|
-
<option value="python">Python</option>
|
|
138
|
-
<option value="sql">SQL</option>
|
|
139
|
-
<option value="yaml">YAML</option>
|
|
140
|
-
<option value="text">None</option>
|
|
141
|
-
</select>
|
|
142
|
-
<button type="button" id="node-clientcode-expand-editor"
|
|
143
|
-
class="red-ui-button red-ui-button-small">
|
|
144
|
-
<i class="fa fa-expand"></i>
|
|
145
|
-
</button>
|
|
337
|
+
<div id="client-code-tabs-default-values" style="display:none;">
|
|
338
|
+
<div class="form-row node-input-rule-container-row node-inpclientcode-defaults-container-row">
|
|
339
|
+
<ol id="node-inpclientcode-defaults-container"></ol>
|
|
146
340
|
</div>
|
|
147
|
-
|
|
341
|
+
</div>
|
|
148
342
|
|
|
149
|
-
|
|
150
|
-
<div style="
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
343
|
+
<div id="client-code-tabs-code-editor">
|
|
344
|
+
<div class="form-row" style="position: relative; margin-bottom: 0px;">
|
|
345
|
+
<label for="node-input-clientcode">
|
|
346
|
+
<i class="fa fa-file-code-o"></i> Client Code
|
|
347
|
+
</label>
|
|
348
|
+
|
|
349
|
+
<div style="position: absolute; right:0;display:inline-block; text-align: right; font-size: 0.8em;">
|
|
350
|
+
Syntax:
|
|
351
|
+
<select id="node-input-format" style="width:110px; font-size: 10px !important; height: 24px; padding:0;">
|
|
352
|
+
<option value="handlebars">mustache</option>
|
|
353
|
+
<option value="html">HTML</option>
|
|
354
|
+
<option value="json">JSON</option>
|
|
355
|
+
<option value="javascript">JavaScript</option>
|
|
356
|
+
<option value="css">CSS</option>
|
|
357
|
+
<option value="markdown">Markdown</option>
|
|
358
|
+
<option value="php">PHP</option>
|
|
359
|
+
<option value="python">Python</option>
|
|
360
|
+
<option value="sql">SQL</option>
|
|
361
|
+
<option value="yaml">YAML</option>
|
|
362
|
+
<option value="text">None</option>
|
|
363
|
+
</select>
|
|
364
|
+
<button type="button" id="node-clientcode-expand-editor"
|
|
365
|
+
class="red-ui-button red-ui-button-small">
|
|
366
|
+
<i class="fa fa-expand"></i>
|
|
367
|
+
</button>
|
|
368
|
+
</div>
|
|
369
|
+
</div>
|
|
154
370
|
|
|
155
|
-
|
|
371
|
+
<div class="form-row node-text-editor-row">
|
|
372
|
+
<div style="height: 250px; min-height:150px;"
|
|
373
|
+
class="node-text-editor"
|
|
374
|
+
id="node-input-clientcode-editor" ></div>
|
|
375
|
+
</div>
|
|
376
|
+
|
|
377
|
+
<input type="hidden" id="node-input-clientcode" autofocus="autofocus">
|
|
378
|
+
</div>
|
|
379
|
+
|
|
380
|
+
</div>
|
|
156
381
|
</script>
|
|
157
382
|
|
|
158
383
|
<script type="text/html" data-help-name="ClientCode">
|
|
@@ -168,6 +393,7 @@ Variables:
|
|
|
168
393
|
node.id - id of this node, same as `nodeid` above
|
|
169
394
|
payload - a reference to msg.payload as it was received by this node
|
|
170
395
|
topic - a reference to the msg.topic as it was recieved by this node
|
|
396
|
+
cfg - an object that represents the default values defined in the msg parameters tab
|
|
171
397
|
|
|
172
398
|
Functionality:
|
|
173
399
|
node.send({..}) - send data to the output port of this node
|
package/nodes/60-client-code.js
CHANGED
|
@@ -58,6 +58,49 @@ module.exports = function (RED) {
|
|
|
58
58
|
var node = this;
|
|
59
59
|
var cfg = config;
|
|
60
60
|
|
|
61
|
+
function getToValue(msg, rule, done) {
|
|
62
|
+
var value = rule.to;
|
|
63
|
+
|
|
64
|
+
if (rule.tot === 'json') {
|
|
65
|
+
value = JSON.parse(rule.to);
|
|
66
|
+
} else if (rule.tot === 'bin') {
|
|
67
|
+
value = Buffer.from(JSON.parse(rule.to))
|
|
68
|
+
} else if (rule.tot === 'str') {
|
|
69
|
+
value = rule.to
|
|
70
|
+
} else if (rule.tot === "num") {
|
|
71
|
+
value = Number(rule.to)
|
|
72
|
+
} else if (rule.tot === "bool") {
|
|
73
|
+
value = /^true$/i.test(rule.to);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (rule.tot === "msg") {
|
|
77
|
+
value = RED.util.getMessageProperty(msg, rule.to);
|
|
78
|
+
} else if ((rule.tot === 'flow') || (rule.tot === 'global')) {
|
|
79
|
+
RED.util.evaluateNodeProperty(rule.to, rule.tot, node, msg, (err, value) => {
|
|
80
|
+
if (err) {
|
|
81
|
+
done(undefined, undefined);
|
|
82
|
+
} else {
|
|
83
|
+
done(undefined, value);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return
|
|
87
|
+
} else if (rule.tot === 'date') {
|
|
88
|
+
value = RED.util.evaluateNodeProperty(rule.to, rule.tot, node)
|
|
89
|
+
} else if (rule.tot === 'jsonata') {
|
|
90
|
+
let jsonExpr = RED.util.prepareJSONataExpression(rule.to, node);
|
|
91
|
+
|
|
92
|
+
RED.util.evaluateJSONataExpression(jsonExpr, msg, (err, value) => {
|
|
93
|
+
if (err) {
|
|
94
|
+
done(RED._("change.errors.invalid-expr", { error: err.message }))
|
|
95
|
+
} else {
|
|
96
|
+
done(undefined, value);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
done(undefined, value);
|
|
102
|
+
}
|
|
103
|
+
|
|
61
104
|
node.on('close', function () {
|
|
62
105
|
node.status({});
|
|
63
106
|
});
|
|
@@ -72,17 +115,42 @@ module.exports = function (RED) {
|
|
|
72
115
|
node.error(e)
|
|
73
116
|
}
|
|
74
117
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
118
|
+
let defaultValues = {}
|
|
119
|
+
let operationDefValue = {}
|
|
120
|
+
|
|
121
|
+
let stupidLoop = (ruleIdx) => {
|
|
122
|
+
if ( ruleIdx >= (cfg.rules || []).length) {
|
|
123
|
+
RED.comms.publish(
|
|
124
|
+
"introspect:client-code-perform",
|
|
125
|
+
RED.util.encodeObject({
|
|
126
|
+
msg: "execfunc",
|
|
127
|
+
payload: msg.payload,
|
|
128
|
+
topic: msg.topic,
|
|
129
|
+
func: msg.clientcode || cfg.clientcode,
|
|
130
|
+
nodeid: node.id,
|
|
131
|
+
_msg: msg,
|
|
132
|
+
_cfg: defaultValues,
|
|
133
|
+
_ops: operationDefValue
|
|
134
|
+
})
|
|
135
|
+
);
|
|
136
|
+
done()
|
|
137
|
+
} else {
|
|
138
|
+
try {
|
|
139
|
+
let rule = cfg.rules[ruleIdx]
|
|
140
|
+
let name = rule.p
|
|
141
|
+
getToValue(msg, rule, (err, value) => {
|
|
142
|
+
defaultValues[name] = value
|
|
143
|
+
operationDefValue[name] = rule.t
|
|
144
|
+
stupidLoop(ruleIdx+1)
|
|
145
|
+
})
|
|
146
|
+
} catch (e) {
|
|
147
|
+
console.log(e)
|
|
148
|
+
stupidLoop(ruleIdx + 1)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
stupidLoop(0)
|
|
86
154
|
});
|
|
87
155
|
}
|
|
88
156
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"clientcode": {
|
|
3
|
+
"label": {
|
|
4
|
+
"statusset": "Status Set",
|
|
5
|
+
"rules": "Rules",
|
|
6
|
+
"rule": "rule",
|
|
7
|
+
|
|
8
|
+
"set": "set __property__",
|
|
9
|
+
"change": "change __property__",
|
|
10
|
+
"delete": "delete __property__",
|
|
11
|
+
"move": "move __property__",
|
|
12
|
+
|
|
13
|
+
"changeCount": "assert: __count__ values",
|
|
14
|
+
"regex": "Use regular expressions",
|
|
15
|
+
"deepCopy": "Deep copy value",
|
|
16
|
+
|
|
17
|
+
"notmth": "not match __property__",
|
|
18
|
+
"mth": "match __property__",
|
|
19
|
+
"eql": "equal __property__",
|
|
20
|
+
"noteql": "not equal __property__",
|
|
21
|
+
"notset": "not set __property__",
|
|
22
|
+
"debug": "debug __property__",
|
|
23
|
+
"unsupported": "supported rule __property__",
|
|
24
|
+
|
|
25
|
+
"ignore_failure_if_succeed": "Ignore failure if succeed once"
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
"action": {
|
|
29
|
+
"default": "Default",
|
|
30
|
+
"overwrite": "Overwrite",
|
|
31
|
+
"set": "Defined",
|
|
32
|
+
"change": "Change",
|
|
33
|
+
"delete": "Delete",
|
|
34
|
+
"move": "Move",
|
|
35
|
+
"toValue": "to the value",
|
|
36
|
+
"to": "to",
|
|
37
|
+
"search": "Search for",
|
|
38
|
+
"replace": "Replace with",
|
|
39
|
+
|
|
40
|
+
"notmth": "Not Match",
|
|
41
|
+
"mth": "Match",
|
|
42
|
+
"eql": "Equal",
|
|
43
|
+
"noteql": "Not Equal",
|
|
44
|
+
"notset": "Not Defined",
|
|
45
|
+
"debug": "Debug"
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
"errors": {
|
|
49
|
+
"invalid-from": "Invalid 'from' property: __error__",
|
|
50
|
+
"invalid-json": "Invalid 'to' JSON property",
|
|
51
|
+
"invalid-expr": "Invalid JSONata expression: __error__",
|
|
52
|
+
"no-override": "Cannot set property of non-object type: __property__",
|
|
53
|
+
"invalid-prop": "Invalid property expression: __property__",
|
|
54
|
+
"invalid-json-data": "Invalid JSON data: __error__"
|
|
55
|
+
},
|
|
56
|
+
"status": {
|
|
57
|
+
"waiting": "Waiting for Godot",
|
|
58
|
+
"timeout": "No more time to waiting"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|