UNPKG

node-red-contrib-susi

Version:
119 lines (103 loc) 4.36 kB
<!-- Copyright 2014, 2015 ADVANTECH Corp. 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. --> <!-- Define the edit dialog. --> <script type="text/x-red" data-template-name="SUSIIoT-Data"> <div class="form-row"> <label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label> <input type="text" id="node-input-topic" placeholder="Topic"> </div> <br/> <div class="form-row"> <label for="node-input-feature"><i class="fa fa-dot-circle-o"></i> Feature</label> <select id="node-input-feature" onchange="FeatureChangeIndex()"> </select> </div> <br/> <div class="form-row" id="row-featuretype"> <label for="node-input-featuretype"><i class="fa fa-dot-circle-o"></i> Type</label> <select id="node-input-featuretype"> </select> </div> <br/> <!-- Node name --> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> </script> <!-- Next, some simple help text is provided for the node. --> <script type="text/x-red" data-help-name="SUSIIoT-Data"> <p>Node to retrieve the status of a ADVANTECH platform by SUSIIoT, either at startup, or at a predefined period, determined by an input message</p> <p>Outputs a <b>msg</b> containing <b>msg.topic</b> which defaults to the sensor name, and <b>msg.payload</b> containing the reading.</p> </script> <script type="text/javascript"> RED.nodes.registerType('SUSIIoT-Data', { category: 'ADVANTECH', // the palette category defaults: { // defines the editable properties of the node name: {value: ""}, topic: {value: "SUSIIoT Data"}, feature: {value: ""}, featuretype: {value: ""} }, inputs: 1, // set the number of inputs - only 0 or 1 outputs: 1, // set the number of outputs - 0 to n color: "#FFAAAA", icon: "white-globe.png", // saved in icons/myicon.png paletteLabel: "IoT Data", label: function() { // sets the default label contents return this.name||this.topic||"SUSIIoT-Data"; }, labelStyle: function() { // sets the class to apply to the label return this.name ? "node_label_italic": ""; }, oneditprepare: ws_oneditprepare_Data }); var typelist = []; function FeatureChangeIndex() { var list = typelist[$("#node-input-feature").val()]; if (list != null && list != "") { $("#node-input-featuretype").html(list); $("#row-featuretype").show(); } else { var temp = "All"; $("#node-input-featuretype").val(temp); $("#row-featuretype").hide(); } } function ws_oneditprepare_Data() { featuretmp = this.feature; featuretypetmp = this.featuretype; $.getJSON('SUSIIoT',function(data) { featurelist = "<option value=All>All</option>"; for (var i=0; i<data.length; i++) { featurelist = featurelist + '<option value="' + data[i][0] + '">' + data[i][0] +'</option>'; if(data[i].length > 1) typelist[data[i][0]] = "<option value=All>All</option>"; for (var j=1; j<data[i].length; j++) { typelist[data[i][0]] = typelist[data[i][0]] + '<option value="' + data[i][j] + '">' + data[i][j] +'</option>'; } } $("#node-input-feature").html(featurelist); $("#node-input-feature").val(featuretmp); FeatureChangeIndex(); var temp = "All"; if (typelist[featuretmp] != 'undefined') $("#node-input-featuretype").val(featuretypetmp); else $("#node-input-featuretype").val(temp); }); } </script>