[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / core_nodes / parsers / 70-CSV.html
1
2 <!--
3   Copyright 2014 IBM Corp.
4
5   Licensed under the Apache License, Version 2.0 (the "License");
6   you may not use this file except in compliance with the License.
7   You may obtain a copy of the License at
8
9   http://www.apache.org/licenses/LICENSE-2.0
10
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an "AS IS" BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16 -->
17
18 <script type="text/x-red" data-template-name="csv">
19     <div class="form-row">
20         <label for="node-input-temp"><i class="fa fa-list"></i> Columns</label>
21         <input type="text" id="node-input-temp" placeholder="comma-separated column names">
22     </div>
23     <div class="form-row">
24         <label for="node-input-select-sep"><i class="fa fa-text-width"></i> Separator</label>
25             <select style="width: 150px" id="node-input-select-sep">
26                 <option value=",">comma</option>
27                 <option value="\t">tab</option>
28                 <option value=" ">space</option>
29                 <option value=";">semicolon</option>
30                 <option value=":">colon</option>
31                 <option value="">other...</option>
32            </select>
33            <input style="width: 40px;" type="text" id="node-input-sep" pattern=".">
34     </div>
35
36     <div class="form-row">
37         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
38         <input type="text" id="node-input-name" placeholder="Name">
39     </div>
40     <hr align="middle"/>
41     <div class="form-row">
42         <label style="width: 100%;"><i class="fa fa-gears"></i> CSV-to-Object options</label>
43         <label style="margin-left: 10px; margin-right: -10px;"><i class="fa fa-sign-in"></i> Input</label>
44         <input style="width: 30px" type="checkbox" id="node-input-hdrin"><label style="width: auto;" for="node-input-hdrin">first row contains column names</span>
45     </div>
46     <div class="form-row">
47         <label style="margin-left: 10px; margin-right: -10px;"><i class="fa fa-sign-out"></i> Output</label>
48         <select type="text" id="node-input-multi" style="width: 250px;">
49             <option value="one">a message per row</option>
50             <option value="mult">a single message [array]</option>
51         </select>
52     </div>
53     <hr align="middle"/>
54     <div class="form-row">
55         <label style="width: 100%;"><i class="fa fa-gears"></i> Object-to-CSV options</label>
56         <label style="margin-left: 10px; margin-right: -10px;"><i class="fa fa-sign-in"></i> Output</label>
57         <input style="width: 30px" type="checkbox" id="node-input-hdrout"><label style="width: auto;" for="node-input-hdrout">include column name row</span>
58     </div>
59     <div class="form-row">
60         <label style="margin-left: 10px; margin-right: -10px;"><i class="fa fa-align-left"></i> Newline</label>
61         <select style="width: 150px" id="node-input-ret">
62             <option value='\n'>Linux (\n)</option>
63             <option value='\r'>Mac (\r)</option>
64             <option value='\r\n'>Windows (\r\n)</option>
65        </select>
66     </div>
67 </script>
68
69 <script type="text/x-red" data-help-name="csv">
70     <p>A function that parses the <b>msg.payload</b> to convert csv to/from a javascript object.
71     Places the result in the payload.</p>
72     <p>If the input is a string it tries to parse it as CSV and creates a javascript object.</p>
73     <p>If the input is a javascript object it tries to build a CSV string.</p>
74     <p>The columns template should contain an ordered list of column headers. For csv input these become the property names.
75     For csv output these specify the properties to extract from the object and the order for the csv.</p>
76     <p><b>Note:</b> the columns should always be specified comma separated - even if another separator is chosen for the data.</p>
77     </script>
78
79 <script type="text/javascript">
80     RED.nodes.registerType('csv',{
81         category: 'function',
82         color:"#DEBD5C",
83         defaults: {
84             name: {value:""},
85             sep: {value:',',required:true,validate:RED.validators.regex(/^.{1,2}$/)},
86             //quo: {value:'"',required:true},
87             hdrin: {value:""},
88             hdrout: {value:""},
89             multi: {value:"one",required:true},
90             ret: {value:'\\n'},
91             temp: {value:""}
92         },
93         inputs:1,
94         outputs:1,
95         icon: "arrow-in.png",
96         label: function() {
97             return this.name||"csv";
98         },
99         labelStyle: function() {
100             return this.name?"node_label_italic":"";
101         },
102         oneditprepare: function() {
103             if (this.sep == "," || this.sep == "\\t" || this.sep == ";" || this.sep == ":" || this.sep == " ") {
104                 $("#node-input-select-sep").val(this.sep);
105                 $("#node-input-sep").hide();
106             } else {
107                 $("#node-input-select-sep").val("");
108                 $("#node-input-sep").val(this.sep);
109                 $("#node-input-sep").show();
110             }
111             $("#node-input-select-sep").change(function() {
112                 var v = $("#node-input-select-sep option:selected").val();
113                 $("#node-input-sep").val(v);
114                 if (v == "") {
115                     $("#node-input-sep").val("");
116                     $("#node-input-sep").show().focus();
117                 } else {
118                     $("#node-input-sep").hide();
119                 }
120             });
121         }
122     });
123 </script>