UNPKG

node-red-bluemix-nodes

Version:

A collection of extra Node-RED nodes for IBM Bluemix.

178 lines (146 loc) 8.08 kB
<!-- Copyright 2016 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="business-rules"> <div class="form-row"> <label for="node-input-service"><i class="fa fa-hand-o-right"></i> Bluemix Service</label> <select type="text" id="node-input-service" style="display: inline-block; vertical-align:middle; width: 72%;"> <option value="">Select a Business Rules service instance</option> </select> </div> <div class="form-row"> <label for="node-input-rulesets"><i class="fa fa-hand-o-right"></i> Decision Services </label> <select type="text" id="node-input-rulesets" style="display: inline-block; vertical-align:middle; width: 72%;"> </select> </div> <div class="form-row"> <label for="node-input-ruleset"><i class="fa fa-save"></i> Current </label> <input type="text" id="node-input-ruleset" placeholder="Ruleset Path" readonly style="display: inline-block; vertical-align:middle; width: 72%;"/> </div> <div class="form-row"> <label for="node-input-test-test-mode"><i class="fa fa-cog"></i> Test </label> <select type="text" id="node-input-test-mode" style="display: inline-block; vertical-align:middle; width: 59%;"> <option value="false">Current Decision Service with trace disabled</option> <option value="true">Current Decision Service with trace enabled</option> </select> <a id="node-input-htds-test-btn" class="btn" href="#" onclick="javascript:TestDecisionService();return false;"> <i class="fa fa-external-link"></i> Run</a> </div> <div class="form-tips" id="node-missing-service-warning" style="display: none"><i class="fa fa-warning"></i><b> Warning:</b> There is no Business Rules service connected </div> <div class="form-tips" id="node-node-info"><i class="fa fa-book"></i><b> Tips:</b> Check out the node info tab for more information </div> </script> <script type="text/x-red" data-help-name="business-rules"> <p>Enables developers to spend less time recoding and testing when the business policy changes.</p> <p>The Business Rules service minimizes your code changes by keeping business logic separate from application logic.</p> <p><b>Node Configuration</b></p> <ul> <li> Create and Bind a Business Rules service instance on this Node-RED App</li> <li> Deploy some Decisions Services</li> <li> Select the Decision Service to be executed and click on Done</li> <li> In input, wire your Business Rules node with a valid Json or Xml payload (use the test tool to help you)</li> <li> In output, wire your Business Rules node with the node that will use the response of Decision Service execution request done by this node</li> </ul> <p><b>Node input</b></p> <ul> <li><code>msg.payload</code> : a string representing a valid XML or JSON payload matching the selected Decision Service in the node configuration.</li> </ul> <p><b>Node output</b></p> <ul> <li><code>msg.payload</code> : the decision corresponding the input data, returned either in XML or JSON as detected in the input.</li> </ul> <p><b>Documentations</b></p> <ul> <li><a href="https://github.com/ylecleach/labs/tree/master/node-red/basic-labs/business-rules" target="_blank">Business Rules Node Tutorials</a></li> <li><a href="https://console.ng.bluemix.net/docs/services/rules/rules.html#rules" target="_blank">Business Rules Service documentation</a></li> <li><a href="http://www.ibm.com/developerworks/topics/business%20rules%20service" target="_blank">All Business Rules service tutorials</a></li> <li><a href="http://www.ibm.com/developerworks/bpm/library/techarticles/1504_reinholds-bluemix/1504_reinholds.html" target="_blank">Top 10 Bluemix tutorials for BPM</a></li> </ul> </script> <script type="text/javascript"> function TestDecisionService () { var traceMode = null, serviceSelect = null, rulesetSelect = null, serviceSelectedVal = null, rulesetSelectedVal = null req_string = null, fullURL = null; traceMode = $('#node-input-test-mode').val(); serviceSelect = $('#node-input-service'); rulesetSelect = $('#node-input-ruleset'); serviceSelectedVal = serviceSelect.val(); rulesetSelectedVal = rulesetSelect.val(); req_string = 'business-rules/get-htds-test-uri/' + encodeURIComponent(serviceSelectedVal)+ '/'+ encodeURIComponent(rulesetSelectedVal) ; $.getJSON(req_string, function(data) { fullURL = 'https://' + data.username + ':' + data.password + '@' + data.url.host + '/DecisionService/run.jsp?path=' +rulesetSelectedVal+'&trace='+(traceMode === "true" ? true : false); window.open(fullURL); }); } (function() { function updateRulesetList(node) { var serviceSelect = $('#node-input-service'); var rulesetsSelect = $('#node-input-rulesets'); rulesetsSelect.empty(); $.getJSON('business-rules/service/' + serviceSelect.val() + '/rulesets', function(rulesets) { $.each(rulesets, function(index, ruleset) { var option = "<option value=\"" + ruleset + "\">"+ ruleset + "</option>"; rulesetsSelect.append(option); }); rulesetsSelect.find("option").filter(function() {return $(this).val() === node.rulesets;}).attr('selected', true); }); } function oneditprepare() { var node = this; $.getJSON('business-rules/vcap/', function(services) { if (services.length == 0) { $("#node-missing-service-warning").show(); } else { // Assume service[0] var select = $('#node-input-service'); var rulesetsSelect = $('#node-input-rulesets'); for (var i = 0; i < services.length; ++i) { var name = services[i]; var option = "<option value=\"" + name + "\">"+ name + "</option>"; select.append(option); } select.find("option").filter(function() {return $(this).val() === node.service;}).attr('selected', true); // update list of ruleset for the selected service when the service changes $('#node-input-service').change(function() { updateRulesetList(node); }); updateRulesetList(node); // update the text value when rulesets are selected rulesetsSelect.change(function() { $("#node-input-ruleset").val($(this).val()); }); } }); } RED.nodes.registerType('business-rules',{ category: 'Smarter Process', defaults: { service: {value: ""}, rulesets: {value: ""}, ruleset: {value: ""} }, color: "rgb(255, 255, 255)", inputs: 1, outputs: 1, icon: "businessrules-icon25x25.png", paletteLabel: "business rules", label: function() { return this.name || "business rules"; }, labelStyle: function() { return this.name ? "node_label_italic" : ""; }, oneditprepare: oneditprepare }); })(); </script>