@gregoriusrippenstein/node-red-contrib-introspection 0.2.6 → 0.2.9

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.
@@ -1,10 +1,24 @@
1
1
  <script type="text/javascript">
2
- function nr_intro_generate_svg( callbackWithSvgCode ) {
3
- //
4
- // begin the SVG conversion code.
5
- //
6
- var origSvg = $($('svg')[0]);
2
+ function nr_intro_generate_svg_3_1( callbackWithSvgCode ) {
3
+ //****
4
+ // Node-RED 3.1.x has multiple SVGs all over the place, so we
5
+ // need to look for the one with 8000x8000.
6
+ // Tested this on Node-RED 3.1.0.beta.4 - dunno about other 3.1.x.beta.y
7
+ //****
7
8
 
9
+ handleSvgObject( $($('svg[width=8000]')[0]), callbackWithSvgCode );
10
+ }
11
+
12
+ function nr_intro_generate_svg_3_0( callbackWithSvgCode ) {
13
+ //****
14
+ // for Node-RED v3.0.x (well 3.0.2 tested, dunno about 3.0.1)
15
+ //****
16
+
17
+ handleSvgObject( $($('svg')[0]), callbackWithSvgCode);
18
+ }
19
+
20
+
21
+ function handleSvgObject( origSvg, callbackWithSvgCode ) {
8
22
  // the DOMParser of Firefox does not like foreignObjects, so remove them.
9
23
  // Correction: DOMParser doesn't mind foreignObjects as long as there is
10
24
  // any HTML/<img>-tags in the foreignObjects.,,, of course, image tags
@@ -169,7 +183,6 @@
169
183
  };
170
184
 
171
185
  if ( imageCache[hrefSrc] ) {
172
- console.log( "FOUND " + hrefSrc + " in cache");
173
186
  elem.setAttribute(
174
187
  "xlink:href",
175
188
  "data:image/" + fileType[postfix] + ";base64," + imageCache[hrefSrc]
@@ -245,6 +258,25 @@
245
258
  }
246
259
  };
247
260
 
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;
278
+ };
279
+
248
280
  /*
249
281
  When the server side of this node is triggered, it posts a message on
250
282
  the communication channel. The frontend node captures that message,
@@ -259,7 +291,7 @@
259
291
  }
260
292
 
261
293
  var notification = data.notification;
262
- nr_intro_generate_svg( (svgdata) => {
294
+ generatorFunctionForVersion(RED.settings.version)( (svgdata) => {
263
295
  $.ajax({
264
296
  type: "POST",
265
297
  url: "/screenshot",
@@ -363,7 +395,7 @@
363
395
 
364
396
  this.editor.setValue( "Please wait, screenshot being prepared ..." );
365
397
 
366
- nr_intro_generate_svg( (svgdata) => {
398
+ generatorFunctionForVersion(RED.settings.version)( (svgdata) => {
367
399
  that.editor.setValue( svgdata );
368
400
  });
369
401
 
@@ -135,6 +135,19 @@
135
135
  });
136
136
 
137
137
  dirList.treeList('data',items);
138
+
139
+ $("#node-input-back-home-but").on("click", function(e) {
140
+ e.preventDefault();
141
+ var nde = RED.nodes.node(node.id);
142
+ if ( nde ) {
143
+ RED.workspaces.show(nde.z,false,false,true);
144
+ nde.highlighted = true;
145
+ nde.dirty = true;
146
+ RED.view.reveal(nde.id,true)
147
+ RED.view.redraw();
148
+ RED.tray.close();
149
+ }
150
+ });
138
151
  },
139
152
 
140
153
  oneditsave: function() {
@@ -148,8 +161,9 @@
148
161
  </script>
149
162
 
150
163
  <script type="text/html" data-template-name="Orphans">
151
- <div class="form-row">
152
- <label><i class="fa fa-tag"></i> <span>Orphans</span></label>
164
+ <div class="form-row node-input-target-row">
165
+ <button id="node-input-back-home-but"
166
+ class="red-ui-button">Back Home</button>
153
167
  </div>
154
168
 
155
169
  <div class="form-row node-input-target-row node-input-target-list-row" style="position: relative; min-height: 100px">
@@ -11,13 +11,41 @@ module.exports = function(RED) {
11
11
 
12
12
  node.on("input", function(msg, send, done) {
13
13
  var os = require('os');
14
- var got = require('got');
15
14
 
16
15
  var baseUrl = "http://" + os.hostname() + ":" + RED.settings.get("uiPort");
17
16
  if ( RED.settings.get("httpAdminRoot") != "/" ) {
18
17
  baseUrl += RED.settings.get("httpAdminRoot");
19
18
  }
20
19
 
20
+ var getFlows = (hdrs, got) => {
21
+ got.get( baseUrl + "/flows", {
22
+ headers: {
23
+ "Node-RED-API-Version": cfg.flowVersion,
24
+ ...hdrs
25
+ }
26
+ }).then( res => {
27
+ var bodySize = res.body.length;
28
+
29
+ send({
30
+ ...msg,
31
+ payload: res.body
32
+ });
33
+
34
+ node.status({fill:"green",shape:"dot",text:"Good"});
35
+ setTimeout( function() {
36
+ node.status({
37
+ fill: "blue",
38
+ shape: "dot",
39
+ text: "Flow size: " + bodySize
40
+ })
41
+ }, 450);
42
+
43
+ }).catch( err => {
44
+ node.status({fill:"red",shape:"dot",text:"Failed"});
45
+ node.error(err)
46
+ });
47
+ };
48
+
21
49
  if ( cfg.useAuthentication ) {
22
50
  var username = undefined;
23
51
  var password = undefined;
@@ -48,41 +76,26 @@ module.exports = function(RED) {
48
76
  "password": password
49
77
  }
50
78
 
51
- got.post( baseUrl + "/auth/token", {
52
- json: data
53
- }).then( res => {
54
- node.status({fill:"blue",shape:"dot",text:"Requesting flows"});
55
-
56
- var access_token = JSON.parse(res.body).access_token;
57
- got.get( baseUrl + "/flows", {
58
- headers: {
59
- "Node-RED-API-Version": cfg.flowVersion,
60
- "Authorization": "Bearer " + access_token
61
- }
79
+ import('got').then( (module) => {
80
+ module.got.post( baseUrl + "/auth/token", {
81
+ json: data
62
82
  }).then( res => {
63
- var bodySize = res.body.length;
64
-
65
- send( {
66
- ...msg,
67
- payload: res.body
83
+ node.status({
84
+ fill:"blue",
85
+ shape:"dot",
86
+ text:"Requesting flows"
68
87
  });
69
88
 
70
- node.status({fill:"green",shape:"dot",text:"Good"});
71
- setTimeout( function() {
72
- node.status({
73
- fill: "blue",
74
- shape: "dot",
75
- text: "Flow size: " + bodySize
76
- })
77
- }, 450);
89
+ var access_token = JSON.parse(res.body).access_token;
78
90
 
79
- }).catch( err => {
91
+ getFlows({
92
+ "Authorization": "Bearer " + access_token
93
+ }, module.got);
94
+
95
+ }).catch((err) => {
80
96
  node.status({fill:"red",shape:"dot",text:"Failed"});
81
- node.error(err)
97
+ node.error( err );
82
98
  });
83
- }).catch((err) => {
84
- node.status({fill:"red",shape:"dot",text:"Failed"});
85
- node.error( err );
86
99
  });
87
100
  }
88
101
  })
@@ -93,36 +106,12 @@ module.exports = function(RED) {
93
106
  * Authentication free zone...
94
107
  */
95
108
  node.status({fill:"blue",shape:"dot",text:"Requesting flows"});
96
-
97
- got.get( baseUrl + "/flows",
98
- {headers: {"Node-RED-API-Version": cfg.flowVersion}}
99
- ).then( res => {
100
- if ( res.statusCode == 200 ) {
101
- var bodySize = res.body.length;
102
-
103
- send( {
104
- ...msg,
105
- payload: res.body
106
- });
107
-
108
- node.status({fill:"green",shape:"dot",text:"Good"});
109
- setTimeout( function() {
110
- node.status({
111
- fill: "blue",
112
- shape: "dot",
113
- text: "Flow size: " + bodySize
114
- })
115
- }, 450);
116
- } else {
117
- node.error( res );
118
- node.status({fill:"red",shape:"dot",text:"Failed"});
119
- }
120
- }).catch( err => {
121
- node.status({fill:"red",shape:"dot",text:"Failed"});
122
- node.error(err)
109
+ import('got').then( (module) => {
110
+ getFlows({}, module.got);
123
111
  });
124
112
  }
125
113
  });
126
114
  }
115
+
127
116
  RED.nodes.registerType("GetFlows", GetFlowsFunctionality);
128
117
  }
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@gregoriusrippenstein/node-red-contrib-introspection",
3
- "version": "0.2.6",
3
+ "version": "0.2.9",
4
+ "dependencies": {
5
+ "got": "latest"
6
+ },
4
7
  "keywords": [
5
8
  "node-red"
6
9
  ],
@@ -8,7 +11,7 @@
8
11
  "license": "SEE LICENSE IN https://github.com/gorenje/node-red-contrib-introspection/blob/main/LICENSE",
9
12
  "author": "Gerrit Riessen <nodered@spreads-the.love> (https://spread-the.love)",
10
13
  "engines": {
11
- "node": ">=8"
14
+ "node": ">=16"
12
15
  },
13
16
  "node-red": {
14
17
  "version": ">=2.0.0",