Skip to content

Commit 8316ae8

Browse files
committed
Merge branch 'develop'
* develop: bump version and add authors fix required fields bug and improve error messages when document _id doesn't exist
2 parents ba0ac80 + 41aba1a commit 8316ae8

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

77-cloudant-cf.html

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,6 @@
175175
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
176176
<input type="text" id="node-input-name" placeholder="Name">
177177
</div>
178-
179-
<script>
180-
$("#node-input-search").change(function() {
181-
var searchType = $("#node-input-search option:selected").val();
182-
if (searchType == "_id_") $("#node-search-index-form").hide();
183-
else $("#node-search-index-form").show();
184-
});
185-
</script>
186178
</script>
187179

188180
<script type="text/javascript">
@@ -217,8 +209,8 @@
217209
name : { value: "" },
218210
database: { value: "", required: true },
219211
search : { value: "_id_", required: true },
220-
design : { value: "", required: true },
221-
index : { value: "", required: true }
212+
design : { value: "" },
213+
index : { value: "" }
222214
},
223215
inputs : 1,
224216
outputs: 1,
@@ -231,11 +223,14 @@
231223
});
232224

233225
function oneditprepare() {
234-
var select = $('#node-input-service');
235226
var node = this;
236227

228+
var serviceSelect = $('#node-input-service');
229+
var searchBySelect = $('#node-input-search');
230+
var searchForm = $('#node-search-index-form');
231+
237232
$.getJSON('cloudant/vcap/',function(data) {
238-
var last = select.children().last();
233+
var last = serviceSelect.children().last();
239234
var opts = [];
240235

241236
for (var i=0; i < data.length; i++) {
@@ -249,24 +244,38 @@
249244

250245
if (opts.length == 0) {
251246
node.service = "_ext_";
252-
select.find("option").filter(function() {
247+
serviceSelect.find("option").filter(function() {
253248
return $(this).val() == node.service;
254249
}).attr('selected', true);
255250
} else {
256251
last.before(opts.join(""));
257252
}
258253

259-
select.change();
254+
serviceSelect.change();
260255
});
261256

262-
select.change(function() {
263-
var service = select.val();
257+
serviceSelect.change(function() {
258+
var service = serviceSelect.val();
264259
if (service == "_ext_") {
265260
$("#node-input-external-details").show();
266261
} else {
267262
$("#node-input-external-details").hide();
268263
}
269264
});
265+
266+
searchBySelect.change(function() {
267+
var searchBy = searchBySelect.val();
268+
269+
if (searchBy === "_idx_") {
270+
node._def.defaults.design.required = true;
271+
node._def.defaults.index.required = true;
272+
searchForm.show();
273+
} else {
274+
node._def.defaults.design.required = false;
275+
node._def.defaults.index.required = false;
276+
searchForm.hide();
277+
}
278+
});
270279
}
271280

272281
function label() {

77-cloudant-cf.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,13 @@ module.exports = function(RED) {
212212
function CloudantInNode(n) {
213213
RED.nodes.createNode(this,n);
214214

215-
this.cloudant = n.cloudant;
216-
this.url = _getUrl(this, n);
217-
this.database = n.database;
218-
this.search = n.search;
219-
this.design = n.design;
220-
this.index = n.index;
215+
this.cloudant = n.cloudant;
216+
this.url = _getUrl(this, n);
217+
this.database = n.database;
218+
this.search = n.search;
219+
this.design = n.design;
220+
this.index = n.index;
221+
this.payloadIn = "";
221222

222223
if (this.url) {
223224
var node = this;
@@ -226,6 +227,8 @@ module.exports = function(RED) {
226227
var db = nano.use(node.database);
227228

228229
node.on("input", function(msg) {
230+
node.payloadIn = msg.payload;
231+
229232
if (node.search === "_id_") {
230233
var id = msg.payload;
231234
db.get(id, sendDocumentOnPayload);
@@ -241,7 +244,12 @@ module.exports = function(RED) {
241244
if (!err) {
242245
node.send({ payload: body });
243246
} else {
244-
node.error(err);
247+
if (err.description === "missing") {
248+
node.warn("Document '" + node.payloadIn+ "' not found in database '" +
249+
node.database + "'.");
250+
} else {
251+
node.error(err.reason);
252+
}
245253
}
246254
}
247255
}

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ from the database. For both cases, the query should be passed in the
3030

3131
When getting documents by id, the `payload` will be the desired `_id` value.
3232
For `search indexes`, the query should follow the format `indexName:value`.
33+
34+
Authors
35+
-------
36+
* Luiz Gustavo Ferraz Aoqui - [[email protected]](mailto:[email protected])
37+
* Túlio Pascoal

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "node-red-node-cf-cloudant",
3-
"version" : "0.2.1",
3+
"version" : "0.2.2",
44
"description" : "A Node-RED node to write to a Cloudant database on Bluemix",
55
"dependencies" : {
66
"nano" : "5.10.0"

0 commit comments

Comments
 (0)