@isaac-platform/isaac-node-red
Version:
Set of Node-RED nodes to communicate with an ISAAC system
243 lines (219 loc) • 8.92 kB
HTML
<script type="text/javascript">
// isaac prefix ensures that node appears when filtering by "isaac"
RED.nodes.registerType('isaac playable', {
category: 'ISAAC',
color: '#C0C0C0',
icon: 'isaac.svg',
inputs: 1,
outputs: 1,
paletteLabel: 'playable',
label: function () {
if (this.name) {
return this.name;
}
return this.paletteLabel;
},
defaults: {
isaacConnection: { type: 'isaac-connection', required: true },
name: { value: '' },
action: { value: 'getAll' },
externalRef: { value: '' },
displayName: { value: '' },
description: { value: '' },
command: { value: '' },
group: { value: '' },
duration: { value: 1000 },
durationType: { value: 'static' },
forceCached: { value: false },
},
oneditprepare: function () {
const updateLinks = () => {
const configNodeId = $('#node-input-isaacConnection').val();
if (!configNodeId) {
return;
}
const configNode = RED.nodes.node(configNodeId);
if (!configNode || !configNode.ipAddress) {
const links = document.querySelectorAll('.isaac-workspace-link, .isaac-doc-link');
links.forEach((link) => {
link.style.display = 'none';
});
return;
}
const getDisplay = (linkEl) => {
return linkEl.classList.contains('isaac-full-width') ? 'block' : 'inline';
};
const docLink = document.querySelector('.isaac-doc-link');
if (docLink) {
docLink.style.display = getDisplay(docLink);
docLink.href = `${configNode.ipAddress}/docs/v1/?urls.primaryName=Playables`;
}
const workspaceLinks = document.querySelectorAll('.isaac-workspace-link');
workspaceLinks.forEach((link) => {
link.style.display = getDisplay(link);
link.href = `${configNode.ipAddress}/system/modules`;
});
};
updateLinks();
$('#node-input-isaacConnection').change(updateLinks);
document.querySelector('#node-config-input-forceCached').checked = !!this.forceCached;
$('#node-input-action').change((e) => {
$('.action-related').hide();
const value = e.target.value;
if (value !== 'getAll') {
$('#row-externalRef').show();
}
if (value === 'upsert') {
$('#row-displayName').show();
$('#row-description').show();
$('#row-command').show();
$('#row-group').show();
$('#row-duration').show();
$('#row-durationType').show();
$('#row-forceCached').show();
}
});
},
oneditsave: function () {
this.forceCached = document.querySelector('#node-config-input-forceCached').checked;
},
});
</script>
<script type="text/html" data-template-name="isaac playable">
<div class="form-row">
<label for="node-input-isaacConnection"><i class="fa fa-server"></i> Connection</label>
<input type="text" id="node-input-isaacConnection" />
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Node Name</label>
<input type="text" id="node-input-name" />
</div>
<div class="form-row">
<label for="node-input-action" title="Can be overwritten by msg.action">
<i class="fa fa-bolt"></i> Action <strong>*</strong>
</label>
<select id="node-input-action">
<option value="getOne">Get one</option>
<option value="getAll">Get all</option>
<option value="upsert">Add/update one</option>
<option value="delete">Delete one</option>
</select>
</div>
<div class="form-row action-related" id="row-externalRef">
<label for="node-input-action" title="Can be overwritten by msg.config.externalRef">
External Ref <strong>*</strong>
</label>
<input type="text" id="node-input-externalRef" />
</div>
<div class="form-row action-related" id="row-displayName">
<label for="node-input-displayName" title="Can be overwritten by msg.config.displayName">
Display Name <strong>*</strong>
</label>
<input type="text" id="node-input-displayName" />
</div>
<div class="form-row action-related" id="row-description">
<label for="node-input-description" title="Can be overwritten by msg.config.description">Description</label>
<input type="text" id="node-input-description" />
</div>
<div class="form-row action-related" id="row-command">
<label for="node-input-command" title="Can be overwritten by msg.config.command">Command <strong>*</strong></label>
<input type="text" id="node-input-command" />
</div>
<div class="form-row action-related" id="row-group">
<label for="node-input-group" title="Can be overwritten by msg.config.group">Group</label>
<input type="text" id="node-input-group" />
</div>
<div class="form-row action-related" id="row-duration">
<label for="node-input-duration" title="Can be overwritten by msg.config.duration">
Duration (ms) <strong>*</strong>
</label>
<input type="number" id="node-input-duration" />
</div>
<div class="form-row action-related" id="row-durationType">
<label for="node-input-durationType" title="Can be overwritten by msg.config.durationType">Duration Type</label>
<select id="node-input-durationType">
<option value="static">Static</option>
<option value="dynamic">Dynamic</option>
<option value="loop">Loop</option>
</select>
</div>
<div class="form-row action-related" id="row-forceCached">
<label for="node-config-input-forceCached" title="Can be overwritten by msg.config.forceCached">
Available for Instant Play
</label>
<input class="switch__input" type="checkbox" id="node-config-input-forceCached" style="width: auto;" />
</div>
<div
style="color:#A3A3A3; display:flex; gap:16px; align-items:center; padding:8px 16px; border: 1px solid #a3a3a3; border-radius:12px; margin-top:12px"
>
<i class="fa fa-info" style="width:16px; text-align:center;"></i>
<p style="margin: 0; padding: 0;">
All properties can be overwritten by incoming messages.<br />
Hover a property label to see how it can be overwritten.<br />
Required properties (*) can be provided either in the UI or in messages.
</p>
</div>
<div style="margin-top:12px">
<a href="" target="_blank" class="isaac-workspace-link isaac-full-width" style="text-decoration:underline">
<i class="fa fa-external-link" style="margin-right:8px"></i>Workspace: Modules
</a>
<a
href=""
target="_blank"
class="isaac-doc-link isaac-full-width"
style="margin-top:12px; text-decoration:underline"
>
<i class="fa fa-book" style="margin-right:8px"></i>API Documentation: Playables
</a>
</div>
</script>
<script type="text/html" data-help-name="isaac playable">
<p>
Fetches, creates, updates and deletes ISAAC playables. Values passed in <code>msg.config</code> will override values
enterred in the UI editor dialog. Values not defined in <code>msg.config</code> nor the UI editor dialog will
fallback to the default values of the editor dialog, so make sure to define all values when updating an existing
item.
</p>
<h3>Inputs</h3>
<h4>Common</h4>
<dl class="message-properties">
<dt>action <span class="property-type">string</span></dt>
<dd>Can be <code>getOne</code>, <code>getAll</code>, <code>upsert</code> or <code>delete</code>.</dd>
</dl>
<h4>Action getOne</h4>
<dl class="message-properties">
<dt>config.externalRef <span class="property-type">string</span></dt>
<dd>The externalRef of the playable to fetch.</dd>
</dl>
<h4>Action upsert</h4>
<dl class="message-properties">
<dt>config.externalRef <span class="property-type">string</span></dt>
<dd><code>externalRef</code> of the playable to create or update.</dd>
<dt>config.displayName <span class="property-type">string</span></dt>
<dd>Display name of the new or updated playable.</dd>
<dt class="optional">config.description <span class="property-type">string</span></dt>
<dd>Optional. Description of the new or updated playable.</dd>
<dt>config.command <span class="property-type">string</span></dt>
<dd>The playable's command.</dd>
<dt class="optional">config.group <span class="property-type">string</span></dt>
<dd>Optional. Organizational group to place the playable in.</dd>
<dt>config.duration <span class="property-type">number</span></dt>
<dd>Playable duration (ms)</dd>
<dt class="optional">config.durationType <span class="property-type">string</span></dt>
<dd>Optional. Can be <code>static</code>, <code>dynamic</code> or <code>loop</code></dd>
<dt class="optional">config.forceCached <span class="property-type">boolean</span></dt>
<dd>Optional. Whether the playable is available for Instant Play.</dd>
</dl>
<h4>Action delete</h4>
<dl class="message-properties">
<dt>config.externalRef <span class="property-type">string</span></dt>
<dd>The externalRef of the playable to delete.</dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>The playable(s).</dd>
<dt>statusCode <span class="property-type">number</span></dt>
<dd>The status code of the response.</dd>
</dl>
</script>