UNPKG

node-red-contrib-kolibri

Version:

Node-RED nodes for connecting to a Kolibri Broker (e.g. HMS Hub)

153 lines (150 loc) 7.77 kB
<script type="text/javascript"> (function () { 'use strict'; /* * Copyright 2021 HMS Industrial Networks AB * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http: //www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ RED.nodes.registerType('kolibri-broker', { category: 'config', defaults: { name: { value: '', required: true }, broker: { value: '', required: true, validate: RED.validators.regex(/(?:^|[ \t])((?:localhost|[\w-]+(?:\.[\w-]+)+)(\/\S*)?)/i) }, port: { value: 443, required: true, validate: RED.validators.number() }, path: { value: '/', required: true, validate: RED.validators.regex(/^\/(([a-z0-9][a-z0-9_.-]{0,30}\/?)*[a-z0-9])?$/i) }, useProxy: { value: false, required: false }, proxyHost: { value: 'localhost', required: false }, proxyPort: { value: 8080, required: false, validate: function (v) { var isEnabled = $('#node-config-input-useProxy').is(':checked'); if (isEnabled) { return !isNaN(v) && !isNaN((Number.parseInt(v))) && Number.parseInt(v) >= 0; } return true; } }, proxyProtocol: { value: 'http', required: true, validate: function (v) { var isEnabled = $('#node-config-input-useProxy').is(':checked'); if (isEnabled) { if (v === 'http' || v === 'https') { return true; } return false; } return true; } }, project: { value: '', required: true }, clientId: { value: '', required: false, validate: RED.validators.regex(/(^$|(([a-z0-9])|([a-z0-9][a-z0-9_.-]{0,30}[a-z0-9]))$)|(^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$)/i) } }, credentials: { user: { type: 'text' }, password: { type: 'password' } }, label: function () { return this.name || 'kolibri-broker'; }, oneditprepare: function () { var tabs = RED.tabs.create({ id: 'node-config-kolibri-broker-tabs', onchange: function (tab) { $('#node-config-kolibri-broker-tabs-content').children().hide(); $('#' + tab.id).show(); } }); tabs.addTab({ id: 'kolibri-broker-tab-connection', label: 'Connection' }, 0); tabs.addTab({ id: 'kolibri-broker-tab-security', label: 'Security' }, 1); setTimeout(function () { tabs.resize(); }, 0); } }); })(); </script> <script type="text/html" data-template-name="kolibri-broker"> <div class="form-row"> <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-config-input-name" placeholder="Name"> </div> <div class="form-row"> <ul style="background: #fff; min-width: 600px; margin-bottom: 20px;" id="node-config-kolibri-broker-tabs"></ul> </div> <div id="node-config-kolibri-broker-tabs-content" style="min-height: 170px;"> <div id="kolibri-broker-tab-connection" style="display:none"> <label for="broker-border"></i> Kolibri Broker</label> <div id="broker-border" style="border-style:solid; border-width:1px; padding:5px;"> <div class="form-row node-input-broker"> <label for="node-config-input-broker"><i class="fa fa-globe"></i> Server</label> <input class="input-append-left" type="text" id="node-config-input-broker" placeholder="PROJECT.hms-hub.com" style="width: 50%;"> <label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label> <input type="text" id="node-config-input-port" placeholder="443" style="width:45px"> </div> <div class="form-row node-input-project" id="project_field" style="display: block"> <label for="node-config-input-project"><i class="fa fa-clipboard"></i> Project</label> <input class="input-append-left" type="text" id="node-config-input-project" placeholder="testv21" style="width: 50%;"> </div> <div class="form-row node-input-path" id="path_field" style="display: block"> <label for="node-config-input-path"><i class="fa fa-clipboard"></i> Path</label> <input class="input-append-left" type="text" id="node-config-input-path" placeholder="/" style="width: 50%;"> </div> </div> <label for="proxy-border"></i> Proxy</label> <div style="border-style:solid; border-width:1px; padding:5px;"> <div class="form-row"> <label for="node-config-input-useProxy"><i class="fa fa-check"></i> Enable</label> <input class="input-append-left" type="checkbox" id="node-config-input-useProxy" placeholder="false" style="width:auto"> </div> <div class="form-row"> <div style="margin-bottom: 10px;"> <label for="node-config-input-proxyProtocol"><i class="fa fa-angle-double-right"></i> Protocol</label> <select id="node-config-input-proxyProtocol" class="input-append-left" style="width: fit-content;" > <option value="http" selected="selected">HTTP</option> <option value="https">HTTPS</option> </select> </div> <label for="node-config-input-proxyHost"><i class="fa fa-globe"></i> Server</label> <input class="input-append-left" type="text" id="node-config-input-proxyHost" placeholder="" style="width: 50%;"> <label for="node-config-input-proxyPort" style="margin-left: 10px; width: 35px; "> Port</label> <input type="text" id="node-config-input-proxyPort" placeholder="" style="width:45px"> </div> </div> </div> <div id="kolibri-broker-tab-security" style="display:none"> <div class="form-row"> <label for="node-config-input-user"><i class="fa fa-user"></i> Username</span></label> <input type="text" id="node-config-input-user"> </div> <div class="form-row"> <label for="node-config-input-password"><i class="fa fa-lock"></i> Password</span></label> <input type="password" id="node-config-input-password"> </div> <div class="form-row"> <label for="node-config-input-clientId"><i class="fa fa-user"></i> Client ID</label></label> <input type="text" id="node-config-input-clientId""> </div> </div> </div> </script> <script type="text/html" data-help-name="kolibri-broker"> <p>A minimum Kolibri broker connection requires only a broker server address to be added to the default configuration.</p> </script>