UNPKG

@isaac-platform/isaac-node-red

Version:

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

228 lines (207 loc) 8.13 kB
<script type="text/javascript"> // isaac prefix ensures that node appears when filtering by "isaac" RED.nodes.registerType('isaac control panel', { category: 'ISAAC', color: '#C0C0C0', icon: 'isaac.svg', inputs: 1, outputs: 1, paletteLabel: 'control panel', label: function () { if (this.name) { return this.name; } return this.paletteLabel; }, defaults: { isaacConnection: { type: 'isaac-connection', required: true }, name: { value: '' }, action: { value: 'getOne' }, location: { value: 'registered' }, displayName: { value: '' }, description: { value: '' }, url: { value: '' }, openExternally: { value: false }, _id: { value: null }, payload: { value: '{}' }, }, 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'; }); const span = document.querySelector('#panels-note-span'); if (span) { span.style.display = 'inline'; } 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=Control Panels`; } const workspaceLinks = document.querySelectorAll('.isaac-workspace-link'); workspaceLinks.forEach((link) => { link.style.display = getDisplay(link); link.href = `${configNode.ipAddress}/system/panels`; }); const span = document.querySelector('#panels-note-span'); if (span) { span.style.display = 'none'; } }; updateLinks(); $('#node-input-isaacConnection').change(updateLinks); $('#node-input-action').change((e) => { $('.action-related').hide(); $('.location-option').hide(); const value = e.target.value; if (value === 'getAll') { $('#row-location').show(); $('#location-all').show(); $('#location-registered').show(); $('#location-available').show(); } else if (value === 'add') { $('#row-payload').show(); $('#row-location').show(); $('#location-registered').show(); $('#location-available').show(); if ($('#node-input-location').val() === 'all') { $('#node-input-location').val('registered').change(); } } else if (value === 'update') { $('#row-_id').show(); $('#row-payload').show(); } else if (value === 'getOne' || value === 'delete') { $('#row-_id').show(); } }); $('#node-input-payload').typedInput({ type: 'json', types: ['json'] }); }, oneditsave: function () { this.openExternally = document.querySelector('#node-config-input-openExternally').checked; }, }); </script> <script type="text/html" data-template-name="isaac control panel"> <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" style="width:250px"> <option value="getOne">Get one</option> <option value="getAll">Get all</option> <option value="add">Add one</option> <option value="update">Update one</option> <option value="delete">Delete one</option> </select> </div> <div class="form-row action-related" id="row-location"> <label title="Can be overwritten by msg.config.location"> <i class="fa fa-folder"></i> Location </label> <select id="node-input-location"> <option value="all" class="location-option" id="location-all">Available & Registered</option> <option value="registered" class="location-option" id="location-registered">Registered</option> <option value="available" class="location-option" id="location-available">Available</option> </select> </div> <div class="form-row action-related" id="row-_id"> <label for="node-input-_id" title="Can be overwritten by msg.config._id">ID <strong>*</strong></label> <input type="text" id="node-input-_id" /> </div> <div class="form-row action-related" id="row-payload"> <label for="node-input-payload" title="Can be overwritten by msg.payload">Payload <strong>*</strong></label> <input type="text" id="node-input-payload" /> </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: Panels </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: Control Panels </a> </div> </script> <script type="text/html" data-help-name="isaac control panel"> <p> Fetches, creates, updates and deletes ISAAC control panels. Values passed in <code>msg.config</code> will override values enterred in the UI editor dialog. </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>add</code>, <code>update</code> or <code>delete</code>. </dd> </dl> <h4>Action getAll</h4> <dl class="message-properties"> <dt class="optional">config.location <span class="property-type">string</span></dt> <dd>Optional. Used to filter by location. Can be: <code>registered</code>, <code>available</code> or <code>all</code> (equivalent to omitting the value)</code></dd> </dl> <h4>Action getOne</h4> <dl class="message-properties"> <dt>config._id <span class="property-type">number</span></dt> <dd>ID of the control panel to fetch.</dd> </dl> <h4>Action add</h4> <dl class="message-properties"> <dt>payload <span class="property-type">object</span></dt> <dd>The values needed to create a control panel. Refer to the API documentation for the latest schemas.</dd> <dt>config.location <span class="property-type">string</span></dt> <dd>Location of the panel. Required if <code>location</code> is not specified in <code>payload</code>. Can be: <code>registered</code> or <code>available</code></dd> </dl> <h4>Action update</h4> <dl class="message-properties"> <dt>payload <span class="property-type">object</span></dt> <dd>The updated values of the control panel. Refer to the API documentation for the latest schemas.</dd> <dt>config._id <span class="property-type">number</span></dt> <dd>ID of the control panel to update.</dd> </dl> <h4>Action delete</h4> <dl class="message-properties"> <dt>config._id <span class="property-type">number</span></dt> <dd>ID of the control panel to delete.</dd> </dl> <h3>Outputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">object</span></dt> <dd>The control panel(s).</dd> <dt>statusCode <span class="property-type">number</span></dt> <dd>The status code of the response.</dd> </dl> </script>