Created
December 5, 2013 05:53
-
-
Save bulkan/7800715 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ganttresult = []; | |
app.get('/get',cors(), function(request,response) { | |
async.waterfall([ | |
function(callback) { | |
connection.query("SELECT id FROM Gantt",function(err, rows) { | |
if (err) return callback(err); | |
rows.unshift(null); | |
callback.apply(this, rows); | |
}, | |
function(all_id, callback){ | |
function _query(row, _cb) { | |
connection.query("SELECT id,tailName FROM Gantt where id= '" + row.id + "'", function(err, rows) { | |
if (err) { | |
console.log('error in fetching ' + err); | |
return _cb(err); | |
} | |
rows.unshift(null); | |
_cb.apply(this, rows); | |
} | |
async.map(all_id, _query, function(err, more_rows){ | |
if (err) return callback(err); | |
var jsonString1 = rows; | |
var set_id = jsonString1[0].id; | |
connection.query("SELECT itemId,name,start,end FROM GanttFlight where id= '"+set_id+"'",function(err, rows) { | |
if (err) { | |
console.log('error in fetching ' + err); | |
} | |
var jsonString2=rows; | |
var gantt1=new Object(); | |
gantt1.id=jsonString1[0].id; | |
gantt1.name=jsonString1[0].tailName; | |
var series = new Array(); | |
if(jsonString2.length>0){ | |
for(var i=0;i<jsonString2.length;i++){ | |
var gantt2=new Object(); | |
gantt2.item=jsonString2[i]; | |
series.push(gantt2); | |
gantt1.series=series; | |
} | |
} | |
else{ | |
gantt1.series=[]; | |
} | |
ganttresult.push(gantt1); | |
}); | |
} | |
var result= JSON.stringify(ganttresult); | |
ganttresult=[]; | |
response.send('{\"data\":'+result+'}'); | |
response.end(); | |
} | |
}); | |
} | |
], function(err) { | |
if(err){ | |
console.log(err); | |
} | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment