UNPKG

node-red-contrib-neuralnetwork

Version:

SmartNode node package, provided by MakerCollider

136 lines (120 loc) 6.17 kB
/** * Copyright 2015, 2015 MakerCollider. * * 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. **/ <script type="text/x-red" data-template-name="outputJudge"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="outputJudge.label.name"></span></label> <input type="text" id="node-input-name" data-i18n="[placeholder]outputJudge.label.placeholder"> </div> <div class="form-row" style="margin-bottom:0;"> <label><i class="fa fa-list"></i> <span data-i18n="outputJudge.label.rules"></span></label> </div> <div class="form-row node-input-rule-container-row" style="margin-bottom: 0px;"> <div id="node-input-rule-container-div" style="box-sizing: border-box; border-radius: 5px; height: 250px; padding: 5px; border: 1px solid #ccc; overflow-y:scroll;"> <ol id="node-input-rule-container" style=" list-style-type:none; margin: 0;"></ol> </div> </div> <div class="form-row"> <a href="#" class="editor-button editor-button-small" id="node-input-add-rule" style="margin-top: 4px;"><i class="fa fa-plus"></i> <span data-i18n="outputJudge.label.addbutton"></span></a> </div> <div class="form-row"> <label><i class="fa fa-empire"></i> <span data-i18n="outputJudge.label.judgeType"></span></label> <select for="node-input-judgeType" style="width:73%" id="node-input-judgeType"> <option value ="1">Max</option> <option value ="0">Min</option> </select> </div> <div class="form-row"> <label for="node-input-resultValue"><i class="fa fa-clock-o"></i> <span data-i18n="outputJudge.label.resultValue"></span></label> <input type="text" id="node-input-resultValue"> </div> </script> <script type="text/x-red" data-help-name="outputJudge"> </script> <script type="text/javascript"> RED.nodes.registerType('outputJudge', { color: "#E2D96E", category: 'brain', defaults: { name: {value:""}, rules: {value:[{name:"",value:0},]}, judgeType: {value:"1", required: true}, resultValue: {value:"", required: true} }, inputs: 1, outputs: 1, icon: "light.png", label: function() { return this.name||"outputJudge"; }, paletteLabel: function () { return this.name||this._("outputJudge.label.palette"); }, oneditprepare: function() { function generateRule(i,rule) { var container = $('<li/>',{style:"background: #fff; margin:0; padding:8px 0px; border-bottom: 1px solid #ccc;"}); var row = $('<div/>').appendTo(container); $('<i style="color: #eee; cursor: move;" class="node-input-rule-handle fa fa-bars"></i>').appendTo(row); $('<div/>',{style:"display:inline-block; width: 50px; text-align: right;"}).text("msg.").appendTo(row); var valueField = $('<input/>',{class:"node-input-rule-value",type:"text",style:"margin-left: 5px; width: 145px;"}).appendTo(row); $('<div/>',{style:"display:inline-block; width: 30px; text-align:center;"}).text("to").appendTo(row); var valueField2 = $('<input/>',{class:"node-input-rule-to-value",type:"text",style:"margin-left: 5px; width: 50px;"}).appendTo(row); var finalspan = $('<span/>',{style:"float: right;margin-right: 10px;"}).appendTo(row); finalspan.append(' &#8594; <span class="node-input-rule-index">'+i+'</span> '); var deleteButton = $('<a/>',{href:"#",class:"editor-button editor-button-small", style:"margin-top: 7px; margin-left: 5px;"}).appendTo(finalspan); $('<i/>',{class:"fa fa-remove"}).appendTo(deleteButton); deleteButton.click(function() { container.css({"background":"#fee"}); container.fadeOut(300, function() { $(this).remove(); $("#node-input-rule-container").children().each(function(i) { $(this).find(".node-input-rule-index").html(i+1); }); }); }); $("#node-input-rule-container").append(container); valueField.val(rule.name); valueField2.val(rule.value); } //add input param rule $("#node-input-add-rule").click(function() { generateRule($("#node-input-rule-container").children().length+1,{name:""}); $("#node-input-rule-container-div").scrollTop($("#node-input-rule-container-div").get(0).scrollHeight); }); //init for (var i=0;i<this.rules.length;i++) { var rule = this.rules[i]; generateRule(i+1,rule); } }, oneditsave: function() { function saveRules(e) { var rules = $("#node-input-rule-container").children(); var node = e; node.rules= []; rules.each(function(i) { var rule = $(this); var n = rule.find(".node-input-rule-value").val(); var m = rule.find(".node-input-rule-to-value").val(); if (n.length > 0){ var r = {name:n,value:m}; node.rules.push(r); } }); } saveRules(this); } }); </script>