refactored widgets api call to render all at once rather than one area at a time, closes https://github.com/NodeBB/NodeBB/issues/2062

This commit is contained in:
psychobunny
2014-09-16 10:12:12 -04:00
parent 0ecaa05c76
commit ecd00bb679
2 changed files with 62 additions and 51 deletions

View File

@@ -84,19 +84,34 @@ apiController.getConfig = function(req, res, next) {
apiController.renderWidgets = function(req, res, next) {
var uid = req.user ? req.user.uid : 0,
area = {
var async = require('async'),
uid = req.user ? req.user.uid : 0,
areas = {
template: req.query.template,
location: req.query.location,
locations: req.query.locations,
url: req.query.url
};
},
renderedWidgets = [];
if (!area.template || !area.location) {
if (!areas.template || !areas.locations) {
return res.json(200, {});
}
widgets.render(uid, area, function(err, data) {
res.json(200, data);
async.each(areas.locations, function(location, next) {
widgets.render(uid, {
template: areas.template,
url: areas.url,
location: location
}, function(err, widgets) {
renderedWidgets.push({
location: location,
widgets: widgets
});
next();
});
}, function(err) {
res.json(200, renderedWidgets);
});
};