diff options
Diffstat (limited to 'dgbuilder/core_nodes/logic')
-rw-r--r-- | dgbuilder/core_nodes/logic/10-switch.html | 198 | ||||
-rw-r--r-- | dgbuilder/core_nodes/logic/10-switch.js | 78 | ||||
-rw-r--r-- | dgbuilder/core_nodes/logic/15-change.html | 139 | ||||
-rw-r--r-- | dgbuilder/core_nodes/logic/15-change.js | 74 | ||||
-rw-r--r-- | dgbuilder/core_nodes/logic/16-range.html | 81 | ||||
-rw-r--r-- | dgbuilder/core_nodes/logic/16-range.js | 48 |
6 files changed, 0 insertions, 618 deletions
diff --git a/dgbuilder/core_nodes/logic/10-switch.html b/dgbuilder/core_nodes/logic/10-switch.html deleted file mode 100644 index 4e02f446..00000000 --- a/dgbuilder/core_nodes/logic/10-switch.html +++ /dev/null @@ -1,198 +0,0 @@ -<!-- - Copyright 2013 IBM 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. ---> - -<script type="text/x-red" data-template-name="switch"> - <div class="form-row"> - <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> - <input type="text" id="node-input-name" placeholder="Name"> - </div> - <div class="form-row" style="padding-top:10px;"> - If msg.<input type="text" id="node-input-property" style="width: 200px;"/> - </div> - <div class="form-row"> - <div id="node-input-rule-container-div" style="border-radius: 5px; height: 310px; padding: 5px; border: 1px solid #ccc; overflow-y:scroll;"> - <ol id="node-input-rule-container" style=" list-style-type:none; margin: 0;"> - </ol> - </div> - <a href="#" class="btn btn-mini" id="node-input-add-rule" style="margin-top: 4px;"><i class="fa fa-plus"></i> Add</a> - </div> - <div> - <select id="node-input-checkall" style="width:100%; margin-right:5px;"> - <option value="true">checking all rules</option> - <option value="false">stopping after first match</option> - </select> - </div> -</script> - -<script type="text/x-red" data-help-name="switch"> - <p>A simple function node to route messages based on its properties.</p> - <p>When a message arrives, the selected property is evaluated against each - of the defined rules. The message is then sent to the output of <i>all</i> - rules that pass.</p> - <p>Note: the <i>otherwise</i> rule applies as a "not any of" the rules preceding it.</p> -</script> - -<script type="text/javascript"> - RED.nodes.registerType('switch', { - color: "#E2D96E", - category: 'function', - defaults: { - name: {value:""}, - property: {value:"payload", required:true}, - rules: {value:[{t:"eq", v:""}]}, - checkall: {value:"true", required:true}, - outputs: {value:1} - }, - inputs: 1, - outputs: 1, - icon: "switch.png", - label: function() { - return this.name||"switch"; - }, - oneditprepare: function() { - - var operators = [ - {v:"eq",t:"=="}, - {v:"neq",t:"!="}, - {v:"lt",t:"<"}, - {v:"lte",t:"<="}, - {v:"gt",t:">"}, - {v:"gte",t:">="}, - {v:"btwn",t:"is between"}, - {v:"cont",t:"contains"}, - {v:"regex",t:"matches regex"}, - {v:"true",t:"is true"}, - {v:"false",t:"is false"}, - {v:"null",t:"is null"}, - {v:"nnull",t:"is not null"}, - {v:"else",t:"otherwise"} - ]; - - function generateRule(i,rule) { - var container = $('<li/>',{style:"margin:0; padding:8px 0px; border-bottom: 1px solid #ccc;"}); - var row = $('<div/>').appendTo(container); - var row2 = $('<div/>',{style:"padding-top: 5px; text-align: right;"}).appendTo(container); - - var selectField = $('<select/>',{style:"width:120px; margin-left: 5px; text-align: center;"}).appendTo(row); - for (var d in operators) { - selectField.append($("<option></option>").val(operators[d].v).text(operators[d].t)); - } - - var valueField = $('<input/>',{class:"node-input-rule-value",type:"text",style:"margin-left: 5px; width: 145px;"}).appendTo(row); - var btwnField = $('<span/>').appendTo(row); - var btwnValueField = $('<input/>',{class:"node-input-rule-btwn-value",type:"text",style:"margin-left: 5px; width: 50px;"}).appendTo(btwnField); - btwnField.append(" and "); - var btwnValue2Field = $('<input/>',{class:"node-input-rule-btwn-value2",type:"text",style:"width: 50px;margin-left:2px;"}).appendTo(btwnField); - - var finalspan = $('<span/>',{style:"float: right; margin-top: 3px;margin-right: 10px;"}).appendTo(row); - finalspan.append(' send to <span class="node-input-rule-index">'+i+'</span> '); - - selectField.change(function() { - var type = selectField.children("option:selected").val(); - if (type.length < 4) { - selectField.css({"width":"60px"}); - } else if (type === "regex") { - selectField.css({"width":"147px"}); - } else { - selectField.css({"width":"120px"}); - } - if (type === "btwn") { - valueField.hide(); - btwnField.show(); - } else { - btwnField.hide(); - if (type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else") { - valueField.hide(); - } else { - valueField.show(); - } - } - }); - - var deleteButton = $('<a/>',{href:"#",class:"btn btn-mini", style:"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); - - selectField.find("option").filter(function() {return $(this).val() == rule.t;}).attr('selected',true); - if (rule.t == "btwn") { - btwnValueField.val(rule.v); - btwnValue2Field.val(rule.v2); - } else if (typeof rule.v != "undefined") { - valueField.val(rule.v); - } - selectField.change(); - } - - $("#node-input-add-rule").click(function() { - generateRule($("#node-input-rule-container").children().length+1,{t:"",v:"",v2:""}); - $("#node-input-rule-container-div").scrollTop($("#node-input-rule-container-div").get(0).scrollHeight); - }); - - for (var i=0;i<this.rules.length;i++) { - var rule = this.rules[i]; - generateRule(i+1,rule); - } - - function switchDialogResize(ev,ui) { - $("#node-input-rule-container-div").css("height",(ui.size.height-260)+"px"); - }; - - $( "#dialog" ).on("dialogresize", switchDialogResize); - $( "#dialog" ).one("dialogopen", function(ev) { - var size = $( "#dialog" ).dialog('option','sizeCache-switch'); - if (size) { - switchDialogResize(null,{size:size}); - } - }); - $( "#dialog" ).one("dialogclose", function(ev,ui) { - $( "#dialog" ).off("dialogresize",switchDialogResize); - }); - }, - oneditsave: function() { - var rules = $("#node-input-rule-container").children(); - var ruleset; - var node = this; - node.rules= []; - rules.each(function(i) { - var rule = $(this); - var type = rule.find("select option:selected").val(); - var r = {t:type}; - if (!(type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else")) { - if (type === "btwn") { - r.v = rule.find(".node-input-rule-btwn-value").val(); - r.v2 = rule.find(".node-input-rule-btwn-value2").val(); - } else { - r.v = rule.find(".node-input-rule-value").val(); - } - } - node.rules.push(r); - }); - node.outputs = node.rules.length; - } - }); -</script> diff --git a/dgbuilder/core_nodes/logic/10-switch.js b/dgbuilder/core_nodes/logic/10-switch.js deleted file mode 100644 index 8bcb8571..00000000 --- a/dgbuilder/core_nodes/logic/10-switch.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright 2013 IBM 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. - **/ - -module.exports = function(RED) { - "use strict"; - var operators = { - 'eq': function(a, b) { return a == b; }, - 'neq': function(a, b) { return a != b; }, - 'lt': function(a, b) { return a < b; }, - 'lte': function(a, b) { return a <= b; }, - 'gt': function(a, b) { return a > b; }, - 'gte': function(a, b) { return a >= b; }, - 'btwn': function(a, b, c) { return a >= b && a <= c; }, - 'cont': function(a, b) { return (a + "").indexOf(b) != -1; }, - 'regex': function(a, b) { return (a + "").match(new RegExp(b)); }, - 'true': function(a) { return a === true; }, - 'false': function(a) { return a === false; }, - 'null': function(a) { return typeof a == "undefined"; }, - 'nnull': function(a) { return typeof a != "undefined"; }, - 'else': function(a) { return a === true; } - }; - - function SwitchNode(n) { - RED.nodes.createNode(this, n); - this.rules = n.rules; - this.property = n.property; - this.checkall = n.checkall || "true"; - var propertyParts = n.property.split("."); - var node = this; - - for (var i=0; i<this.rules.length; i+=1) { - var rule = this.rules[i]; - if (!isNaN(Number(rule.v))) { - rule.v = Number(rule.v); - rule.v2 = Number(rule.v2); - } - } - - this.on('input', function (msg) { - var onward = []; - try { - var prop = propertyParts.reduce(function (obj, i) { - return obj[i] - }, msg); - var elseflag = true; - for (var i=0; i<node.rules.length; i+=1) { - var rule = node.rules[i]; - var test = prop; - if (rule.t == "else") { test = elseflag; elseflag = true; } - if (operators[rule.t](test,rule.v, rule.v2)) { - onward.push(msg); - elseflag = false; - if (node.checkall == "false") { break; } - } else { - onward.push(null); - } - } - this.send(onward); - } catch(err) { - node.warn(err); - } - }); - } - RED.nodes.registerType("switch", SwitchNode); -} diff --git a/dgbuilder/core_nodes/logic/15-change.html b/dgbuilder/core_nodes/logic/15-change.html deleted file mode 100644 index 702dd807..00000000 --- a/dgbuilder/core_nodes/logic/15-change.html +++ /dev/null @@ -1,139 +0,0 @@ -<!-- - Copyright 2013 IBM 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. ---> - -<script type="text/x-red" data-template-name="change"> - <div> - <select id="node-input-action" style="width:95%; margin-right:5px;"> - <option value="replace">Set the value of the message property</option> - <option value="change">Search/replace the value of the message property</option> - <option value="delete">Delete the message property</option> - </select> - </div> - <div class="form-row" style="padding-top:10px;" id="node-prop1-row"> - <label for="node-input-property">called</label> msg.<input type="text" id="node-input-property" style="width: 63%;"/> - </div> - <div class="form-row" id="node-from-row"> - <label for="node-input-from" id="node-input-f"></label> - <input type="text" id="node-input-from" placeholder="this"/> - </div> - <div class="form-row" id="node-to-row"> - <label for="node-input-to" id="node-input-t"></label> - <input type="text" id="node-input-to" placeholder="that"/> - </div> - <div class="form-row" id="node-reg-row"> - <label> </label> - <input type="checkbox" id="node-input-reg" style="display: inline-block; width: auto; vertical-align: top;"> - <label for="node-input-reg" style="width: 70%;">Use regular expressions ?</label> - </div> - <div class="form-tips" id="node-tip"></div> - <br/> - <div class="form-row"> - <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> - <input type="text" id="node-input-name" placeholder="Name"> - </div> -</script> - -<script type="text/x-red" data-help-name="change"> - <p>A simple function node to change, replace, add or delete properties of a message.</p> - <p>When a message arrives, the selected property is modified by the defined rules. - The message is then sent to the output.</p> - <p><b>Note:</b> Replace only operates on <b>strings</b>. Anything else will be passed straight through.</p> -</script> - -<script type="text/javascript"> - RED.nodes.registerType('change', { - color: "#E2D96E", - category: 'function', - defaults: { - action: {value:"replace",required:true}, - property: {value:"payload",required:true}, - from: {value:"",validate: function(v) { - if (this.action == "change" && this.reg) { - try { - var re = new RegExp(this.from, "g"); - return true; - } catch(err) { - return false; - } - } - return true; - }}, - to: {value:""}, - reg: {value:false}, - name: {value:""} - }, - inputs: 1, - outputs: 1, - icon: "swap.png", - label: function() { - if (this.name) { - return this.name; - } - if (this.action == "replace") { - return "set msg."+this.property; - } else { - return this.action+" msg."+this.property - } - }, - labelStyle: function() { - return this.name ? "node_label_italic" : ""; - }, - oneditprepare: function() { - if (this.reg === null) { $("#node-input-reg").prop('checked', true); } - $("#node-input-action").change( function() { - var a = $("#node-input-action").val(); - if (a === "replace") { - $("#node-input-todo").html("called"); - //$("#node-input-f").html("name"); - $("#node-input-t").html("to"); - $("#node-from-row").hide(); - $("#node-to-row").show(); - $("#node-reg-row").hide(); - $("#node-tip").show(); - $("#node-tip").html("Tip: expects a new property name and either a fixed value OR the full name of another message property eg: msg.sentiment.score"); - } - if (a === "delete") { - $("#node-input-todo").html("called"); - //$("#node-input-f").html("called"); - //$("#node-input-t").html("to"); - $("#node-from-row").hide(); - $("#node-to-row").hide(); - $("#node-reg-row").hide(); - $("#node-tip").hide(); - } - if (a === "change") { - $("#node-input-todo").html("called"); - $("#node-input-f").html("Search for"); - $("#node-input-t").html("replace with"); - $("#node-from-row").show(); - $("#node-to-row").show(); - $("#node-reg-row").show(); - $("#node-tip").show(); - $("#node-tip").html("Tip: only works on string properties. If regular expressions are used, the <i>replace with</i> field can contain capture results, eg $1."); - } - //if (a === "replace") { - // $("#node-input-todo").html("called"); - // //$("#node-input-f").html("with"); - // $("#node-input-t").html("with"); - // $("#node-from-row").hide(); - // $("#node-to-row").show(); - // $("#node-tip").html("Tip: accepts either a fixed value OR the full name of another msg.property eg: msg.sentiment.score"); - //} - }); - $("#node-input-action").change(); - } - }); -</script> diff --git a/dgbuilder/core_nodes/logic/15-change.js b/dgbuilder/core_nodes/logic/15-change.js deleted file mode 100644 index b7ef62e1..00000000 --- a/dgbuilder/core_nodes/logic/15-change.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2013 IBM 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. - **/ - -module.exports = function(RED) { - "use strict"; - function ChangeNode(n) { - RED.nodes.createNode(this, n); - this.action = n.action; - this.property = n.property || ""; - this.from = n.from || " "; - this.to = n.to || " "; - this.reg = (n.reg === null || n.reg); - var node = this; - if (node.reg === false) { - this.from = this.from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); - } - var makeNew = function( stem, path, value ) { - var lastPart = (arguments.length === 3) ? path.pop() : false; - for (var i = 0; i < path.length; i++) { - stem = stem[path[i]] = stem[path[i]] || {}; - } - if (lastPart) { stem = stem[lastPart] = value; } - return stem; - }; - - this.on('input', function (msg) { - if (node.action == "change") { - try { - node.re = new RegExp(this.from, "g"); - } catch (e) { - node.error(e.message); - } - if (typeof msg[node.property] === "string") { - msg[node.property] = (msg[node.property]).replace(node.re, node.to); - } - } - //else if (node.action == "replace") { - //if (node.to.indexOf("msg.") == 0) { - //msg[node.property] = eval(node.to); - //} - //else { - //msg[node.property] = node.to; - //} - //} - else if (node.action == "replace") { - if (node.to.indexOf("msg.") === 0) { - makeNew( msg, node.property.split("."), eval(node.to) ); - } - else { - makeNew( msg, node.property.split("."), node.to ); - } - //makeNew( msg, node.property.split("."), node.to ); - } - else if (node.action == "delete") { - delete(msg[node.property]); - } - node.send(msg); - }); - } - RED.nodes.registerType("change", ChangeNode); -} diff --git a/dgbuilder/core_nodes/logic/16-range.html b/dgbuilder/core_nodes/logic/16-range.html deleted file mode 100644 index 5f87128f..00000000 --- a/dgbuilder/core_nodes/logic/16-range.html +++ /dev/null @@ -1,81 +0,0 @@ -<!-- - Copyright 2013 IBM 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. ---> - -<script type="text/x-red" data-template-name="range"> - <div class="form-row"> - <label for="node-input-action"><i class="fa fa-dot-circle-o"></i> Action</label> - <select id="node-input-action" style="width:70%; margin-right:5px;"> - <option value="scale">Scale msg.payload</option> - <option value="clamp">Scale and limit to the target range</option> - <option value="roll">Scale and wrap within the target range</option> - </select> - </div> - <br/> - <div class="form-row"><i class="fa fa-sign-in"></i> Map the input range:</div> - <div class="form-row"><label></label> - from: <input type="text" id="node-input-minin" placeholder="e.g. 0" style="width:100px;"/> - to: <input type="text" id="node-input-maxin" placeholder="e.g. 99" style="width:100px;"/> - </div> - <div class="form-row"><i class="fa fa-sign-out"></i> to the result range:</div> - <div class="form-row"><label></label> - from: <input type="text" id="node-input-minout" placeholder="e.g. 0" style="width:100px;"/> - to: <input type="text" id="node-input-maxout" placeholder="e.g. 255" style="width:100px;"/> - </div> - <br/> - <div class="form-row"><label></label> - <input type="checkbox" id="node-input-round" style="display: inline-block; width: auto; vertical-align: top;"> - <label style="width: auto;" for="node-input-round">Round result to the nearest integer?</label></input> - </div> - <br/> - <div class="form-row"> - <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> - <input type="text" id="node-input-name" placeholder="Name"> - </div> - <div class="form-tips" id="node-tip">Tip: This node ONLY works with numbers.</div> -</script> - -<script type="text/x-red" data-help-name="range"> - <p>A simple function node to remap numeric input values to another scale.</p> - <p>Currently only does a linear scaling.</p> - <p><b>Note:</b> This only operates on <b>numbers</b>. Anything else will try to be made into a number and rejected if that fails.</p> - <p><i>Scale and limit to target range</i> means that the result will never be outside the range specified within the result range.</p> - <p><i>Scale and wrap within the target range</i> means that the result will essentially be a "modulo-style" wrap-around within the result range.</p> -</script> - -<script type="text/javascript"> - RED.nodes.registerType('range', { - color: "#E2D96E", - category: 'function', - defaults: { - minin: {value:"",required:true,validate:RED.validators.number()}, - maxin: {value:"",required:true,validate:RED.validators.number()}, - minout: {value:"",required:true,validate:RED.validators.number()}, - maxout: {value:"",required:true,validate:RED.validators.number()}, - action: {value:"scale"}, - round: {value:false}, - name: {value:""} - }, - inputs: 1, - outputs: 1, - icon: "range.png", - label: function() { - return this.name || "range"; - }, - labelStyle: function() { - return this.name ? "node_label_italic" : ""; - } - }); -</script> diff --git a/dgbuilder/core_nodes/logic/16-range.js b/dgbuilder/core_nodes/logic/16-range.js deleted file mode 100644 index ec39342a..00000000 --- a/dgbuilder/core_nodes/logic/16-range.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2013 IBM 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. - **/ - -module.exports = function(RED) { - "use strict"; - function RangeNode(n) { - RED.nodes.createNode(this, n); - this.action = n.action; - this.round = n.round || false; - this.minin = Number(n.minin); - this.maxin = Number(n.maxin); - this.minout = Number(n.minout); - this.maxout = Number(n.maxout); - var node = this; - - this.on('input', function (msg) { - var n = Number(msg.payload); - if (!isNaN(n)) { - if (node.action == "clamp") { - if (n < node.minin) { n = node.minin; } - if (n > node.maxin) { n = node.maxin; } - } - if (node.action == "roll") { - if (n >= node.maxin) { n = (n - node.minin) % (node.maxin - node.minin) + node.minin; } - if (n < node.minin) { n = (n - node.minin) % (node.maxin - node.minin) + node.maxin; } - } - msg.payload = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout; - if (node.round) { msg.payload = Math.round(msg.payload); } - node.send(msg); - } - else { node.log("Not a number: "+msg.payload); } - }); - } - RED.nodes.registerType("range", RangeNode); -} |