2014-09-12 17:50:01 +02:00
|
|
|
|
2014-04-29 18:01:30 +02:00
|
|
|
<!--
|
2015-10-15 00:38:29 +02:00
|
|
|
Copyright 2014,2015 IBM Corp.
|
2014-04-29 18:01:30 +02:00
|
|
|
|
|
|
|
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="csv">
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-temp"><i class="fa fa-list"></i> <span data-i18n="csv.label.columns"></span></label>
|
2015-05-28 00:07:31 +02:00
|
|
|
<input type="text" id="node-input-temp" data-i18n="[placeholder]csv.placeholder.columns">
|
2014-04-29 18:01:30 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-select-sep"><i class="fa fa-text-width"></i> <span data-i18n="csv.label.separator"></span></label>
|
2014-09-12 17:50:01 +02:00
|
|
|
<select style="width: 150px" id="node-input-select-sep">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value="," data-i18n="csv.separator.comma"></option>
|
|
|
|
<option value="\t" data-i18n="csv.separator.tab"></option>
|
|
|
|
<option value=" " data-i18n="csv.separator.space"></option>
|
|
|
|
<option value=";" data-i18n="csv.separator.semicolon"></option>
|
|
|
|
<option value=":" data-i18n="csv.separator.colon"></option>
|
|
|
|
<option value="#" data-i18n="csv.separator.hashtag"></option>
|
|
|
|
<option value="" data-i18n="csv.separator.other"></option>
|
2014-09-12 17:50:01 +02:00
|
|
|
</select>
|
|
|
|
<input style="width: 40px;" type="text" id="node-input-sep" pattern=".">
|
2014-04-29 18:01:30 +02:00
|
|
|
</div>
|
2014-09-12 17:50:01 +02:00
|
|
|
|
2014-04-29 18:01:30 +02:00
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
2015-05-26 22:11:14 +02:00
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
2014-04-29 18:01:30 +02:00
|
|
|
</div>
|
2014-09-12 17:50:01 +02:00
|
|
|
<hr align="middle"/>
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label style="width: 100%;"><i class="fa fa-gears"></i> <span data-i18n="csv.label.c2o"></span></label>
|
|
|
|
<label style="margin-left: 10px; margin-right: -10px;"><i class="fa fa-sign-in"></i> <span data-i18n="csv.label.input"></span></label>
|
|
|
|
<input style="width: 30px" type="checkbox" id="node-input-hdrin"><label style="width: auto;" for="node-input-hdrin"><span data-i18n="csv.label.firstrow"></span></span>
|
2014-09-12 17:50:01 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label style="margin-left: 10px; margin-right: -10px;"><i class="fa fa-sign-out"></i> <span data-i18n="csv.label.output"></span></label>
|
2014-09-12 17:50:01 +02:00
|
|
|
<select type="text" id="node-input-multi" style="width: 250px;">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value="one" data-i18n="csv.output.row"></option>
|
|
|
|
<option value="mult" data-i18n="csv.output.array"></option>
|
2014-09-12 17:50:01 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<hr align="middle"/>
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label style="width: 100%;"><i class="fa fa-gears"></i> <span data-i18n="csv.label.o2c"></span></label>
|
|
|
|
<label style="margin-left: 10px; margin-right: -10px;"><i class="fa fa-sign-in"></i> <span data-i18n="csv.label.output"></span></label>
|
|
|
|
<input style="width: 30px" type="checkbox" id="node-input-hdrout"><label style="width: auto;" for="node-input-hdrout"><span data-i18n="csv.label.includerow"></span></span>
|
2014-09-12 17:50:01 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label style="margin-left: 10px; margin-right: -10px;"><i class="fa fa-align-left"></i> <span data-i18n="csv.label.newline"></span></label>
|
2014-09-12 17:50:01 +02:00
|
|
|
<select style="width: 150px" id="node-input-ret">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value='\n' data-i18n="csv.newline.linux"></option>
|
|
|
|
<option value='\r' data-i18n="csv.newline.mac"></option>
|
|
|
|
<option value='\r\n' data-i18n="csv.newline.windows"></option>
|
2014-09-12 17:50:01 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
2014-04-29 18:01:30 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="csv">
|
2016-02-12 14:16:28 +01:00
|
|
|
<p>A function that parses the <code>msg.payload</code> to convert CSV to/from a javascript object.
|
2014-09-12 17:50:01 +02:00
|
|
|
Places the result in the payload.</p>
|
2014-04-29 18:01:30 +02:00
|
|
|
<p>If the input is a string it tries to parse it as CSV and creates a javascript object.</p>
|
|
|
|
<p>If the input is a javascript object it tries to build a CSV string.</p>
|
2015-10-15 00:38:29 +02:00
|
|
|
<p>If the input is a simple array the output is just a CSV generated from that array.</p>
|
2016-02-12 14:16:28 +01:00
|
|
|
<p>If the input is an array of arrays, or an array of objects, a multiple-line CSV is created.</p>
|
2015-10-15 00:38:29 +02:00
|
|
|
<p>The columns template should contain an ordered list of column headers. For CSV input these become the property names.
|
|
|
|
For CSV output these specify the properties to extract from the object and the order for the CSV.</p>
|
|
|
|
<p>If the input is an array then the columns template does not matter, but can be used to generate a row of column titles.</p>
|
2014-04-29 18:01:30 +02:00
|
|
|
<p><b>Note:</b> the columns should always be specified comma separated - even if another separator is chosen for the data.</p>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('csv',{
|
|
|
|
category: 'function',
|
|
|
|
color:"#DEBD5C",
|
|
|
|
defaults: {
|
|
|
|
name: {value:""},
|
2014-09-12 17:50:01 +02:00
|
|
|
sep: {value:',',required:true,validate:RED.validators.regex(/^.{1,2}$/)},
|
2014-04-29 18:01:30 +02:00
|
|
|
//quo: {value:'"',required:true},
|
2014-09-12 17:50:01 +02:00
|
|
|
hdrin: {value:""},
|
|
|
|
hdrout: {value:""},
|
|
|
|
multi: {value:"one",required:true},
|
|
|
|
ret: {value:'\\n'},
|
|
|
|
temp: {value:""}
|
2014-04-29 18:01:30 +02:00
|
|
|
},
|
|
|
|
inputs:1,
|
|
|
|
outputs:1,
|
2016-06-12 23:37:38 +02:00
|
|
|
icon: "parser-csv.png",
|
2014-04-29 18:01:30 +02:00
|
|
|
label: function() {
|
|
|
|
return this.name||"csv";
|
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
2014-09-12 17:50:01 +02:00
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
2015-01-09 21:32:05 +01:00
|
|
|
if (this.sep == "," || this.sep == "\\t" || this.sep == ";" || this.sep == ":" || this.sep == " " || this.sep == "#") {
|
2014-09-12 17:50:01 +02:00
|
|
|
$("#node-input-select-sep").val(this.sep);
|
|
|
|
$("#node-input-sep").hide();
|
|
|
|
} else {
|
|
|
|
$("#node-input-select-sep").val("");
|
|
|
|
$("#node-input-sep").val(this.sep);
|
|
|
|
$("#node-input-sep").show();
|
|
|
|
}
|
|
|
|
$("#node-input-select-sep").change(function() {
|
|
|
|
var v = $("#node-input-select-sep option:selected").val();
|
|
|
|
$("#node-input-sep").val(v);
|
|
|
|
if (v == "") {
|
|
|
|
$("#node-input-sep").val("");
|
|
|
|
$("#node-input-sep").show().focus();
|
|
|
|
} else {
|
|
|
|
$("#node-input-sep").hide();
|
|
|
|
}
|
|
|
|
});
|
2014-04-29 18:01:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|