mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
113 lines
5.4 KiB
HTML
113 lines
5.4 KiB
HTML
<!--
|
|
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="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>
|
|
<p>Uses the <i><a href="https://github.com/webroo/dummy-json" target="_new">dummy-json</a></i>
|
|
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: 'function',
|
|
paletteLabel:"data 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: "template.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>
|