Skip to content

Commit

Permalink
Merge branch '1.5.0' into 'release'
Browse files Browse the repository at this point in the history
1.5.0

See merge request !12
  • Loading branch information
vamsee committed Jul 20, 2018
2 parents ba4535e + 3c3f50e commit 568c21b
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 97 deletions.
19 changes: 18 additions & 1 deletion create-data/create-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
value : "create data"
},
modelname : {
value : ""
value : "",required:true,validate: RED.validators.regex(/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/)
},
data : {
value : ""
Expand All @@ -23,6 +23,23 @@
icon : "oeCloudLogo.svg",
label : function() {
return this.name || "create data";
},
oneditprepare : function() {
$("#node-input-modelname").click(function() {
console.log(RED);
$("#node-input-modelname").addClass('disabled');
$.getJSON('http://localhost:' + RED.settings.editorTheme.projects.appPort + '/api/ModelDefinitions?filter[order]=clientModelName',function(data) {
$("#node-input-modelname").removeClass('disabled');
var modelNames = data.map(function(m) {return m.clientModelName});
$("#node-input-modelname").autocomplete({
source:modelNames,
minLength:0,
close: function( event, ui ) {
$("#node-input-modelname").autocomplete( "destroy" );
}
}).autocomplete("search","");
});
});
}
});
</script>
Expand Down
45 changes: 34 additions & 11 deletions create-data/create-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,49 @@ module.exports = function (RED) {
function CreateDataNode(config) {
RED.nodes.createNode(this, config);
var node = this;
var _node = this;
var _node = this;
node.status({});
var modelName = config.modelname;
var Model = loopback.findModel(modelName, _node.callContext);
if (!Model) {
node.status({
"fill": "red",
"shape": "dot",
"text": !modelName || (modelName && modelName.trim().length === 0) ? "ModelName not Set" : "Invalid ModelName: " + modelName
});
return;
}

this.on('input', function (msg) {
node.status({});
var modelName = config.modelname;
var dataStr = config.data;
if(!modelName || modelName.trim()==='') {
node.status({fill:"red",shape:"dot",text:"ModelName not Set"});
return this.warn(RED._("createData.errors.modelNameNotSet"));
}
var dataStr = (config.data === undefined || config.data === null || config.data.trim() === "") ? msg.payload : config.data;
var data = (typeof dataStr === "string") ? JSON.parse(dataStr) : dataStr;
var data;
try {
data = (typeof dataStr === "string") ? JSON.parse(dataStr) : dataStr;
} catch(e) {
node.status({
"fill": "red",
"shape": "dot",
"text": e.message ? e.message : "Error while parsing " + dataStr
});
return;
}
var Model = loopback.findModel(modelName, node.callContext);

if (Model) {
node.status({});
Model.upsert(data, msg.callContext, function (err, response) {
if (err) {
node.status({
"fill": "red",
"shape": "dot",
"text": "An error occurred"
"text": err.name? err.name : "An error occurred while inserting. See error output"
});
msg.payload = err;
node.send([null, msg]);
Expand All @@ -46,13 +74,8 @@ module.exports = function (RED) {
}
});
} else {
node.status({
"fill": "red",
"shape": "dot",
"text": "Model " + modelName + " not found"
});
msg.payload = new Error("Model " + modelName + " not found");
node.send([null, msg]);
node.status({fill:"red",shape:"dot",text:"Invalid ModelName: " + modelName});
return this.error(RED._("createData.errors.modelNameInvalid"));
}

});
Expand All @@ -65,7 +88,7 @@ module.exports = function (RED) {
node.status({
"fill": "red",
"shape": "dot",
"text": "ERROR: Model with name " + modelName + " does not exist"
"text": "Invalid ModelName: " + modelName
});
}
});
Expand Down
19 changes: 18 additions & 1 deletion destroy-data/destroy-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,31 @@
value : "destroy data"
},
modelname : {
value : ""
value : "",required:true,validate: RED.validators.regex(/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/)
}
},
inputs : 1,
outputs : 2,
icon : "oeCloudLogo.svg",
label : function() {
return this.name || "destroy data";
},
oneditprepare : function() {
$("#node-input-modelname").click(function() {
console.log(RED);
$("#node-input-modelname").addClass('disabled');
$.getJSON('http://localhost:' + RED.settings.editorTheme.projects.appPort + '/api/ModelDefinitions?filter[order]=clientModelName',function(data) {
$("#node-input-modelname").removeClass('disabled');
var modelNames = data.map(function(m) {return m.clientModelName});
$("#node-input-modelname").autocomplete({
source:modelNames,
minLength:0,
close: function( event, ui ) {
$("#node-input-modelname").autocomplete( "destroy" );
}
}).autocomplete("search","");
});
});
}
});
</script>
Expand Down
39 changes: 28 additions & 11 deletions destroy-data/destroy-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@ module.exports = function(RED) {
RED.nodes.createNode(this, config);
var node = this;
var _node = this;

node.status({});
var modelName = config.modelname;
var Model = loopback.findModel(modelName, _node.callContext);
if (!Model) {
node.status({
"fill": "red",
"shape": "dot",
"text": !modelName || (modelName && modelName.trim().length === 0) ? "ModelName not Set" : "Invalid ModelName: " + modelName
});
return;
}

this.on('input', function(msg) {
node.status({});
var modelName = config.modelname;

if(!modelName || modelName.trim()==='') {
node.status({fill:"red",shape:"dot",text:"ModelName not Set"});
return this.warn(RED._("destroyData.errors.modelNameNotSet"));
}
var Model = loopback.findModel(modelName, node.callContext);

if(Model)
Expand All @@ -36,23 +52,24 @@ module.exports = function(RED) {


});
} else {
node.status({fill:"red",shape:"dot",text:"Invalid ModelName: " + modelName});
return this.error(RED._("destroyData.errors.modelNameInvalid"));
}
else
{
node.status({"fill": "red", "shape": "dot", "text":"Model " + modelName + " not found" });
node.send([null, {payload: new Error("Model " + modelName + " not found")}]);
}

});

node.on('close', function() {
node.on('close', function () {
node.status({});
var modelName = config.modelname;
var Model = loopback.findModel(modelName, _node.callContext);
if(!Model)
{
node.status({"fill": "red", "shape": "dot", "text": "ERROR: Model with name " + modelName + " does not exist"});
}
if (!Model) {
node.status({
"fill": "red",
"shape": "dot",
"text": "Invalid ModelName: " + modelName
});
}
});
}
RED.nodes.registerType("destroy-data", DestroyDataNode);
Expand Down
17 changes: 17 additions & 0 deletions find-data/find-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@
icon : "oeCloudLogo.svg",
label : function() {
return this.name || "find data";
},
oneditprepare : function() {
$("#node-input-modelname").click(function() {
console.log(RED);
$("#node-input-modelname").addClass('disabled');
$.getJSON('http://localhost:' + RED.settings.editorTheme.projects.appPort + '/api/ModelDefinitions?filter[order]=clientModelName',function(data) {
$("#node-input-modelname").removeClass('disabled');
var modelNames = data.map(function(m) {return m.clientModelName});
$("#node-input-modelname").autocomplete({
source:modelNames,
minLength:0,
close: function( event, ui ) {
$("#node-input-modelname").autocomplete( "destroy" );
}
}).autocomplete("search","");
});
});
}
});
</script>
Expand Down
115 changes: 62 additions & 53 deletions find-data/find-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,77 +9,86 @@ var _ = require('lodash');

module.exports = function (RED) {


function FindDataNode(config) {
RED.nodes.createNode(this, config);
var node = this;
var _node = this;
node.status({});
var modelName = config.modelname;
if(modelName && modelName.trim().length > 0) {
var Model = loopback.findModel(modelName, _node.callContext);
if (!Model) {
node.status({
"fill": "red",
"shape": "dot",
"text": "Invalid ModelName: " + modelName
});
return;
}
}

this.on('input', function (msg) {
var filter;
node.status({});
var modelName = config.modelname || msg.modelName;
if (config.filter && typeof config.filter === 'string') filter = JSON.parse(config.filter);
try {
if (config.filter && typeof config.filter === 'string') filter = JSON.parse(config.filter);
} catch(e) {
node.status({
"fill": "red",
"shape": "dot",
"text": e.message ? e.message : "Error while parsing " + dataStr
});
return;
}
if (config.filter && typeof config.filter === 'object') filter = config.filter;
if (!filter) filter = msg.filter;
if (!filter) filter = {};

var Model;

if (modelName && modelName.trim().length > 0) {
Model = loopback.findModel(modelName, node.callContext);
if (Model) {
Model.find(filter, msg.callContext, function (err, response) {
if (err) {
console.log(err);
node.status({
"fill": "red",
"shape": "dot",
"text": "An error occurred"
});
msg.payload = err;
node.send([null, msg]);
} else {
node.status({
"fill": "green",
"shape": "dot",
"text": "Found " + response.length + " records"
});
msg.resultModelName = modelName;
response.forEach(function (instance, index) {
if (instance instanceof Model) {
response[index] = response[index].toObject();
}
});
msg.payload = response;
node.send([msg, null]);
}
});
} else {
var err = {
"errorMessage": "Model " + modelName + " not found"
};
node.status({
"fill": "red",
"shape": "dot",
"text": "Model " + modelName + " not found"
});
msg.payload = err;
node.send([null, msg]);
}
} else {
var err = {
"errorMessage": "Model Name not specified in config or as 'msg.modelname'"
};
try {
if (filter && typeof filter === 'string') filter = JSON.parse(filter);
} catch(e) {
node.status({
"fill": "red",
"shape": "dot",
"text": "Model Name not specified in config or as 'msg.modelname'"
"text": e.message ? e.message : "Error while parsing " + dataStr
});
msg.payload = err;
node.send([null, msg]);
return;
}



var Model = loopback.findModel(modelName, node.callContext);
if (Model) {
Model.find(filter, msg.callContext, function (err, response) {
if (err) {
console.log(err);
node.status({
"fill": "red",
"shape": "dot",
"text": "An error occurred"
});
msg.payload = err;
node.send([null, msg]);
} else {
node.status({
"fill": "green",
"shape": "dot",
"text": "Found " + response.length + " records"
});
msg.resultModelName = modelName;
response.forEach(function (instance, index) {
if (instance instanceof Model) {
response[index] = response[index].toObject();
}
});
msg.payload = response;
node.send([msg, null]);
}
});
} else {
node.status({fill:"red",shape:"dot",text:"Invalid ModelName: " + modelName});
return this.error(RED._("findData.errors.modelNameInvalid"));
}
});

node.on('close', function () {
Expand Down
2 changes: 1 addition & 1 deletion loopback-async-after-remote/async-after-remote.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$("#node-input-modelname").click(function() {
console.log(RED);
$("#node-input-modelname").addClass('disabled');
$.getJSON('http://localhost:' + RED.settings.editorTheme.projects.appPort + '/api/ModelDefinitions',function(data) {
$.getJSON('http://localhost:' + RED.settings.editorTheme.projects.appPort + '/api/ModelDefinitions?filter[order]=clientModelName',function(data) {
$("#node-input-modelname").removeClass('disabled');
var modelNames = data.map(function(m) {return m.clientModelName});
$("#node-input-modelname").autocomplete({
Expand Down
2 changes: 1 addition & 1 deletion loopback-async-before-remote/async-before-remote.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$("#node-input-modelname").click(function() {
console.log(RED);
$("#node-input-modelname").addClass('disabled');
$.getJSON('http://localhost:' + RED.settings.editorTheme.projects.appPort + '/api/ModelDefinitions',function(data) {
$.getJSON('http://localhost:' + RED.settings.editorTheme.projects.appPort + '/api/ModelDefinitions?filter[order]=clientModelName',function(data) {
$("#node-input-modelname").removeClass('disabled');
var modelNames = data.map(function(m) {return m.clientModelName});
$("#node-input-modelname").autocomplete({
Expand Down
2 changes: 1 addition & 1 deletion loopback-async-observer/async-observer.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$("#node-input-modelname").click(function() {
console.log(RED);
$("#node-input-modelname").addClass('disabled');
$.getJSON('http://localhost:' + RED.settings.editorTheme.projects.appPort + '/api/ModelDefinitions',function(data) {
$.getJSON('http://localhost:' + RED.settings.editorTheme.projects.appPort + '/api/ModelDefinitions?filter[order]=clientModelName',function(data) {
$("#node-input-modelname").removeClass('disabled');
var modelNames = data.map(function(m) {return m.clientModelName});
$("#node-input-modelname").autocomplete({
Expand Down
Loading

0 comments on commit 568c21b

Please sign in to comment.