node-red-contrib-connector-manager 1.0.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/LICENSE +201 -0
- package/README.md +81 -0
- package/opcua-connector-manager.html +304 -0
- package/opcua-connector-manager.js +8 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# node-red-contrib-opcua-connector-manager
|
|
2
|
+
|
|
3
|
+
A Node-RED sidebar panel that lists every **config node** reference across all flow tabs and lets you bulk-reassign them in one shot — useful when promoting flows from dev to prod.
|
|
4
|
+
|
|
5
|
+
Despite the name it works with **any** config node type: OPCUA connectors, MQTT brokers, HTTP request configs, database connections, whatever.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Sidebar panel** — always accessible via the ⇄ icon, no node placement needed
|
|
12
|
+
- **Config-type selector** — pick any type that actually exists in the workspace
|
|
13
|
+
- **Per-instance cards**, each showing:
|
|
14
|
+
- Name and detail line (endpoint URL, broker address, host…)
|
|
15
|
+
- Flow-tab pills with per-flow node counts
|
|
16
|
+
- *Replace with* dropdown
|
|
17
|
+
- **Bulk apply** — one click to reassign all referencing nodes, then Deploy to save
|
|
18
|
+
- **Stale-reference detection** — highlights nodes pointing to deleted config nodes
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Requirements
|
|
23
|
+
|
|
24
|
+
- Node-RED ≥ 3.0.0
|
|
25
|
+
- Node.js ≥ 18.0.0
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
### npm
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
cd ~/.node-red
|
|
35
|
+
npm install node-red-contrib-opcua-connector-manager
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Docker
|
|
39
|
+
|
|
40
|
+
```dockerfile
|
|
41
|
+
COPY nodes/ /opt/nr-local-nodes/
|
|
42
|
+
RUN npm install /opt/nr-local-nodes/node-red-contrib-opcua-connector-manager
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
Open the **⇄** tab in the Node-RED right sidebar. That's it.
|
|
50
|
+
|
|
51
|
+
1. Pick a config node type from the dropdown at the top.
|
|
52
|
+
2. Each card is one config node instance. The flow pills show you exactly where it's used.
|
|
53
|
+
3. Set *Replace with* on the cards you want to change.
|
|
54
|
+
4. Click **Apply Changes**, then **Deploy**.
|
|
55
|
+
|
|
56
|
+
You can also drop the *Config Node Mgr* node from the *Connector Manager* palette onto any flow — double-clicking it opens the sidebar automatically.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Dev → Prod example
|
|
61
|
+
|
|
62
|
+
Say you have two OPCUA connectors:
|
|
63
|
+
|
|
64
|
+
| Config node | Endpoint |
|
|
65
|
+
|---|---|
|
|
66
|
+
| OPC Server – Dev | `opc.tcp://dev-plc:4840` |
|
|
67
|
+
| OPC Server – Prod | `opc.tcp://10.0.1.5:4840` |
|
|
68
|
+
|
|
69
|
+
Open the panel, select `OPCUA-IIoT-Connector`, set *Replace with* to *OPC Server – Prod* on the dev card, click Apply, Deploy. Done.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Example flow
|
|
74
|
+
|
|
75
|
+
Import [`examples/config-node-manager.json`](./examples/config-node-manager.json) via **☰ → Import**.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
[Apache 2.0](./LICENSE) — [OWT Swiss](https://owt.swiss)
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
<!-- editor-side code for the Config Node Manager sidebar -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
(function () {
|
|
4
|
+
const SIDEBAR_ID = 'opcua-connector-manager';
|
|
5
|
+
let activeType = null;
|
|
6
|
+
|
|
7
|
+
const esc = s => $('<span/>').text(s == null ? '' : String(s)).html();
|
|
8
|
+
|
|
9
|
+
// Only show config types that nodes actually reference (no point listing orphans)
|
|
10
|
+
function listTypes() {
|
|
11
|
+
const present = new Set();
|
|
12
|
+
RED.nodes.eachConfig(n => present.add(n.type));
|
|
13
|
+
|
|
14
|
+
const used = new Set();
|
|
15
|
+
RED.nodes.eachNode(n => {
|
|
16
|
+
for (const def of Object.values(n._def?.defaults ?? {}))
|
|
17
|
+
if (def?.type && present.has(def.type)) used.add(def.type);
|
|
18
|
+
});
|
|
19
|
+
return [...used].sort();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Pull a readable name + optional detail line from any config node
|
|
23
|
+
function labelFor(n) {
|
|
24
|
+
const detail = n.endpointUrl ?? n.broker ?? n.host ?? n.url ?? n.server ?? null;
|
|
25
|
+
const name = n.name || detail || `${n.type} ${n.id.slice(0, 8)}…`;
|
|
26
|
+
return { name, detail: detail !== name ? detail : null };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function scan(type) {
|
|
30
|
+
// Build a tab-id → label map; RED.nodes.node() doesn't resolve workspace nodes in NR4
|
|
31
|
+
const tabLabels = {};
|
|
32
|
+
RED.nodes.eachWorkspace?.(t => { tabLabels[t.id] = t.label || t.name || t.id; });
|
|
33
|
+
|
|
34
|
+
const configs = [];
|
|
35
|
+
RED.nodes.eachConfig(n => {
|
|
36
|
+
if (n.type !== type) return;
|
|
37
|
+
const { name, detail } = labelFor(n);
|
|
38
|
+
configs.push({ id: n.id, name, detail });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const byId = Object.fromEntries(configs.map(c => [c.id, c]));
|
|
42
|
+
|
|
43
|
+
const refs = [];
|
|
44
|
+
RED.nodes.eachNode(n => {
|
|
45
|
+
for (const [prop, def] of Object.entries(n._def?.defaults ?? {})) {
|
|
46
|
+
if (def?.type !== type) continue;
|
|
47
|
+
const cid = n[prop];
|
|
48
|
+
if (!cid) continue;
|
|
49
|
+
refs.push({
|
|
50
|
+
nodeId: n.id, nodeType: n.type, nodeName: n.name ?? '',
|
|
51
|
+
prop, configId: cid,
|
|
52
|
+
flow: tabLabels[n.z] ?? ''
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return { configs, byId, refs };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function renderContent($root, type) {
|
|
61
|
+
$root.empty().html('<p style="color:#aaa;margin:4px 0"><i class="fa fa-spin fa-spinner"></i> Scanning…</p>');
|
|
62
|
+
|
|
63
|
+
const { configs, byId, refs } = scan(type);
|
|
64
|
+
$root.empty();
|
|
65
|
+
|
|
66
|
+
if (!refs.length) {
|
|
67
|
+
const msg = configs.length
|
|
68
|
+
? `<div style="color:#888;padding:6px 0"><i class="fa fa-info-circle"></i> No nodes reference any <code>${esc(type)}</code> config node.</div>`
|
|
69
|
+
: `<div style="color:#888;padding:6px 0"><i class="fa fa-info-circle"></i> No <code>${esc(type)}</code> config nodes found.</div>`;
|
|
70
|
+
$root.html(msg);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// stale last, then sorted by connector name → flow → node name
|
|
75
|
+
refs.sort((a, b) => {
|
|
76
|
+
const as = !byId[a.configId], bs = !byId[b.configId];
|
|
77
|
+
if (as !== bs) return as ? 1 : -1;
|
|
78
|
+
const ca = byId[a.configId]?.name ?? '', cb = byId[b.configId]?.name ?? '';
|
|
79
|
+
return ca.localeCompare(cb) || a.flow.localeCompare(b.flow) || a.nodeName.localeCompare(b.nodeName);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const staleCount = refs.filter(r => !byId[r.configId]).length;
|
|
83
|
+
const staleNote = staleCount
|
|
84
|
+
? ` <span style="color:#c00;font-weight:600">· ${staleCount} stale reference(s)</span>`
|
|
85
|
+
: '';
|
|
86
|
+
|
|
87
|
+
const $summary = $(`
|
|
88
|
+
<div style="padding:6px 10px;background:#eef6fb;border:1px solid #c3dff0;border-radius:4px;font-size:.88em;margin-bottom:10px">
|
|
89
|
+
<i class="fa fa-info-circle" style="color:#3FADB5"></i>
|
|
90
|
+
<b>${configs.length}</b> config node(s) — <b>${refs.length}</b> referencing node(s)${staleNote}
|
|
91
|
+
</div>`);
|
|
92
|
+
|
|
93
|
+
const replaceOpts = configs.map(c => `<option value="${esc(c.id)}">${esc(c.name)}</option>`).join('');
|
|
94
|
+
|
|
95
|
+
function makeNodeCard(ref) {
|
|
96
|
+
const cfg = byId[ref.configId];
|
|
97
|
+
const isStale = !cfg;
|
|
98
|
+
const border = isStale ? '#fbb' : '#ddd';
|
|
99
|
+
const bg = isStale ? '#fff8f8' : '#fff';
|
|
100
|
+
const nodeName = ref.nodeName || `(${ref.nodeType})`;
|
|
101
|
+
|
|
102
|
+
const titleHtml = ref.flow
|
|
103
|
+
? `<span style="color:#999;font-weight:normal">${esc(ref.flow)}</span><span style="color:#bbb;padding:0 4px">→</span>${esc(nodeName)}`
|
|
104
|
+
: esc(nodeName);
|
|
105
|
+
|
|
106
|
+
const $card = $(`
|
|
107
|
+
<div style="border:1px solid ${border};border-radius:5px;padding:9px 12px;margin-bottom:8px;background:${bg}">
|
|
108
|
+
<div style="display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:6px">
|
|
109
|
+
<div style="min-width:0;flex:1">
|
|
110
|
+
<span style="font-weight:bold;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:block">${titleHtml}</span>
|
|
111
|
+
<div style="color:#aaa;font-size:.8em;font-family:monospace;margin-top:1px">${esc(ref.nodeType)}</div>
|
|
112
|
+
</div>
|
|
113
|
+
<span style="background:${isStale ? '#e53935' : '#3FADB5'};color:#fff;border-radius:10px;padding:1px 8px;font-size:.8em;white-space:nowrap;margin-left:8px;flex-shrink:0;align-self:center">
|
|
114
|
+
${esc(ref.prop)}
|
|
115
|
+
</span>
|
|
116
|
+
</div>
|
|
117
|
+
</div>`);
|
|
118
|
+
|
|
119
|
+
const stalePrefix = isStale
|
|
120
|
+
? `<option value="" disabled selected>— select replacement —</option>`
|
|
121
|
+
: '';
|
|
122
|
+
const $sel = $(`<select class="opcua-cm-select" data-node-id="${esc(ref.nodeId)}" data-prop="${esc(ref.prop)}" style="flex:1;min-width:0">${stalePrefix}${replaceOpts}</select>`);
|
|
123
|
+
if (cfg) $sel.val(ref.configId);
|
|
124
|
+
// stale refs stay on the disabled placeholder — no silent auto-assign
|
|
125
|
+
$card.append(
|
|
126
|
+
$('<div style="display:flex;align-items:center;gap:6px"/>').append(
|
|
127
|
+
$('<span style="font-size:.82em;color:#888;white-space:nowrap;flex-shrink:0">→</span>'),
|
|
128
|
+
$sel
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
return $card;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const $cards = $('<div/>');
|
|
136
|
+
refs.forEach(r => $cards.append(makeNodeCard(r)));
|
|
137
|
+
|
|
138
|
+
const $applyBtn = $('<button class="red-ui-button" type="button"><i class="fa fa-check"></i> Apply Changes</button>');
|
|
139
|
+
const $status = $('<span style="font-size:.85em;color:#888"/>');
|
|
140
|
+
const $applyRow = $('<div style="display:flex;align-items:center;gap:10px;margin-top:4px"/>').append($applyBtn, $status);
|
|
141
|
+
|
|
142
|
+
$applyBtn.on('click', () => {
|
|
143
|
+
// dry-run: collect what would change
|
|
144
|
+
const pending = [];
|
|
145
|
+
$root.find('.opcua-cm-select').each(function () {
|
|
146
|
+
const nodeId = $(this).data('node-id');
|
|
147
|
+
const prop = $(this).data('prop');
|
|
148
|
+
const newId = $(this).val();
|
|
149
|
+
|
|
150
|
+
if (!newId) return; // stale ref with no replacement chosen
|
|
151
|
+
const node = RED.nodes.node(nodeId);
|
|
152
|
+
if (!node) return;
|
|
153
|
+
if (!node._def?.defaults?.[prop]) return; // prop must be in the node's declared schema
|
|
154
|
+
if (node[prop] === newId) return; // no actual change
|
|
155
|
+
|
|
156
|
+
pending.push({ nodeId, prop, newId });
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
if (!pending.length) {
|
|
160
|
+
$status.text('No changes selected.').css('color', '#888');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (!confirm(`Apply ${pending.length} change(s) to node config references?\nThis cannot be undone without redeploying.`)) return;
|
|
165
|
+
|
|
166
|
+
pending.forEach(({ nodeId, prop, newId }) => {
|
|
167
|
+
const node = RED.nodes.node(nodeId);
|
|
168
|
+
if (node) node[prop] = newId;
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
RED.nodes.dirty(true);
|
|
172
|
+
RED.view?.redraw?.(true);
|
|
173
|
+
$status.text(`${pending.length} node(s) updated — Deploy to save.`).css('color', '#2e7d32');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
$root.append($summary, $cards, $applyRow);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function refresh($root) {
|
|
180
|
+
$root.empty();
|
|
181
|
+
const types = listTypes();
|
|
182
|
+
|
|
183
|
+
if (!types.length) {
|
|
184
|
+
$root.html('<div style="padding:6px 0;color:#888"><i class="fa fa-info-circle"></i> No referenceable config nodes found — add some and click Refresh.</div>');
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!activeType || !types.includes(activeType))
|
|
189
|
+
activeType = types.includes('OPCUA-IIoT-Connector') ? 'OPCUA-IIoT-Connector' : types[0];
|
|
190
|
+
|
|
191
|
+
const typeOpts = types.map(t => `<option value="${esc(t)}"${t === activeType ? ' selected' : ''}>${esc(t)}</option>`).join('');
|
|
192
|
+
const $typeSel = $(`<select style="flex:1;min-width:0">${typeOpts}</select>`);
|
|
193
|
+
const $typeRow = $('<div style="display:flex;align-items:center;gap:8px;padding-bottom:10px;margin-bottom:8px;border-bottom:2px solid #eee"/>').append(
|
|
194
|
+
$('<label style="white-space:nowrap;font-size:.88em;font-weight:600;color:#555">Config type:</label>'),
|
|
195
|
+
$typeSel
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const $content = $('<div/>');
|
|
199
|
+
$root.append($typeRow, $content);
|
|
200
|
+
|
|
201
|
+
$typeSel.on('change', () => {
|
|
202
|
+
activeType = $typeSel.val();
|
|
203
|
+
renderContent($content, activeType);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
renderContent($content, activeType);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// sidebar panel
|
|
210
|
+
const $panel = $('<div style="padding:10px;overflow-y:auto;height:100%;box-sizing:border-box"/>');
|
|
211
|
+
const $refreshBtn = $('<button class="red-ui-button red-ui-button-small" type="button" title="Re-scan"><i class="fa fa-refresh"></i> Refresh</button>');
|
|
212
|
+
$refreshBtn.on('click', () => refresh($panel));
|
|
213
|
+
|
|
214
|
+
RED.sidebar?.addTab?.({
|
|
215
|
+
id: SIDEBAR_ID,
|
|
216
|
+
label: 'manager',
|
|
217
|
+
name: 'Config node manager',
|
|
218
|
+
content: $panel,
|
|
219
|
+
toolbar: $('<div style="padding:4px 6px"/>').append($refreshBtn),
|
|
220
|
+
enableOnEdit: true,
|
|
221
|
+
onchange: () => refresh($panel)
|
|
222
|
+
});
|
|
223
|
+
// NR4 renders the label as plain text; replace with a proper FA icon via DOM
|
|
224
|
+
$('[data-id="' + SIDEBAR_ID + '"]').html('<i class="fa fa-exchange"></i>');
|
|
225
|
+
|
|
226
|
+
// palette node — just a shortcut to open the sidebar
|
|
227
|
+
RED.nodes.registerType('opcua-connector-manager', {
|
|
228
|
+
category: 'Connector Manager',
|
|
229
|
+
color: '#3FADB5',
|
|
230
|
+
defaults: { name: { value: '' } },
|
|
231
|
+
inputs: 0,
|
|
232
|
+
outputs: 0,
|
|
233
|
+
icon: 'font-awesome/fa-exchange',
|
|
234
|
+
paletteLabel: 'Config Node Mgr',
|
|
235
|
+
|
|
236
|
+
label: function () { return this.name || 'Config Node Mgr'; },
|
|
237
|
+
labelStyle: function () { return this.name ? 'node_label_italic' : ''; },
|
|
238
|
+
|
|
239
|
+
// opening the edit dialog also opens the sidebar
|
|
240
|
+
oneditprepare: function () {
|
|
241
|
+
RED.sidebar?.show?.(SIDEBAR_ID);
|
|
242
|
+
refresh($panel);
|
|
243
|
+
$('#cm-open-btn').on('click', () => {
|
|
244
|
+
RED.sidebar?.show?.(SIDEBAR_ID);
|
|
245
|
+
refresh($panel);
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
oneditsave: function () {}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
}());
|
|
253
|
+
</script>
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
<!-- edit dialog — just points to the sidebar -->
|
|
257
|
+
<script type="text/html" data-template-name="opcua-connector-manager">
|
|
258
|
+
<div class="form-row">
|
|
259
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
260
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
261
|
+
</div>
|
|
262
|
+
<div class="form-row" style="text-align:center;padding:18px 0 10px">
|
|
263
|
+
<i class="fa fa-exchange" style="font-size:2em;color:#3FADB5;display:block;margin-bottom:10px"></i>
|
|
264
|
+
<p style="color:#555;margin:0 0 12px">
|
|
265
|
+
The <strong>Config Node Manager</strong> lives in the sidebar.<br>
|
|
266
|
+
<small style="color:#999">It opened automatically — look for the <b>⇄</b> tab on the right.</small>
|
|
267
|
+
</p>
|
|
268
|
+
<button type="button" class="red-ui-button" id="cm-open-btn">
|
|
269
|
+
<i class="fa fa-external-link"></i> Focus Sidebar
|
|
270
|
+
</button>
|
|
271
|
+
</div>
|
|
272
|
+
</script>
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
<!-- help panel -->
|
|
276
|
+
<script type="text/html" data-help-name="opcua-connector-manager">
|
|
277
|
+
<p>
|
|
278
|
+
A persistent <strong>sidebar panel</strong> that lists every config node reference
|
|
279
|
+
across all flows and lets you bulk-reassign them — handy when promoting from dev to prod.
|
|
280
|
+
</p>
|
|
281
|
+
|
|
282
|
+
<h3>Opening the panel</h3>
|
|
283
|
+
<p>
|
|
284
|
+
Click the <b>⇄</b> tab in the right sidebar. It is always there
|
|
285
|
+
without placing this node on the canvas. Double-clicking the canvas node also opens it.
|
|
286
|
+
</p>
|
|
287
|
+
|
|
288
|
+
<h3>Workflow</h3>
|
|
289
|
+
<ol>
|
|
290
|
+
<li>Pick a config node type from the dropdown.</li>
|
|
291
|
+
<li>Each card represents one node that references a config. Unused config nodes are hidden.</li>
|
|
292
|
+
<li>Use the <em>→</em> dropdown on each card to pick a replacement connector.</li>
|
|
293
|
+
<li>Click <strong>Apply Changes</strong>, then <strong>Deploy</strong> to persist.</li>
|
|
294
|
+
</ol>
|
|
295
|
+
|
|
296
|
+
<h3>Stale references</h3>
|
|
297
|
+
<p>Red cards mark nodes whose config was deleted. Use the dropdown to assign a valid replacement.</p>
|
|
298
|
+
|
|
299
|
+
<h3>Notes</h3>
|
|
300
|
+
<ul>
|
|
301
|
+
<li>Works with any config node type, not just OPCUA.</li>
|
|
302
|
+
<li>Nothing is saved until you Deploy.</li>
|
|
303
|
+
</ul>
|
|
304
|
+
</script>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
module.exports = function (RED) {
|
|
2
|
+
function OpcuaConnectorManagerNode(config) {
|
|
3
|
+
RED.nodes.createNode(this, config);
|
|
4
|
+
this.status({ fill: 'grey', shape: 'ring', text: 'connector manager' });
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
RED.nodes.registerType('opcua-connector-manager', OpcuaConnectorManagerNode);
|
|
8
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-red-contrib-connector-manager",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Node-RED sidebar panel to bulk-reassign any config node references across all flows — ideal when promoting from dev to prod.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "OWT Swiss",
|
|
7
|
+
"url": "https://owt.swiss"
|
|
8
|
+
},
|
|
9
|
+
"contributors": [
|
|
10
|
+
"Arthur Cousin"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"node-red",
|
|
15
|
+
"opcua",
|
|
16
|
+
"iiot",
|
|
17
|
+
"config",
|
|
18
|
+
"connector",
|
|
19
|
+
"manager",
|
|
20
|
+
"migration",
|
|
21
|
+
"bulk",
|
|
22
|
+
"dev-to-prod"
|
|
23
|
+
],
|
|
24
|
+
"homepage": "https://owt.swiss",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18.0.0"
|
|
27
|
+
},
|
|
28
|
+
"node-red": {
|
|
29
|
+
"version": ">=3.0.0",
|
|
30
|
+
"nodes": {
|
|
31
|
+
"opcua-connector-manager": "opcua-connector-manager.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {},
|
|
35
|
+
"files": [
|
|
36
|
+
"opcua-connector-manager.js",
|
|
37
|
+
"opcua-connector-manager.html",
|
|
38
|
+
"LICENSE",
|
|
39
|
+
"README.md"
|
|
40
|
+
]
|
|
41
|
+
}
|