2016-03-16 17:37:23 +01:00
|
|
|
|
|
|
|
<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> <span data-i18n="node-red:common.label.name"></span></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> <span data-i18n="node-red:template.label.property"></span></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> <span data-i18n="node-red:template.label.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>
|
2019-09-20 22:22:14 +02:00
|
|
|
<p>Uses the <i><a href="https://github.com/webroo/dummy-json/blob/master/README.md" target="_new">dummy-json</a></i>
|
2016-03-16 17:37:23 +01:00
|
|
|
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:
|
2019-03-06 18:44:06 +01:00
|
|
|
<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 [nn], date, time, lowercase, uppercase, int, float, boolean</pre>
|
2016-03-16 17:37:23 +01:00
|
|
|
<p>Multiple values can be generated by use of the <i>repeat</i> syntax.</p>
|
2019-09-20 22:22:14 +02:00
|
|
|
<p>In addition any properties passed in on <code>msg</code> can also be used - for example <code>{{payload}}</code>.</p>
|
2016-03-16 17:37:23 +01:00
|
|
|
<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: 'function',
|
|
|
|
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: "template.png",
|
2018-04-14 23:43:14 +02:00
|
|
|
paletteLabel: function() {
|
|
|
|
return this._("datagen.datagen");
|
|
|
|
},
|
2016-03-16 17:37:23 +01:00
|
|
|
label: function() {
|
|
|
|
return this.name || "data generator";
|
|
|
|
},
|
2019-09-20 22:22:14 +02:00
|
|
|
outputLabels: function() { return this.syntax === "json" ? "object" : "string"; },
|
2016-03-16 17:37:23 +01:00
|
|
|
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() {
|
2017-06-24 13:17:18 +02:00
|
|
|
$("#node-input-template").val(this.editor.getValue());
|
|
|
|
this.editor.destroy();
|
|
|
|
delete this.editor;
|
|
|
|
},
|
|
|
|
oneditcancel: function() {
|
|
|
|
this.editor.destroy();
|
2016-03-16 17:37:23 +01:00
|
|
|
delete this.editor;
|
|
|
|
},
|
|
|
|
oneditresize: function(size) {
|
|
|
|
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
|
|
|
|
var height = $("#dialog-form").height();
|
2017-06-24 13:17:18 +02:00
|
|
|
for (var i=0; i<rows.size(); i++) {
|
2016-03-16 17:37:23 +01:00
|
|
|
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>
|