Skip to content

Commit

Permalink
try to improve switch editor behaviour (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Aug 24, 2018
1 parent dc97e1f commit 63d8f34
Showing 1 changed file with 115 additions and 110 deletions.
225 changes: 115 additions & 110 deletions nodes/ccu-switch.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,106 +14,6 @@
limitations under the License.
-->

<script type="text/x-red" data-template-name="ccu-switch">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="ccu-switch.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]ccu-switch.label.name">
</div>
<div class="form-row">
<label for="node-input-ccuConfig"><i class="icon-globe"></i> CCU</label>
<input type="text" id="node-input-ccuConfig">
</div>
<div class="form-row">
<label for="node-input-iface"><i class="fa fa-empire"></i> Interface</label>
<select id="node-input-iface" disabled>
</select>
</div>
<div class="form-row sysvar">
<label for="node-input-sysvar"><i class="icon-tags"></i> Sysvar</label>
<select id="node-input-sysvar">
</select>
</div>
<div class="form-row sysvar">
<label for="node-input-sysvarProperty"><i class="icon-tags"></i> Property</label>
<select id="node-input-sysvarProperty">
<option selected>value</option>
<option>valueEnum</option>
<option>ts</option>
<option>lc</option>
</select>
</div>
<div class="form-row datapoint">
<label for="node-input-channel"><i class="icon-tags"></i> Channel</label>
<input type="text" id="node-input-channel">
</div>
<div class="form-row datapoint">
<label for="node-input-datapoint"><i class="icon-tag"></i> Datapoint</label>
<input type="text" id="node-input-datapoint">
</div>
<div class="form-row datapoint">
<label for="node-input-datapointProperty"><i class="icon-tags"></i> Property</label>
<select id="node-input-datapointProperty">
<option selected>value</option>
<option>ts</option>
<option>lc</option>
<option>working</option>
<option>direction</option>
</select>
</div>

<input type="hidden" id="node-input-outputs"/>

<div class="form-row node-input-rule-container-row">
<ol id="node-input-rule-container"></ol>
</div>
<div class="form-row">
<select id="node-input-checkall" style="width:100%; margin-right:5px;">
<option value="true" data-i18n="ccu-switch.checkall"></option>
<option value="false" data-i18n="ccu-switch.stopfirst"></option>
</select>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-repair" style="display: inline-block; width: auto; vertical-align: top;">
<label style="width: auto;" for="node-input-repair"><span data-i18n="ccu-switch.label.repair"></span></label></input>
</div>
</script>

<script type="text/x-red" data-help-name="ccu-switch">
<p>Route messages based on their property values or sequence position.</p>
<h3>Details</h3>
<p>When a message arrives, the node will evaluate each of the defined rules
and forward the message to the corresponding outputs of any matching rules.</p>
<p>Optionally, the node can be set to stop evaluating rules once it finds one
that matches.</p>
<p>The rules can be evaluated against an individual message property, a flow or global
context property or the result of a JSONata expression.</p>
<h4>Rules</h4>
<p>There are four types of rule:</p>
<ol>
<li><b>Value</b> rules are evaluated against the configured property</li>
<li><b>Sequence</b> rules can be used on message sequences, such as those
generated by the Split node</li>
<li>A JSONata <b>Expression</b> can be provided that will be evaluated
against the whole message and will match if the expression returns
a true value.</li>
<li>An <b>Otherwise</b> rule can be used to match if none of the preceeding
rules have matched.</li>
</ol>
<h4>Notes</h4>
<p>The <code>is true/false</code> and <code>is null</code> rules perform strict
comparisons against those types. They do not convert between types.</p>
<p>The <code>is empty</code> rule passes for Strings, Arrays and Buffers that have
a length of 0, or Objects that have no properties. It does not pass for <code>null</code>
or <code>undefined</code> values.</p>
<h4>Handling message sequences</h4>
<p>By default, the node does not modify the <code>msg.parts</code> property of messages
that are part of a sequence.</p>
<p>The <b>recreate message sequences</b> option can be enabled to generate new message sequences
for each rule that matches. In this mode, the node will buffer the entire incoming
sequence before sending the new sequences on. The runtime setting <code>nodeMessageBufferMaxLength</code>
can be used to limit how many messages nodes will buffer.</p>
</script>

<script type="text/javascript">
(function () {
const operators = [
Expand Down Expand Up @@ -219,31 +119,35 @@ <h4>Handling message sequences</h4>
const $nodeInputChannel = $('#node-input-channel');
const $nodeInputSysvar = $('#node-input-sysvar');
const $nodeInputDatapoint = $('#node-input-datapoint');
const $nodeInputDatapointProperty = $('#node-input-datapointProperty');

let data;

let ifacesLoaded = false;
let ifacesPending = false;

$('.form-row.datapoint').hide();
$('.form-row.sysvar').hide();

function loadIfaces(iface, cb) {
if (ifacesPending) {
return;
}
ifacesPending = true;
console.log('loadIfaces()');
$nodeInputIface.html('<option>ReGaHSS</option>');

const nodeId = $nodeInputCcuConfig.val();
if (nodeId === '_ADD_') {
if (typeof cb === 'function') {
cb();
ifacesPending = false;
}
} else {
if (nodeId !== '_ADD_') {
const url = 'ccu?config=' + nodeId + '&type=ifaces';
$.getJSON(url, d => {
$nodeInputIface.html('<option>ReGaHSS</option>');

Object.keys(d).forEach(i => {
$nodeInputIface.append('<option' + (d[i].enabled ? '' : ' disabled') + (i === node.iface ? ' selected' : '') + '>' + i + '</option>');
});

$nodeInputIface.removeAttr('disabled');

$nodeInputIface.trigger('change');
if (typeof cb === 'function') {
cb();
Expand Down Expand Up @@ -279,7 +183,6 @@ <h4>Handling message sequences</h4>
console.log('$nodeInputCcuConfig change');
loadIfaces(this.iface, () => {
ifacesLoaded = true;
$nodeInputIface.removeAttr('disabled');
loadConfig();
});
});
Expand Down Expand Up @@ -339,7 +242,7 @@ <h4>Handling message sequences</h4>
if ($nodeInputIface.val() === 'ReGaHSS') {
$('.form-row.datapoint').hide();
$('.form-row.sysvar').show();
} else {
} else if ($nodeInputIface.val()) {
$('.form-row.sysvar').hide();
$('.form-row.datapoint').show();
}
Expand Down Expand Up @@ -613,4 +516,106 @@ <h4>Handling message sequences</h4>
}
});
})();
</script>
</script>


<script type="text/x-red" data-template-name="ccu-switch">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="ccu-switch.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]ccu-switch.label.name">
</div>
<div class="form-row">
<label for="node-input-ccuConfig"><i class="icon-globe"></i> CCU</label>
<input type="text" id="node-input-ccuConfig">
</div>
<div class="form-row">
<label for="node-input-iface"><i class="fa fa-empire"></i> Interface</label>
<select id="node-input-iface" disabled>
</select>
</div>
<div class="form-row sysvar">
<label for="node-input-sysvar"><i class="icon-tags"></i> Sysvar</label>
<select id="node-input-sysvar">
</select>
</div>
<div class="form-row sysvar">
<label for="node-input-sysvarProperty"><i class="icon-tags"></i> Property</label>
<select id="node-input-sysvarProperty">
<option selected>value</option>
<option>valueEnum</option>
<option>ts</option>
<option>lc</option>
</select>
</div>
<div class="form-row datapoint">
<label for="node-input-channel"><i class="icon-tags"></i> Channel</label>
<input type="text" id="node-input-channel">
</div>
<div class="form-row datapoint">
<label for="node-input-datapoint"><i class="icon-tag"></i> Datapoint</label>
<input type="text" id="node-input-datapoint">
</div>
<div class="form-row datapoint">
<label for="node-input-datapointProperty"><i class="icon-tags"></i> Property</label>
<select id="node-input-datapointProperty">
<option value="value">value</option>
<option value="ts">ts</option>
<option value="lc">lc</option>
<option value="working">working</option>
<option>direction</option>
</select>
</div>

<input type="hidden" id="node-input-outputs"/>

<div class="form-row node-input-rule-container-row">
<ol id="node-input-rule-container"></ol>
</div>
<div class="form-row">
<select id="node-input-checkall" style="width:100%; margin-right:5px;">
<option value="true" data-i18n="ccu-switch.checkall"></option>
<option value="false" data-i18n="ccu-switch.stopfirst"></option>
</select>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-repair" style="display: inline-block; width: auto; vertical-align: top;">
<label style="width: auto;" for="node-input-repair"><span data-i18n="ccu-switch.label.repair"></span></label></input>
</div>
</script>

<script type="text/x-red" data-help-name="ccu-switch">
<p>Route messages based on their property values or sequence position.</p>
<h3>Details</h3>
<p>When a message arrives, the node will evaluate each of the defined rules
and forward the message to the corresponding outputs of any matching rules.</p>
<p>Optionally, the node can be set to stop evaluating rules once it finds one
that matches.</p>
<p>The rules can be evaluated against an individual message property, a flow or global
context property or the result of a JSONata expression.</p>
<h4>Rules</h4>
<p>There are four types of rule:</p>
<ol>
<li><b>Value</b> rules are evaluated against the configured property</li>
<li><b>Sequence</b> rules can be used on message sequences, such as those
generated by the Split node</li>
<li>A JSONata <b>Expression</b> can be provided that will be evaluated
against the whole message and will match if the expression returns
a true value.</li>
<li>An <b>Otherwise</b> rule can be used to match if none of the preceeding
rules have matched.</li>
</ol>
<h4>Notes</h4>
<p>The <code>is true/false</code> and <code>is null</code> rules perform strict
comparisons against those types. They do not convert between types.</p>
<p>The <code>is empty</code> rule passes for Strings, Arrays and Buffers that have
a length of 0, or Objects that have no properties. It does not pass for <code>null</code>
or <code>undefined</code> values.</p>
<h4>Handling message sequences</h4>
<p>By default, the node does not modify the <code>msg.parts</code> property of messages
that are part of a sequence.</p>
<p>The <b>recreate message sequences</b> option can be enabled to generate new message sequences
for each rule that matches. In this mode, the node will buffer the entire incoming
sequence before sending the new sequences on. The runtime setting <code>nodeMessageBufferMaxLength</code>
can be used to limit how many messages nodes will buffer.</p>
</script>

0 comments on commit 63d8f34

Please sign in to comment.