xilica-subscribe node rules and text box changed

This commit is contained in:
Niko Vujić
2025-12-31 09:01:03 +01:00
parent 667f954358
commit 11b4f83073
2 changed files with 145 additions and 121 deletions

View File

@@ -5,10 +5,7 @@ RED.nodes.registerType('xilica-subscribe', {
defaults: {
name: { value: "" },
action: { value: "subscribe" },
mode: { value: "list" },
targets: { value: "" },
startIndex: { value: 1 },
endIndex: { value: 1 },
rules: { value: [] },
transport: { value: "TCP" }
},
inputs: 1,
@@ -20,6 +17,100 @@ RED.nodes.registerType('xilica-subscribe', {
return this.name;
}
return "xilica " + act;
},
oneditprepare: function () {
var node = this;
var rules = node.rules || [];
$("#node-input-rules").editableList({
addItem: function (container, index, rule) {
rule = rule || {};
var row = $('<div/>').appendTo(container);
var typeField = $('<select/>', {
class: "node-input-rule-type",
style: "width: 120px; margin-right: 5px;"
}).appendTo(row);
$('<option/>', { value: "eq", text: "==" }).appendTo(typeField);
$('<option/>', { value: "idx", text: "Indexed" }).appendTo(typeField);
var valueField = $('<input/>', {
class: "node-input-rule-value",
type: "text",
style: "width: 180px; margin-right: 5px;"
}).appendTo(row);
var fromField = $('<input/>', {
class: "node-input-rule-from",
type: "number",
style: "width: 80px; margin-right: 5px;",
placeholder: "From"
}).appendTo(row);
var toField = $('<input/>', {
class: "node-input-rule-to",
type: "number",
style: "width: 80px;",
placeholder: "To"
}).appendTo(row);
function updateVisibility() {
var t = typeField.val();
if (t === "idx") {
fromField.show();
toField.show();
} else {
fromField.hide();
toField.hide();
}
}
typeField.on("change", updateVisibility);
typeField.val(rule.t || "eq");
valueField.val(rule.v || "");
if (rule.from !== undefined) {
fromField.val(rule.from);
}
if (rule.to !== undefined) {
toField.val(rule.to);
}
updateVisibility();
},
removable: true,
sortable: true
});
(rules || []).forEach(function (r) {
$("#node-input-rules").editableList('addItem', r);
});
},
oneditsave: function () {
var rules = [];
$("#node-input-rules").editableList('items').each(function () {
var row = $(this);
var type = $(".node-input-rule-type", row).val() || "eq";
var value = $(".node-input-rule-value", row).val() || "";
var from = $(".node-input-rule-from", row).val();
var to = $(".node-input-rule-to", row).val();
var rule = { t: type, v: value };
if (type === "idx") {
if (from !== "") {
rule.from = parseInt(from, 10);
}
if (to !== "") {
rule.to = parseInt(to, 10);
}
}
rules.push(rule);
});
this.rules = rules;
}
});
</script>
@@ -37,25 +128,8 @@ RED.nodes.registerType('xilica-subscribe', {
</select>
</div>
<div class="form-row">
<label for="node-input-mode">Mode</label>
<select id="node-input-mode">
<option value="list">Explicit list</option>
<option value="startsWith">Starts with</option>
<option value="endsWith">Ends with</option>
<option value="startsAndEnds">Starts with and ends with</option>
</select>
</div>
<div class="form-row">
<label for="node-input-targets">Targets</label>
<textarea id="node-input-targets" rows="5" style="width: 100%;"></textarea>
</div>
<div class="form-row">
<label for="node-input-startIndex">Start index</label>
<input type="number" id="node-input-startIndex" min="0">
</div>
<div class="form-row">
<label for="node-input-endIndex">End index</label>
<input type="number" id="node-input-endIndex" min="0">
<label>Rules</label>
<ol id="node-input-rules"></ol>
</div>
<div class="form-row">
<label for="node-input-transport">Transport</label>
@@ -67,13 +141,10 @@ RED.nodes.registerType('xilica-subscribe', {
<p>Builds <code>SUBSCRIBE</code> or <code>UNSUBSCRIBE</code> commands for a Xilica Solaro processor.</p>
<p>On each input message, the node sets <code>msg.payload</code> to one or more commands separated by carriage returns. Wire the output into a <code>xilica-command</code> node to send them over TCP.</p>
<p><strong>Action</strong> selects whether to generate <code>SUBSCRIBE</code> or <code>UNSUBSCRIBE</code> commands.</p>
<p><strong>Mode</strong> controls how the Targets field is interpreted:</p>
<p><strong>Rules</strong> define which control names to generate, similar to the Switch node's rule list:</p>
<ul>
<li><strong>Explicit list</strong>: each non-empty line in Targets is used as a full control name (e.g. <code>MASTER_GAIN</code>).</li>
<li><strong>Starts with</strong>: each line in Targets is treated as a prefix (e.g. <code>CH</code>), and Start/End index define the numeric range (e.g. 148 <code>CH1</code><code>CH48</code>).</li>
<li><strong>Ends with</strong>: each line in Targets is treated as a suffix (e.g. <code>_OUT</code>), and Start/End index define the numeric range (e.g. 14 <code>1_OUT</code><code>4_OUT</code>).</li>
<li><strong>Starts with and ends with</strong>: each line in Targets is interpreted as <code>prefix|suffix</code> (for example <code>CH|OUT</code>), and Start/End index define the numeric range (e.g. 428 <code>CH4OUT</code><code>CH28OUT</code>).</li>
<li><strong>Type ==</strong>: the Value field is used as a full control name (e.g. <code>MASTER_GAIN</code>).</li>
<li><strong>Type Indexed</strong>: the Value field is a base string (e.g. <code>CH</code>), and the From/To fields define a numeric range (e.g. 148 <code>CH1</code><code>CH48</code>).</li>
</ul>
<p>The Transport field controls the subscription transport string, typically <code>TCP</code>. The node generates commands like <code>SUBSCRIBE CH1 "TCP"</code>.</p>
</script>