node-red-contrib-uos-nats 0.2.62 → 0.2.64

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.
@@ -11,29 +11,81 @@
11
11
  outputs: 1,
12
12
  icon: "datahub-provider.svg",
13
13
  oneditprepare: function () {
14
- const updateProviderIdInfo = () => {
15
- const configId = $('#node-input-connection').val();
16
- const configNode = RED.nodes.node(configId);
17
- const $provId = $('#node-input-providerId');
14
+ const node = this;
15
+ const $conn = $('#node-input-connection');
16
+ const $provIdInput = $('#node-input-providerId');
17
+
18
+ // Create UI elements dynamically if they don't exist in template
19
+ // Wrapper for the specific UI
20
+ const $wrapper = $('<div style="display:inline-block; width:70%;"></div>').insertAfter($('label[for="node-input-providerId"]'));
21
+
22
+ // 1. Display Mode Elements
23
+ const $displayGroup = $('<div id="prov-id-display-group" style="display:none; align-items:center;"></div>').appendTo($wrapper);
24
+ // Styled like a read-only input but cleaner
25
+ const $displayText = $('<span id="prov-id-display-text" style="flex-grow:1; padding:6px; background:#f9f9f9; border:1px solid #ccc; border-radius:4px; color:#333;">nodered</span>').appendTo($displayGroup);
26
+ const $editBtn = $('<a class="red-ui-button" style="margin-left:5px;"><i class="fa fa-pencil"></i></a>').appendTo($displayGroup);
18
27
 
19
- if (configNode && configNode.clientName) {
20
- // User wants to see it "greyed out" -> Placeholder is best, or disabled?
21
- // "desweiteren in der Hilfe erwähnen, das Provider ID vom Client Name übernommen wird"
22
- // "du kannst ja das fenster ausgegraut lassen"
28
+ // 2. Input Mode Elements
29
+ const $inputGroup = $('<div id="prov-id-input-group" style="display:none; align-items:center;"></div>').appendTo($wrapper);
30
+ // Move existing input into this group
31
+ $provIdInput.css('width', '100%').css('flex-grow', '1').appendTo($inputGroup);
32
+ const $resetBtn = $('<a class="red-ui-button" style="margin-left:5px;" title="Reset to Auto"><i class="fa fa-undo"></i></a>').appendTo($inputGroup);
23
33
 
24
- // If the field is empty, show the clientName as placeholder/visual
25
- $provId.attr('placeholder', `Default: ${configNode.clientName}`);
34
+ // Helper for updating the display text based on Config
35
+ const updateDisplay = () => {
36
+ const configId = $conn.val();
37
+ const configNode = RED.nodes.node(configId);
38
+ const clientName = (configNode && configNode.clientName) ? configNode.clientName : '...';
39
+
40
+ $displayText.text(clientName);
26
41
 
27
- // Show a helper message
28
- $('#provider-id-helper').text(`Using Client ID from '${configNode.clientName}' (default)`);
42
+ // If config is missing/invalid, fallback to manual?
43
+ if (!configNode) {
44
+ $displayText.text('(No Config Selected)');
45
+ $displayText.css('color', '#999');
29
46
  } else {
30
- $provId.attr('placeholder', 'Leave empty to use Client ID');
31
- $('#provider-id-helper').text('');
47
+ $displayText.css('color', '#333');
32
48
  }
33
49
  };
34
50
 
35
- $('#node-input-connection').on('change', updateProviderIdInfo);
36
- updateProviderIdInfo();
51
+ // Toggle Logic
52
+ const showDisplay = () => {
53
+ $inputGroup.hide();
54
+ $displayGroup.css('display', 'flex'); // Use flex for alignment
55
+ // Clear input value so it saves as empty (auto)
56
+ // Wait, if we clear it here, on save it will be empty. accessing node.providerId in oneditprepare might be stale.
57
+ // We rely on the input's value.
58
+ $provIdInput.val('');
59
+ updateDisplay();
60
+ $('#provider-id-helper').text('Using Client ID from selected u-OS Config (default)');
61
+ };
62
+
63
+ const showInput = () => {
64
+ $displayGroup.hide();
65
+ $inputGroup.css('display', 'flex');
66
+ $provIdInput.focus();
67
+ $('#provider-id-helper').text('Custom Provider ID will be used instead of Client ID.');
68
+ };
69
+
70
+ // Events
71
+ $editBtn.on('click', function () {
72
+ showInput();
73
+ });
74
+
75
+ $resetBtn.on('click', function () {
76
+ showDisplay();
77
+ });
78
+
79
+ $conn.on('change', updateDisplay);
80
+
81
+ // Initial State
82
+ // If node.providerId is empty -> Display Mode
83
+ // If node.providerId has value -> Input Mode
84
+ if (!node.providerId) {
85
+ showDisplay();
86
+ } else {
87
+ showInput();
88
+ }
37
89
  },
38
90
  label: function () {
39
91
  return this.name || `DataHub - Provider ${this.providerId || ''}`;
@@ -56,9 +108,9 @@
56
108
  </div>
57
109
  <div class="form-row">
58
110
  <label for="node-input-providerId"><i class="fa fa-tag"></i> Provider ID</label>
59
- <input type="text" id="node-input-providerId" placeholder="Leave empty to use Client ID">
111
+ <!-- Input is handled dynamically in oneditprepare -->
112
+ <input type="text" id="node-input-providerId" style="display:none;">
60
113
  </div>
61
- <div class="form-tips" id="provider-id-helper" style="margin-bottom:10px; color:#888;"></div>
62
114
  </script>
63
115
 
64
116
  <script type="text/html" data-help-name="datahub-output">
@@ -67,8 +119,9 @@
67
119
  <dt>u-OS Config</dt>
68
120
  <dd>Connection node with host/port and OAuth credentials.</dd>
69
121
  <dt>Provider ID</dt>
70
- <dd>The unique ID for this provider. If left <b>empty</b>, it uses the <strong>Client ID</strong> (associated with the configured <em>Client Name</em>).</dd>
71
- <dd><em>UI Note:</em> The input placeholder shows the Client Name as a reference.</dd>
122
+ <dd>The unique ID for this provider.</dd>
123
+ <dd><b>Auto Mode (Default):</b> Shows the <em>Client Name</em> from your Config. Uses this name automatically.</dd>
124
+ <dd><b>Manual Mode:</b> Click the pencil icon to enter a custom ID manually (not recommended).</dd>
72
125
  </dl>
73
126
  <p>Send a JSON object as <code>msg.payload</code>. Nested objects are flattened using dot-notation to create <strong>subcategories</strong> automatically:</p>
74
127
  <pre>{
@@ -64,13 +64,17 @@ module.exports = function (RED) {
64
64
  return;
65
65
  }
66
66
  // Retrieve configuration node
67
- // Default to Connection's Client ID if providerId is empty/not set
68
- const configClientId = connection.clientId || 'nodered';
67
+ // Default to Connection's Client Name (Friendly Name) because Client ID is often a UUID
68
+ // that doesn't match the desired Provider ID. User typically expects 'nodered' not '0069...'
69
+ let defaultId = connection.clientName;
70
+ if (!defaultId) {
71
+ // Fallback to ID if Name is missing (should not happen as Name is mandatory)
72
+ defaultId = connection.clientId || 'nodered';
73
+ }
74
+
69
75
  let pId = (config.providerId || '').trim();
70
76
  if (!pId) {
71
- pId = configClientId;
72
- // Strip non-alphanumeric chars if Client ID is a UUID/complex string?
73
- // Usually Provider ID can be matching Client ID exactly.
77
+ pId = defaultId;
74
78
  }
75
79
  this.providerId = pId;
76
80
  // this.definitions = config.definitions || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-uos-nats",
3
- "version": "0.2.62",
3
+ "version": "0.2.64",
4
4
  "description": "Node-RED nodes for Weidmüller u-OS Data Hub. Read, write, and provide variables via NATS protocol with OAuth2 authentication. Features: Variable Key resolution, custom icons, example flows, and provider definition caching.",
5
5
  "author": {
6
6
  "name": "IoTUeli",