@gregoriusrippenstein/node-red-contrib-introspection 0.3.2 → 0.3.5

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,14 +1,64 @@
1
1
  <script type="text/javascript">
2
- RED.comms.subscribe('introspect:trigger-import-tripped', (event,data) => {
2
+
3
+ RED.comms.subscribe('introspect:trigger-import-delete', (event,data) => {
4
+ if ( data.msg == "delete-old-nodes" ) {
5
+ RED.view.select(false)
6
+
7
+ // close any dialog that explains that there are duplicates and therefore
8
+ // only a copy can be imported, hit the cancel button on that one.
9
+ // Five clicks should do the job ...
10
+ for ( var idx = 0 ; idx < 5; idx++ ) {
11
+ $($('.ui-dialog-buttonset').find("button")[0]).trigger('click')
12
+ }
13
+
14
+ var allSelectNodes = [];
15
+
16
+ RED.nodes.eachNode( function(e) {
17
+ if ( e._def && e.env && e.env[1] &&
18
+ e._def.category == data.payload.category &&
19
+ (Date.parse(e.env[1].value) <
20
+ (new Date().getTime() - parseInt(data.payload.old_than_ms))) ) {
21
+ allSelectNodes.push(e)
22
+ }
23
+ });
24
+
25
+ RED.view.select({ nodes: allSelectNodes })
26
+ setTimeout( () => {
27
+ RED.actions.invoke("core:delete-selection")
28
+ }, 1500);
29
+ }
30
+ });
31
+
32
+ RED.comms.subscribe('introspect:trigger-import-tripped', (event,data) => {
3
33
  if ( data.msg == "import-flow" ) {
34
+ var content = data.flowContent;
35
+
36
+ if ( data.removeduplicates ) {
37
+ content = content.filter( (elem) => {
38
+ return RED.nodes.node(elem.id) == undefined
39
+ });
40
+ }
41
+
42
+ if ( content.length == 0 ) {
43
+ RED.notify("No new content", {
44
+ type: "ok",
45
+ id: "TriggerImport",
46
+ timeout: 2000
47
+ });
48
+ return;
49
+ }
4
50
  RED.clipboard.import();
5
51
 
6
52
  setTimeout( () => {
7
- var content = data.flowContent;
8
-
9
53
  $('#red-ui-clipboard-dialog-import-text').val(
10
54
  JSON.stringify(content)
11
55
  ).trigger("paste");
56
+
57
+ if ( data.autoimport ) {
58
+ setTimeout( () => {
59
+ $('#red-ui-clipboard-dialog-ok').trigger('click');
60
+ }, 435);
61
+ }
12
62
  }, 300);
13
63
  }
14
64
  });
@@ -22,6 +72,12 @@
22
72
  name: {
23
73
  value:"",
24
74
  },
75
+ autoimport: {
76
+ value: false
77
+ },
78
+ removeduplicates: {
79
+ value: false
80
+ },
25
81
  },
26
82
  inputs:1,
27
83
  outputs:1,
@@ -33,14 +89,36 @@
33
89
  labelStyle: function() {
34
90
  return this.name?"node_label_italic":"";
35
91
  },
36
- });
92
+ });
37
93
  </script>
38
94
 
39
95
  <script type="text/html" data-template-name="TriggerImport">
40
96
  <div class="form-row">
41
- <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name">Name</span></label>
42
- <input type="text" id="node-input-name" placeholder="Name">
97
+ <label for="node-input-name">
98
+ <i class="fa fa-tag"></i>
99
+ <span data-i18n="common.label.name">Name</span>
100
+ </label>
101
+ <input type="text" id="node-input-name" placeholder="Name">
102
+ </div>
103
+
104
+ <div class="form-row">
105
+ <label for="node-input-autoimport" style="width: 150px !important;">
106
+ <span>Automatic Import?</span>
107
+ </label>
108
+ <input type="checkbox"
109
+ id="node-input-autoimport"
110
+ style="display:inline-block; width:15px; vertical-align:baseline;">
43
111
  </div>
112
+
113
+ <div class="form-row">
114
+ <label for="node-input-removeduplicates" style="width: 150px !important;">
115
+ <span>Remove duplicates?</span>
116
+ </label>
117
+ <input type="checkbox"
118
+ id="node-input-removeduplicates"
119
+ style="display:inline-block; width:15px; vertical-align:baseline;">
120
+ </div>
121
+
44
122
  </script>
45
123
 
46
124
  <script type="text/html" data-help-name="TriggerImport">
@@ -10,10 +10,24 @@ module.exports = function(RED) {
10
10
  });
11
11
 
12
12
  node.on("input", function(msg, send, done) {
13
+ if ( msg.payload && msg.payload.cmd == "delete-nodes" ) {
14
+ RED.comms.publish('introspect:trigger-import-delete',
15
+ RED.util.encodeObject({
16
+ msg: "delete-old-nodes",
17
+ payload: msg.payload,
18
+ })
19
+ );
20
+
21
+ send(msg);
22
+ return;
23
+ }
24
+
13
25
  RED.comms.publish("introspect:trigger-import-tripped",
14
26
  RED.util.encodeObject({
15
- flowContent: msg.payload,
16
- msg: "import-flow",
27
+ flowContent: msg.payload,
28
+ msg: "import-flow",
29
+ autoimport: cfg.autoimport,
30
+ removeduplicates: cfg.removeduplicates,
17
31
  })
18
32
  );
19
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gregoriusrippenstein/node-red-contrib-introspection",
3
- "version": "0.3.2",
3
+ "version": "0.3.5",
4
4
  "dependencies": {
5
5
  "got": "latest"
6
6
  },