Skip to content

Commit cec830e

Browse files
update code to use in both test and production mode
1 parent dcd3d27 commit cec830e

File tree

3 files changed

+82
-70
lines changed

3 files changed

+82
-70
lines changed

node-red-contrib-treeview/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-contrib-treeview",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Custom treeView strcture of data saved into cloudantDb for Dri-list application.",
55
"node-red": {
66
"nodes": {

node-red-contrib-treeview/treeView/treeView.html

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
category: 'Tree View',
44
color: '#C7E9C0',
55
defaults: {
6-
host : {value: "", required: true },
76
database: { value:"", required:true },
87
username : { value:"", required:true },
98
password : { value:"", required:true },
109
operation : { value:"", required: true},
11-
//flag: {value: "", required: true},
12-
//reset: {value: "", require: true}
10+
flag: {value: "", required: true},
1311
},
1412
inputs:1,
1513
outputs:1,
@@ -21,10 +19,6 @@
2119
</script>
2220

2321
<script type="text/x-red" data-template-name="Tree View">
24-
<div class="form-row">
25-
<label for="node-input-host"><i class="fa fa-bookmark"></i> Host</label>
26-
<input type="text" id="node-input-host" placeholder="Host">
27-
</div>
2822
<div class="form-row">
2923
<label for="node-input-database"><i class="fa fa-tag"></i> Database</label>
3024
<input type="text" id="node-input-database" placeholder="Database">
@@ -37,21 +31,30 @@
3731
<label for="node-input-password"><i class="fa fa-lock"></i> Password</label>
3832
<input type="password" id="node-input-password" placeholder="Password">
3933
</div>
40-
<!--<div class="form-row">
34+
35+
<div class="form-row">
36+
<label for="node-input-operation"><i class="fa fa-wrench"></i> Operation</label>
37+
<select type="text" id="node-input-operation" style="width:68%;">
38+
<option value="test">Test Mode</option>
39+
<option value="prod">Production Mode</option>
40+
</select>
41+
</div>
42+
43+
<div class="form-row node-input-flag" style="display: none;">
4144
<label for="node-input-flag"><i class="fa fa-flag-checkered"></i> Partial Flag</label>
4245
<select type="text" id="node-input-flag" style="width:68%;">
4346
<option value="true">True</option>
4447
<option value="false">False</option>
4548
</select>
46-
</div>-->
49+
</div>
4750

48-
<!--<div class="form-row">
49-
<label for="node-input-reset"><i class="fa fa-refresh"></i> Reset database</label>
50-
<select type="text" id="node-input-reset" style="width:68%;">
51-
<option value="true">True</option>
52-
<option value="false">False</option>
53-
</select>
54-
</div>-->
51+
<script>
52+
$("#node-input-operation").change(function() {
53+
var id = $("#node-input-operation option:selected").val();
54+
if (id == "test") $(".node-input-flag").show();
55+
else $(".node-input-flag").hide();
56+
});
57+
</script>
5558

5659
</script>
5760

node-red-contrib-treeview/treeView/treeView.js

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function(RED) {
1313
username = config.username,
1414
password = config.password,
1515
partialFlag = config.flag ;
16-
isReset = config.reset;
16+
operation = config.operation;
1717

1818
//initalizing helper init method
1919
treeViewHelper.init();
@@ -34,12 +34,7 @@ module.exports = function(RED) {
3434
msg.payload = `Either username or password should not empty to make ${node.type} node working properly.`;
3535
node.send(msg);
3636
}
37-
38-
if(_.isEmpty(partialFlag)){
39-
msg.payload = `Partial Flag value must be either true or false for ${node.type} node working properly.`;
40-
node.send(msg);
41-
}
42-
37+
4338
var localMsg = {},
4439
action_array = [],
4540
count=0,
@@ -66,61 +61,75 @@ module.exports = function(RED) {
6661
}
6762

6863
// changeing true/false string to boolean value;
69-
//partialFlag = JSON.parse(partialFlag);
70-
//isReset = JSON.parse(isReset);
64+
partialFlag = JSON.parse(partialFlag);
7165

72-
//reset_db_new(partialFlag, function(return_object1){
73-
//console.log('return_object1', return_object1);
66+
if(operation == "test"){
67+
reset_db_new(partialFlag, function(return_object1){
68+
console.log('return_object1', return_object1);
69+
treeViewHelper.process_msg(action_array, function(return_object){
70+
console.log(return_object);
71+
msg.payload = return_object;
72+
node.send(msg);
73+
});
74+
});
75+
msg.payload = `Comes inside the 'Test' operation. with partialFlag = ${partialFlag}`;
76+
node.send(msg);
77+
}else if( operation == "prod"){
7478
treeViewHelper.process_msg(action_array, function(return_object){
7579
console.log(return_object);
7680
msg.payload = return_object;
7781
node.send(msg);
7882
});
79-
//});
83+
msg.payload = `Comes inside the 'Prod' operation. with partialFlag = ${partialFlag}`;
84+
node.send(msg);
85+
}else{
86+
msg.payload = "Un-specified operation for Tree view node.";
87+
node.send(msg);
88+
}
8089

8190
});
8291

83-
//function reset_db_new(partialFlag, callback){
84-
// var node_original = {}, nodes = [];
85-
// if (partialFlag) {
86-
// node_original = testData.node_original1;
87-
// } else {
88-
// node_original=Object.assign(testData.node_original1, testData.node_original2);
89-
// }
90-
// // delete cloudant database
91-
//
92-
// if(isReset){
93-
// database.resetDatabase(function(obj){
94-
// if(obj.isReset){
95-
// //debugger;
96-
// nodes = [];
97-
// for (var each_record in node_original) {
98-
// if(node_original[each_record]){
99-
// nodes.push(node_original[each_record]);
100-
// }
101-
// }
102-
//
103-
// treeViewHelper.save_array(nodes, callback);
104-
// }else{
105-
// nodes = [];
106-
// for (let each in node_original) {
107-
// if(node_original[each]){
108-
// nodes.push(node_original[each]);
109-
// }
110-
// }
111-
// treeViewHelper.save_array(nodes, callback);
112-
// }
113-
// });
114-
// }else{
115-
// nodes = [];
116-
// for (var each_record in node_original) {
117-
// if(node_original[each_record]){
118-
// nodes.push(node_original[each_record]);
119-
// }
120-
// }
121-
// treeViewHelper.save_array(nodes, callback);
122-
// }
123-
//}
92+
function reset_db_new(partialFlag, callback){
93+
var node_original = {}, nodes = [];
94+
if (partialFlag) {
95+
node_original = testData.node_original1;
96+
} else {
97+
node_original=Object.assign(testData.node_original1, testData.node_original2);
98+
}
99+
// delete cloudant database
100+
101+
if(isReset){
102+
database.resetDatabase(function(obj){
103+
if(obj.isReset){
104+
//debugger;
105+
nodes = [];
106+
for (var each_record in node_original) {
107+
if(node_original[each_record]){
108+
nodes.push(node_original[each_record]);
109+
}
110+
}
111+
112+
treeViewHelper.save_array(nodes, callback);
113+
}else{
114+
nodes = [];
115+
for (let each in node_original) {
116+
if(node_original[each]){
117+
nodes.push(node_original[each]);
118+
}
119+
}
120+
treeViewHelper.save_array(nodes, callback);
121+
}
122+
});
123+
}else{
124+
nodes = [];
125+
for (var each_record in node_original) {
126+
if(node_original[each_record]){
127+
nodes.push(node_original[each_record]);
128+
}
129+
}
130+
treeViewHelper.save_array(nodes, callback);
131+
}
132+
}
124133
}
125134

126135
//Register function to Node-red nodes

0 commit comments

Comments
 (0)