Skip to content

Commit 671c8c7

Browse files
committed
fix required fields bug and improve error messages when document _id doesn't exist
1 parent 8ec3ae7 commit 671c8c7

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
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
}

0 commit comments

Comments
 (0)