UNPKG

prisme-flow

Version:

prisme platform flow engine

104 lines (98 loc) 4.81 kB
<!-- Created by prisme.io on 09/06/2017. @author <a href="mailto:hello@prisme.io">savane vamara</a> (prisme.io) --> <script type="text/x-red" data-template-name="data-generator"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Data Generator</label> <input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name"> </div> <div class="form-row"> <label for="node-input-field"><i class="fa fa-edit"></i> Payload </label> <input type="text" id="node-input-field" placeholder="payload" style="width:275px;"> <input type="hidden" id="node-input-fieldType"> </div> <div class="form-row" style="position: relative; margin-bottom: 0px;"> <label for="node-input-template"><i class="fa fa-file-code-o"></i>Template</span></label> <input type="hidden" id="node-input-template" autofocus="autofocus"> </div> <div class="form-row node-text-editor-row"> <div style="height:250px;" class="node-text-editor" id="node-input-template-editor"></div> </div> <div class="form-row"> <label for="node-input-syntax"><i class="fa fa-code"></i> <span data-i18n="datagen.label.syntax"></span></label> <select id="node-input-syntax" style="width:180px;"> <option value="text" data-i18n="datagen.label.text"></option> <option value="json" data-i18n="datagen.label.json"></option> </select> </div> </script> <script type="text/x-red" data-help-name="data-generator"> <p>Creates dummy data strings based on a handlebars-style template.</p> module, which can create rich sets of dummy data for testing or other uses.</p> <p>Will build a string or a parsed JSON object, creating values based on the helper names below: <pre style="word-break:normal">title, firstname, lastname, company, domain, tld, email, street, city, country, countryCode, zipcode, postcode, lat, long, phone, color, hexColor, guid, ipv4, ipv6, lorem, date, time, lowercase, uppercase, int, float, boolean</pre> <p>Multiple values can be generated by use of the <i>repeat</i> syntax.</p> <p>In addition any properties passed in on <code>msg</code> can also be used - for example {{payload}}.</p> <p>Finally <code>msg.seed</code> can be used to preset the pseudo-random seed to ensure repeatability across calls.</p> </script> <script type="text/javascript"> RED.nodes.registerType('data-generator',{ color:"rgb(243, 181, 103)", category: 'utility', paletteLabel:"data&nbsp;generator", defaults: { name: {value:""}, field: {value:"payload"}, fieldType: {value:"msg"}, syntax: {value:"text"}, template: {value:"{\n \"name\": \"{{firstName}} {{lastName}}\",\n \"work\": \"{{company}}\",\n \"email\": \"{{email}}\",\n \"address\": \"{{int 1 100}} {{street}}\",\n \"country\": \"{{country}}\"\n}"} }, inputs:1, outputs:1, icon: "data-generator.png", label: function() { return this.name || "data generator"; }, oneditprepare: function() { var that = this; if (!this.fieldType) { this.fieldType = 'msg'; } $("#node-input-field").typedInput({ default: 'msg', types: ['msg','flow','global'], typeField: $("#node-input-fieldType") }); this.editor = RED.editor.createEditor({ id: 'node-input-template-editor', mode: 'ace/mode/handlebars', value: $("#node-input-template").val() }); RED.library.create({ url:"functions", // where to get the data from type:"function", // the type of object the library is for editor:that.editor, // the field name the main text body goes to fields:['name','outputs'] }); this.editor.focus(); }, oneditsave: function() { $("#node-input-template").val(this.editor.getValue()) delete this.editor; }, oneditresize: function(size) { var rows = $("#dialog-form>div:not(.node-text-editor-row)"); var height = $("#dialog-form").height(); for (var i=0;i<rows.size();i++) { height -= $(rows[i]).outerHeight(true); } var editorRow = $("#dialog-form>div.node-text-editor-row"); height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom"))); $(".node-text-editor").css("height",height+"px"); this.editor.resize(); } }); </script>