forked from Belphemur/json-db-node-red
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjson-db.html
185 lines (162 loc) · 7.47 KB
/
json-db.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!--
Copyright 2014 Antoine Aflalo
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="DataIn">
<div class="form-row" id="node-input-server-row">
<label for="node-input-collection"><i class="icon-tasks"></i> Collection</label>
<input type="text" id="node-input-collection">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-flag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="icon-floppy-save"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="">
</div>
<div class="form-row">
<input type="checkbox" style="display: inline-block; width: auto; vertical-align: top;" id="node-input-update" />
<label style="width: auto;" for="node-input-update"><i class="icon-log-in"></i>Merge Data</label>
</div>
<div class="form-tips">By default, the node will override the old data with the new one. If you check "Merge Data", it will merge the new one with the old one and save it.</div>
</script>
<script type="text/x-red" data-template-name="DataOut">
<div class="form-row" id="node-input-server-row">
<label for="node-input-collection"><i class="icon-tasks"></i> Collection</label>
<input type="text" id="node-input-collection">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-flag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Node-RED">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="icon-floppy-save"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="">
</div>
<div class="form-row">
<input type="checkbox" style="display: inline-block; width: auto; vertical-align: top;" id="node-input-error" />
<label style="width: auto;" for="node-input-error"><i class="icon-log-in"></i>Always send the message</label>
</div>
<div class="form-tips">When the DataPath doesn't exists, the Node will trigger an error and will stop the flow unless you checked "Always send the message".
The message sent will contain a <code>msg.error</code> with the error.</div>
</script>
<script type="text/x-red" data-help-name="DataIn">
<p>Use DataIn to <b>store</b> data into the Json-DB.</p>
<p>The DataIn node is used to store information into the chosen collection.
You select which collection you want to use and the path to the object.</p>
<p>If you chose to merge the data, the node will automatically merge Arrays with others Arrays and Objects with others Objects. You can't merge Array with Object and vice versa</p>
<p>The path can be overridden with the <code>msg.datapath</code>.</p>
<p><code>The msg.payload</code> will contain the data you want to store.</p>
<p>The DataPath represent the path through the object. If the DataPath doesn't exists in the hierachy of the database, it will be created.</p>
<code>
{
test:
{
data: "First"
},
test2 : "Second"
}
</code>
<p>To change the "First" you have to set as Data Path : <code>/test/data</code></p>
<p>To change "Second" : <code>/test2</code></p>
<p>You can also get the whole data by just setting <code>/</code> as DataPath</p>
</script>
<script type="text/x-red" data-help-name="DataOut">
<p>Use DataOut to <b>retrieve</b> data from the Json-DB.</p>
<p>The DataOut node is used to retrieve information into the chosen collection.
You select which collection you want to use and the path to the object.</p>
<p>The path can be overridden with the <code>msg.datapath</code>.</p>
<p><code>The msg.payload</code> will contain the data retrieved from the Json-DB.</p>
<p>In case of error and if you check "Always send the message", the <code>msg.error</code> will contain the error that has been triggered.
The rest of the properties of the msg will stay unchanged. If you activated the <i>Status</i> in the configuration panel of Node-RED, you'll
be able to see directly the last Error message on top of the node.</p>
<p>The DataPath represent the path through the object. If the DataPath doesn't exists, an <b>Error</b> will be thrown.</p>
<code>
{
test:
{
data: "First"
},
test2 : "Second"
}
</code>
<p>To change the "First" you have to set as Data Path : <code>/test/data</code></p>
<p>To change "Second" : <code>/test2</code></p>
<p>You can also get the whole data by just setting <code>/</code> as DataPath</p>
</script>
<script type="text/x-red" data-template-name="json-db-collection">
<div class="form-row">
<label for="node-config-input-name"><i class="icon-flag"></i>Name</label>
<input type="text" id="node-config-input-name" >
</div>
<div class="form-row">
<label for="node-config-input-collection"><i class="icon-cloud"></i>Collection</label>
<input type="text" id="node-config-input-collection" placeholder="myDatas" >
</div>
<div class="form-row">
<input type="checkbox" style="display: inline-block; width: auto; vertical-align: top;" id="node-config-input-save" />
<label style="width: auto;" for="node-config-input-save"><i class="icon-log-in"></i>Direct save on file</label>
</div>
<div class="form-tips">By default, the node will save the collection on the file after you push new data. The collection can't contain any whitespace.</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('json-db-collection', {
category: 'config',
defaults: {
name: {value: ""},
collection: {required: true, validate: RED.validators.regex(/^[a-zA-Z0-9-_]+$/)},
save: {value: true, required: true}
},
label: function () {
return this.name || this.collection;
}
});
RED.nodes.registerType('DataIn', {
category: 'storage-input',
defaults: {
collection: {type: "json-db-collection", required: true},
name: {value: ""},
update: {value: false, required: true},
topic: {value: '' }
},
color: "#6699FF",
inputs: 1,
outputs: 0,
icon: "json-db-in.png",
align: "right",
label: function () {
return this.name || this.topic;
},
labelStyle: function () {
return this.name ? "node_label_italic" : "";
}
});
RED.nodes.registerType('DataOut', {
category: 'storage-output',
defaults: {
collection: {type: "json-db-collection", required: true},
name: {value: ""},
topic: {value: ""},
error: {value: false, required: true}
},
color: "#6699FF",
inputs: 1,
outputs: 1,
icon: "json-db-out.png",
label: function () {
return this.name || this.topic;
},
labelStyle: function () {
return this.name ? "node_label_italic" : "";
}
});
</script>