UNPKG

@isaac-platform/isaac-node-red

Version:

Set of Node-RED nodes to communicate with an ISAAC system

192 lines (177 loc) 7.2 kB
<script type="text/javascript"> // isaac prefix ensures that node appears when filtering by "isaac" RED.nodes.registerType('isaac schedule', { category: 'ISAAC', color: '#C0C0C0', icon: 'isaac.svg', inputs: 1, outputs: 1, paletteLabel: 'schedule', label: function () { if (this.name) { return this.name; } return this.paletteLabel; }, defaults: { isaacConnection: { type: 'isaac-connection', required: true }, name: { value: '' }, prerollWarning: { value: 0 }, upcomingTime: { value: 0 }, upcomingCount: { value: 0 }, useIfModifiedSince: { 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=Schedule`; } const workspaceLinks = document.querySelectorAll('.isaac-workspace-link'); workspaceLinks.forEach((link) => { link.style.display = getDisplay(link); link.href = `${configNode.ipAddress}/schedule/liveschedule`; }); }; updateLinks(); $('#node-input-isaacConnection').change(updateLinks); document.querySelector('#node-config-input-useIfModifiedSince').checked = !!this.useIfModifiedSince; }, oneditsave: function () { this.useIfModifiedSince = document.querySelector('#node-config-input-useIfModifiedSince').checked; }, }); </script> <script type="text/html" data-template-name="isaac schedule"> <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-prerollWarning" title="Can be overwritten by msg.config.prerollWarning"> Preroll Warning (ms) </label> <input type="number" id="node-input-prerollWarning" /> </div> <div class="form-row"> <b title="The follow options only apply to the getUpcomingItems and getCurrentPlaying commands.">Commands Only</b> </div> <div class="form-row"> <label for="node-input-upcomingTime" title="Can be overwritten by msg.config.upcomingTime. Only applies to getUpcomingItems." > Upcoming Time (s) </label> <input type="number" id="node-input-upcomingTime" /> </div> <div class="form-row"> <label for="node-input-upcomingCount" title="Can be overwritten by msg.config.upcomingCount. Applies to both commands." > Upcoming Count </label> <input type="number" id="node-input-upcomingCount" /> </div> <div class="form-row"> <label for="node-config-input-useIfModifiedSince" title="Can be overwritten by msg.config.useIfModifiedSince. Applies to both commands." > Get changed data only </label> <input class="switch__input" type="checkbox" id="node-config-input-useIfModifiedSince" 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: Live Schedule </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: Schedule </a> </div> </script> <script type="text/html" data-help-name="isaac schedule"> <p> Receives live updates from the ISAAC schedule engine. Also responds to commands to fetch upcoming or current items as needed. </p> <h3>Inputs</h3> <h4>Running schedule</h4> <dl class="message-properties"> <dt class="optional">config.prerollWarning <span class="property-type">number</span></dt> <dd>Optional. In ms.</dd> </dl> <h4>Commands</h4> <dl class="message-properties"> <dt>config.command <span class="property-type">string</span></dt> <dd>Can be <code>getUpcomingItems</code> or <code>getCurrentPlaying</code></dd> <dt class="optional">config.upcomingCount <span class="property-type">number</span></dt> <dd> Optional. Applies to both commands. The amount of upcoming items to fetch. <b>Important:</b> This property should not be used (i.e. omitted from incoming messages and set to 0 in UI form) when <code>config.useIfModifiedSince</code> is enabled, as using both together may yield unexpected results. </dd> <dt class="optional">config.upcomingTime <span class="property-type">number</span></dt> <dd> Optional. Applies to command <code>getUpcomingItems</code>. The max difference, in seconds, between the start of a schedule item and the current time for the item to be considered upcoming. </dd> <dt class="optional">config.useIfModifiedSince <span class="property-type">boolean</span></dt> <dd> Optional. Applies to both commands. If enabled, the node will use the schedule service's <code>If-Modified-Since</code> header when fetching schedule items. Each command has its own last fetch time which is updated when the schedule is successfully fetched and reset when <code>useIfModifiedSince</code> is disabled. If the schedule data has not changed since the last fetch, <code>msg.payload</code> will be an empty array, and <code>msg.unchanged</code> will be set to <code>true</code>. <b>Important:</b> When this property is enabled, <code>config.upcomingCount</code> should not be used (i.e. omitted from incoming messages and set to 0 in UI form), as using both together may yield unexpected results. </dd> </dl> <h3>Outputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">object</span></dt> <dd>The items returned by the running schedule or as a result of commands sent to the node.</dd> <dt>topic <span class="property-type">string</span></dt> <dd> <code>item</code> or <code>preroll</code> when originating from the running schedule. <code>upcoming</code> or <code>current</code> when responding to commands. </dd> </dl> </script>