@gregoriusrippenstein/node-red-contrib-introspection 0.2.9 → 0.3.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/README.md CHANGED
@@ -75,7 +75,7 @@ This is a hack that uses the `onpaletteadd` callback to do its magic. If this fu
75
75
 
76
76
  A node for inserting an SVG image into the workspace. The image is layered above the grid but below nodes and their connections. The input message must contain SVG data (in string form) in the `payload` attribute.
77
77
 
78
- ### GetFlows -- Experimental
78
+ ### GetFlows
79
79
 
80
80
  Node retrieves the current `flows.json` from the server but using the [Node-RED API](https://nodered.org/docs/api/admin/methods/get/flows/) so that it is storage independent. It returns the flows as a `payload` of the message.
81
81
 
@@ -85,18 +85,18 @@ GetFlows supports version selection of the flows and it has limited authenticati
85
85
 
86
86
  Inspired by the [dsm](https://flows.nodered.org/node/node-red-contrib-dsm) package that has a [backup](https://github.com/cflurin/node-red-contrib-dsm/wiki/Backup) state machine.
87
87
 
88
- ## Examples
88
+ ## Node-RED Versions
89
89
 
90
- There are [example flows](/examples) contained in the package, examples can also be found online:
90
+ These nodes have been tested and found to work on Node-RED 3.0.2 and 3.1.0.beta.4.
91
91
 
92
- - [Orphans](https://demo.openmindmap.org/omm/#flow/3ebb65fdbecb182e/n/2be3f8794979d47b) - node is top left of flow or search for `type:Orphans`
93
- - [Seeker](https://demo.openmindmap.org/omm/#flow/40ea5f2aea6592ae/n/b5f189a78d829197) - top left and the [Sink](https://demo.openmindmap.org/omm/#flow/459c271a96458c7c/n/e3262d9d2791ab78) - top right
94
- - [Screenshot](https://demo.openmindmap.org/omm/#flow/4e2d8c13066b705e/n/499b1383580831aa) - top left
95
- - [DrawSVG](https://demo.openmindmap.org/omm/#flow/6c8ce462533a1da4/n/248f2edd3d8acd96)
92
+ ## Examples
96
93
 
97
- Example screenshot:
94
+ There are [example flows](/examples) contained in the package, examples can also be found online at [FlowHub.org](https://flowhub.org):
98
95
 
99
- ![example screenshot](/assets/screenshot.svg)
96
+ - [Orphans](https://flowhub.org/f/2401c255b056e0e1)
97
+ - [Sink and Seeker](https://flowhub.org/f/139a816449acd89f)
98
+ - [Screenshot](https://flowhub.org/f/07b2d0f3b0445ab5)
99
+ - [DrawSVG](https://flowhub.org/f/141037dcda5b69fd)
100
100
 
101
101
  ## License
102
102
 
@@ -6,15 +6,39 @@
6
6
  // Tested this on Node-RED 3.1.0.beta.4 - dunno about other 3.1.x.beta.y
7
7
  //****
8
8
 
9
- handleSvgObject( $($('svg[width=8000]')[0]), callbackWithSvgCode );
9
+ return (callbackWithSvgCode) => {
10
+ try {
11
+ handleSvgObject( $($('svg[width=8000]')[0]), callbackWithSvgCode );
12
+ } catch ( e ) {
13
+ var msg = "Error Generating SVG: " + JSON.stringify(e);
14
+
15
+ red.notify(msg,{ type: "error" });
16
+
17
+ var svgData = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg width="1000" height="1000" viewBox="0 0 1000 1000" pointer-events="all" style="cursor: crosshair; touch-action: none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style>.small { font: bold 20px sans-serif; fill: red;}</style><text x="10" y="30" class="small">'+msg+'</text></svg>';
18
+
19
+ callbackWithSvgCode(svgData);
20
+ }
21
+ }
10
22
  }
11
23
 
12
- function nr_intro_generate_svg_3_0( callbackWithSvgCode ) {
24
+ function nr_intro_generate_svg_3_0( red ) {
13
25
  //****
14
26
  // for Node-RED v3.0.x (well 3.0.2 tested, dunno about 3.0.1)
15
27
  //****
16
28
 
17
- handleSvgObject( $($('svg')[0]), callbackWithSvgCode);
29
+ return (callbackWithSvgCode) => {
30
+ try {
31
+ handleSvgObject( $($('svg')[0]), callbackWithSvgCode);
32
+ } catch ( e ) {
33
+ var msg = "Error Generating SVG: " + JSON.stringify(e);
34
+
35
+ red.notify(msg,{ type: "error" });
36
+
37
+ var svgData = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg width="1000" height="1000" viewBox="0 0 1000 1000" pointer-events="all" style="cursor: crosshair; touch-action: none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style>.small { font: bold 20px sans-serif; fill: red;}</style><text x="10" y="30" class="small">'+msg+'</text></svg>';
38
+
39
+ callbackWithSvgCode(svgData);
40
+ }
41
+ }
18
42
  }
19
43
 
20
44
 
@@ -29,6 +53,9 @@
29
53
  var preParseSvg = origSvg.clone();
30
54
  preParseSvg.find("foreignObject").remove();
31
55
 
56
+ // these are svgdraw inserts, this would be mirroring mirroring ...
57
+ preParseSvg.find("svg.__screenshot").remove();
58
+
32
59
  var hwAttrs = (
33
60
  'width="' + origSvg.attr('width') + '" height="' +
34
61
  origSvg.attr('height') + '"'
@@ -39,7 +66,7 @@
39
66
  '<?xml version="1.0" standalone="no"?>\r\n' +
40
67
  '<svg ' + hwAttrs + ' pointer-events="all" style="cursor: crosshair; '+
41
68
  'touch-action: none;" xmlns="http://www.w3.org/2000/svg" '+
42
- 'xmlns:xlink="http://www.w3.org/1999/xlink">\r\n'
69
+ 'class="__screenshot" xmlns:xlink="http://www.w3.org/1999/xlink">\r\n'
43
70
  );
44
71
 
45
72
  var svgBody = preParseSvg.html();
@@ -151,6 +178,17 @@
151
178
  }
152
179
  }
153
180
 
181
+ var removeAllClassAndIdAttrs = (doc) => {
182
+ ["g", "rect", "line", "path", "circle", "image", "text"].forEach((t)=>{
183
+ $(doc.getElementsByTagName(t)).each( (idx, elem ) => {
184
+ elem.setAttribute("class","");
185
+ elem.setAttribute("id","");
186
+ });
187
+ });
188
+
189
+ return doc;
190
+ };
191
+
154
192
  // probably missed some elements ...
155
193
  var tagnames = [ "g", "rect", "line", "path", "circle", "image" ];
156
194
  tagnames.forEach( function(tagname) {
@@ -242,7 +280,9 @@
242
280
  var cb = (cntr) => {
243
281
  if ( cntr < 0 ) {
244
282
  delete imageCache;
245
- callbackWithSvgCode((new XMLSerializer()).serializeToString(doc));
283
+ callbackWithSvgCode((new XMLSerializer()).serializeToString(
284
+ removeAllClassAndIdAttrs(doc)
285
+ ));
246
286
  } else {
247
287
  getDataAndCallbackWhenDone( imageColl.item(cntr), cntr, cb );
248
288
  }
@@ -254,27 +294,35 @@
254
294
  cb );
255
295
  } else {
256
296
  delete imageCache;
257
- callbackWithSvgCode( (new XMLSerializer()).serializeToString(doc) );
297
+ callbackWithSvgCode( (new XMLSerializer()).serializeToString(
298
+ removeAllClassAndIdAttrs(doc)
299
+ ));
258
300
  }
259
301
  };
260
302
 
261
- function generatorFunctionForVersion(version) {
262
- var major = version[0]; // 3.0.x or 3.1.x --> making assumptions that
263
- var minor = version[2]; // between minor version nothing changed
264
-
265
- var dummy = (cd) => {
266
- if ( cb ) {
267
- var svgData = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg width="10" height="10" pointer-events="all" style="cursor: crosshair; touch-action: none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>'
268
- cb(svgData);
269
- }
270
- };
271
-
272
- if ( major == "3" ) {
273
- if ( minor == "0" ) { return nr_intro_generate_svg_3_0; }
274
- if ( minor == "1" ) { return nr_intro_generate_svg_3_1; }
275
- }
276
-
277
- return dummy;
303
+ function generatorFunctionForVersion(red) {
304
+ var version = red.settings.version.split(".")
305
+ var major = version[0]; // 3.0.x or 3.1.x --> making assumptions that
306
+ var minor = version[1]; // between minor version nothing changed
307
+
308
+ var dummy = (red) => {
309
+ return (cb) => {
310
+ var msg = "Node-RED version (" + red.settings.version + ") not supported";
311
+ red.notify(msg,{ type: "error" });
312
+
313
+ if ( cb ) {
314
+ var svgData = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg width="1000" height="1000" viewBox="0 0 1000 1000" pointer-events="all" style="cursor: crosshair; touch-action: none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style>.small { font: bold 20px sans-serif; fill: red;}</style><text x="10" y="30" class="small">'+msg+'</text></svg>';
315
+ cb(svgData);
316
+ }
317
+ };
318
+ };
319
+
320
+ if ( major == "3" ) {
321
+ if ( minor == "0" ) { return nr_intro_generate_svg_3_0(red); }
322
+ if ( minor == "1" ) { return nr_intro_generate_svg_3_1(red); }
323
+ }
324
+
325
+ return dummy(red);
278
326
  };
279
327
 
280
328
  /*
@@ -291,11 +339,12 @@
291
339
  }
292
340
 
293
341
  var notification = data.notification;
294
- generatorFunctionForVersion(RED.settings.version)( (svgdata) => {
342
+
343
+ generatorFunctionForVersion(RED)( (svgdata) => {
295
344
  $.ajax({
296
345
  type: "POST",
297
- url: "/screenshot",
298
- dataType: "image/svg+xml;charset=utf-8",
346
+ url: data.endpoint,
347
+ dataType: "application/json;charset=utf-8",
299
348
  data: {
300
349
  ...data,
301
350
  d: svgdata
@@ -315,7 +364,7 @@
315
364
  case 404:
316
365
  // Http-in POST node is missing
317
366
  RED.notify(
318
- "Missing http-in node: method: POST, path: /screenshot.", {
367
+ "Missing http-in node: method: POST, path: " + data.endpoint, {
319
368
  type: "error"
320
369
  }
321
370
  );
@@ -347,10 +396,13 @@
347
396
  paletteLabel: "Screenshot",
348
397
  defaults: {
349
398
  name: {
350
- value:"",
399
+ value: "",
351
400
  },
352
401
  screenshot: {
353
- value:""
402
+ value: ""
403
+ },
404
+ endpoint: {
405
+ value: "/screenshot"
354
406
  },
355
407
  },
356
408
  inputs:1,
@@ -395,7 +447,7 @@
395
447
 
396
448
  this.editor.setValue( "Please wait, screenshot being prepared ..." );
397
449
 
398
- generatorFunctionForVersion(RED.settings.version)( (svgdata) => {
450
+ generatorFunctionForVersion(RED)( (svgdata) => {
399
451
  that.editor.setValue( svgdata );
400
452
  });
401
453
 
@@ -479,6 +531,14 @@
479
531
  <input type="text" id="node-input-name" placeholder="Name">
480
532
  </div>
481
533
 
534
+ <div class="form-row">
535
+ <label for="node-input-endpoint">
536
+ <i class="fa fa-send-o"></i>
537
+ <span>Post Endpoint</span>
538
+ </label>
539
+ <input type="text" id="node-input-endpoint" placeholder="/screenshot">
540
+ </div>
541
+
482
542
  <div class="form-row" style="position: relative; margin-bottom: 0px;">
483
543
  <label for="node-input-screenshot"><i class="fa fa-file-code-o"></i> <span data-i18n="screenshot.label.screenshot">Screenshot</span></label>
484
544
  <input type="hidden" id="node-input-screenshot" autofocus="autofocus">
@@ -14,6 +14,7 @@ module.exports = function(RED) {
14
14
  RED.util.encodeObject({
15
15
  ...msg,
16
16
  msg: "timer-tripped",
17
+ endpoint: cfg.endpoint,
17
18
  })
18
19
  );
19
20
 
@@ -23,5 +24,6 @@ module.exports = function(RED) {
23
24
  send(msg);
24
25
  });
25
26
  }
27
+
26
28
  RED.nodes.registerType("Screenshot", ScreenshotFunctionality);
27
29
  }
@@ -1,7 +1,19 @@
1
1
  <script type="text/javascript">
2
2
  RED.comms.subscribe("introspect:drawsvg", (event,data) => {
3
3
  if ( data.msg == "svgdata" ) {
4
- $($($('svg')[0]).find('> g > g > g')[2]).append(data.payload);
4
+ var version = RED.settings.version.split(".");
5
+
6
+ if ( version[0] == "3" && version[1] == "0" ) {
7
+ $($($('svg')[0]).find('> g > g > g')[2]).append(
8
+ data.payload
9
+ );
10
+ }
11
+
12
+ if ( version[0] == "3" && version[1] == "1" ) {
13
+ $($($('svg[width=8000]')[0]).find('> g > g > g')[2]).append(
14
+ data.payload
15
+ );
16
+ }
5
17
  }
6
18
  });
7
19
 
@@ -11,7 +11,7 @@ module.exports = function(RED) {
11
11
 
12
12
  node.on("input", function(msg, send, done) {
13
13
  RED.comms.publish("introspect:drawsvg", RED.util.encodeObject({
14
- ...msg,
14
+ payload: msg.payload,
15
15
  msg: "svgdata",
16
16
  }));
17
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gregoriusrippenstein/node-red-contrib-introspection",
3
- "version": "0.2.9",
3
+ "version": "0.3.0",
4
4
  "dependencies": {
5
5
  "got": "latest"
6
6
  },