forked from nkolban/node-red-contrib-couchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcouchdb.html
178 lines (168 loc) · 5.29 KB
/
couchdb.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
<!--
Copyright 2015 Neil Kolban.
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/javascript">
RED.nodes.registerType('couchdb',{
// node definition
category: "storage",
inputs: 1,
outputs: 1,
icon: "couchdb.png",
color: "#73c5e7",
label: function () {
return this.name || "couchdb"
},
paletteLabel: "couchdb",
defaults: {
name: {
value: ""
},
serverUrl: {
value: "",
required: true
},
database: {
value: "",
required: true
},
retrievalType: {
value: "byId"
},
designDoc: {
value: null
},
viewName: {
value: null
}
}
});
RED.nodes.registerType('couchdbinsert',{
// node definition
category: "storage",
inputs: 1,
outputs: 0,
icon: "couchdb.png",
color: "#73c5e7",
label: function () {
return this.name || "couchdb insert"
},
paletteLabel: "couchdb insert",
align: "right",
defaults: {
name: {
value: ""
},
serverUrl: {
value: "",
required: true
},
database: {
value: "",
required: true
}
}
});
</script>
<script type="text/x-red" data-help-name="couchdb">
<p>A node for searching documents in a CouchDB database.</p>
<p>Searching for documents can be done in a few modes. Directly by using the documents
<b>_id</b> or by using a key lookup in a view.</p>
<p>When querying using the <b>by Id</b> option, the value for the documents <code>_id</code>
should be passed in the <code>msg.payload</code> as a string.</p>
<p>When querying using <b>by view</b> option, the value for the search key should
be passed in the <code>msg.payload</code>.</p>
<p>The database name must follow these rules:
<ul>
<li>No spaces</li>
<li>All letters in lower case</li>
<li>The first character must not be <code>_</code></li>
</ul>
</p>
</script>
<script type="text/x-red" data-help-name="couchdbinsert">
<p>A node for inserting documents in a CouchDB database.</p>
<p>The document to be insert will be the JavaScript object found in <code>msg.payload</code>.
To update an existing document, a valid <code>_rev</code> must also be present in the object.
Before you use this node, make sure you understand the principles of working with CouchDB.</p>
<p>The database name must follow these rules:
<ul>
<li>No spaces</li>
<li>All letters in lower case</li>
<li>The first character must not be <code>_</code></li>
</ul>
</p>
</script>
<!--
*
* couchdb
*
-->
<script type="text/x-red" data-template-name="couchdb">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-serverUrl"><i class="fa fa-server"></i> Server URL</label>
<input type="text" id="node-input-serverUrl" placeholder="Server URL">
</div>
<div class="form-row">
<label for="node-input-database"><i class="fa fa-database"></i> Database</label>
<input type="text" id="node-input-database" placeholder="Database">
</div>
<div class="form-row">
<label for="node-input-retrievalType"><i class="fa fa-random"></i> Type</label>
<select type="text" id="node-input-retrievalType">
<option value="byId">... by Id</option>
<option value="byView">... by View</option>
</select>
</div>
<div class="form-row node-input-designDoc">
<label for="node-input-designDoc"><i class="fa fa-book"></i> Design doc</label>
<input type="text" id="node-input-designDoc" placeholder="Design doc">
</div>
<div class="form-row node-input-viewName">
<label for="node-input-viewName"><i class="fa fa-binoculars"></i> View name</label>
<input type="text" id="node-input-viewName" placeholder="View name">
</div>
<script>
$("#node-input-retrievalType").change(function() {
var type = $("#node-input-retrievalType").val();
if (type == "byView") {
$(".node-input-designDoc").show();
$(".node-input-viewName").show();
} else {
$(".node-input-designDoc").hide();
$(".node-input-viewName").hide();
}
});
</script>
</script>
<!--
*
* couchdbinsert
*
-->
<script type="text/x-red" data-template-name="couchdbinsert">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-serverUrl"><i class="fa fa-server"></i> Server URL</label>
<input type="text" id="node-input-serverUrl" placeholder="Server URL">
</div>
<div class="form-row">
<label for="node-input-database"><i class="fa fa-database"></i> Database</label>
<input type="text" id="node-input-database" placeholder="Database">
</div>
</script>