@@ -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