@gregoriusrippenstein/node-red-contrib-introspection 0.0.1

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.
@@ -0,0 +1,158 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('Orphans',{
3
+ color: '#e5e4ef',
4
+ icon: "font-awesome/fa-support",
5
+ category: 'introspection',
6
+ paletteLabel: "Orphans",
7
+ defaults: {
8
+ name: {
9
+ value:"",
10
+ },
11
+ },
12
+ inputs:0,
13
+ outputs:0,
14
+
15
+ label: function() {
16
+ return (this.name || this._def.paletteLabel);
17
+ },
18
+
19
+ labelStyle: function() {
20
+ return this.name?"node_label_italic":"";
21
+ },
22
+
23
+ oneditprepare: function() {
24
+ var node = this;
25
+
26
+ this._resize = function() {
27
+ var rows = $("#dialog-form>div:not(.node-input-target-list-row)");
28
+ var height = $("#dialog-form").height();
29
+ for (var i=0;i<rows.length;i++) {
30
+ height -= $(rows[i]).outerHeight(true);
31
+ }
32
+ var editorRow = $("#dialog-form>div.node-input-target-list-row");
33
+ editorRow.css("height",height+"px");
34
+ };
35
+
36
+ var search = $("#node-input-orphan-target-filter").searchBox({
37
+ style: "compact",
38
+ delay: 300,
39
+ change: function() {
40
+ var val = $(this).val().trim().toLowerCase();
41
+ if (val === "") {
42
+ dirList.treeList("filter", null);
43
+ search.searchBox("count","");
44
+ } else {
45
+ var count = dirList.treeList("filter", function(item) {
46
+ return item.label.toLowerCase().indexOf(val) > -1 || item.node.type.toLowerCase().indexOf(val) > -1
47
+ });
48
+ search.searchBox("count",count+" / "+items.length);
49
+ }
50
+ }
51
+ });
52
+
53
+ var dirList = $("#node-input-orphan-target-container-div").css({
54
+ width: "100%",
55
+ height: "100%"
56
+ }).treeList({multi:true}).on("treelistitemmouseover", function(e, item) {
57
+ item.node.highlighted = true;
58
+ item.node.dirty = true;
59
+ RED.view.redraw();
60
+ }).on("treelistitemmouseout", function(e, item) {
61
+ item.node.highlighted = false;
62
+ item.node.dirty = true;
63
+ RED.view.redraw();
64
+ }).on('treelistselect', function(event, item) {
65
+ if ( item.node ) {
66
+ RED.workspaces.show(item.node.z,false,false,true);
67
+ item.node.highlighted = true;
68
+ item.node.dirty = true;
69
+ RED.view.reveal(item.node.id,true)
70
+ RED.view.redraw();
71
+ }
72
+ });
73
+
74
+ /* ***************
75
+ * code taken from
76
+ * https://discourse.nodered.org/t/search-for-orphan-nodes/77783/3
77
+ */
78
+ const connectedNodes = new Set()
79
+ var candidateNodes = [];
80
+
81
+ // Iterate over all links, add the nodes to the 'connected' set
82
+ RED.nodes.eachLink(link => { connectedNodes.add(link.source); connectedNodes.add(link.target) })
83
+ // Iterate over all nodes, add any not in the connected set to the disconnected set
84
+ RED.nodes.eachNode(node => { if (!connectedNodes.has(node)) candidateNodes.push(node) })
85
+ /************ done code borrowing ************/
86
+
87
+ var items = [];
88
+ var nodeItemMap = {};
89
+
90
+ candidateNodes.forEach(function(n) {
91
+ if (n.id === node.id) {
92
+ return;
93
+ }
94
+
95
+ var nodeDef = RED.nodes.getType(n.type);
96
+ var label;
97
+ var sublabel;
98
+
99
+ if (nodeDef) {
100
+ var l = nodeDef.label;
101
+ label = (typeof l === "function" ? l.call(n) : l)||"";
102
+ sublabel = n.type;
103
+
104
+ if (sublabel.indexOf("subflow:") === 0) {
105
+ return;
106
+
107
+ var subflowId = sublabel.substring(8);
108
+ var subflow = RED.nodes.subflow(subflowId);
109
+ sublabel = "subflow : "+subflow.name;
110
+ }
111
+ }
112
+
113
+ if (!nodeDef || !label) {
114
+ label = n.type;
115
+ }
116
+ nodeItemMap[n.id] = {
117
+ node: n,
118
+ label: label,
119
+ sublabel: sublabel,
120
+ selected: false,
121
+ checkbox: false
122
+ };
123
+ items.push(nodeItemMap[n.id]);
124
+ });
125
+
126
+ dirList.treeList('data',items);
127
+ },
128
+
129
+ oneditsave: function() {
130
+ },
131
+
132
+ oneditresize: function(size) {
133
+ this._resize();
134
+ }
135
+
136
+ });
137
+ </script>
138
+
139
+ <script type="text/html" data-template-name="Orphans">
140
+ <div class="form-row">
141
+ <label><i class="fa fa-tag"></i> <span>Orphans</span></label>
142
+ </div>
143
+
144
+ <div class="form-row node-input-target-row node-input-target-list-row" style="position: relative; min-height: 100px">
145
+ <div style="position: absolute; top: -30px; right: 0;"><input type="text" id="node-input-orphan-target-filter"></div>
146
+ <div id="node-input-orphan-target-container-div"></div>
147
+ </div>
148
+
149
+ <div class="form-row">
150
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name">Name</span></label>
151
+ <input type="text" id="node-input-name" placeholder="Name">
152
+ </div>
153
+
154
+ </script>
155
+
156
+ <script type="text/html" data-help-name="Orphans">
157
+ <p>Orphan node shows all other nodes that are orphans, that is not connected to anything else either input nor output.</p>
158
+ </script>
@@ -0,0 +1,17 @@
1
+ module.exports = function(RED) {
2
+ function OrphanFunctionality(config) {
3
+ RED.nodes.createNode(this,config);
4
+
5
+ var node = this;
6
+ var cfg = config;
7
+
8
+ node.on('close', function() {
9
+ node.status({});
10
+ });
11
+
12
+ node.on("input",function(msg, send, done) {
13
+ send(msg);
14
+ });
15
+ }
16
+ RED.nodes.registerType("Orphans", OrphanFunctionality);
17
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@gregoriusrippenstein/node-red-contrib-introspection",
3
+ "version": "0.0.1",
4
+ "keywords": [
5
+ "node-red"
6
+ ],
7
+ "homepage": "https://github.com/gorenje/node-red-contrib-introspection#README.md",
8
+ "license": "SEE LICENSE IN https://github.com/gorenje/node-red-contrib-introspection/blob/main/LICENSE",
9
+ "author": "Gerrit Riessen <nodered@spreads-the.love> (https://spread-the.love)",
10
+ "engines": {
11
+ "node": ">=16"
12
+ },
13
+ "node-red": {
14
+ "version": ">=2.0.0",
15
+ "nodes": {
16
+ "seeker": "nodes/05-seeker.js",
17
+ "sink": "nodes/10-sink.js",
18
+ "screenshot": "nodes/15-screenshot.js",
19
+ "orphans": "nodes/20-orphans.js"
20
+ }
21
+ },
22
+ "description": "Node-RED Editor-only nodes for introspecting flows.",
23
+ "directories": {
24
+ "example": "examples"
25
+ },
26
+ "scripts": {
27
+ "test": "echo \"Error: no test specified\" && exit 1"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/gorenje/node-red-contrib-introspection.git"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/gorenje/node-red-contrib-introspection/issues"
35
+ }
36
+ }