res.locals fixing controllers

This commit is contained in:
Simon Martín
2017-10-02 12:07:35 +02:00
parent 783eb0eec7
commit f9d87bc40f
4 changed files with 35 additions and 15 deletions
+27 -11
View File
@@ -321,25 +321,41 @@ LayergroupController.prototype.finalizeGetTileOrGrid = function(err, req, res, t
};
LayergroupController.prototype.bbox = function(req, res, next) {
this.staticMap(req, res, +req.params.width, +req.params.height, {
west: +req.params.west,
north: +req.params.north,
east: +req.params.east,
south: +req.params.south
}, next);
this.staticMap(
req,
res,
+req.params.width,
+req.params.height,
null,
{
west: +req.params.west,
north: +req.params.north,
east: +req.params.east,
south: +req.params.south
},
next
);
};
LayergroupController.prototype.center = function(req, res, next) {
this.staticMap(req, res, +req.params.width, +req.params.height, +req.params.z, {
lng: +req.params.lng,
lat: +req.params.lat
}, next);
this.staticMap(
req,
res,
+req.params.width,
+req.params.height,
+req.params.z,
{
lng: +req.params.lng,
lat: +req.params.lat
},
next
);
};
LayergroupController.prototype.staticMap = function(req, res, width, height, zoom /* bounds */, center, next) {
var format = req.params.format === 'jpg' ? 'jpeg' : 'png';
req.params.layer = req.params.layer || 'all';
req.params.format = req.params.format || 'png';
res.locals.layer = res.locals.layer || 'all';
var self = this;
+2 -1
View File
@@ -181,7 +181,8 @@ MapController.prototype.create = function(req, res, prepareConfigFn, next) {
var datasource = context.datasource || Datasource.EmptyDatasource();
mapConfig = new MapConfig(requestMapConfig, datasource);
self.mapBackend.createLayergroup(
mapConfig, req.params,
mapConfig,
res.locals,
new CreateLayergroupMapConfigProvider(mapConfig, req.context.user, self.userLimitsApi, res.locals),
this
);
+3 -3
View File
@@ -125,7 +125,7 @@ NamedMapsController.prototype.staticMap = function(req, res, next) {
var format = req.params.format === 'jpg' ? 'jpeg' : 'png';
res.locals.format = req.params.format || 'png';
res.locals.layer = req.params.layer || 'all';
res.locals.layer = res.locals.layer || 'all';
var namedMapProvider;
step(
@@ -148,7 +148,7 @@ NamedMapsController.prototype.staticMap = function(req, res, next) {
},
function prepareImageOptions(err) {
assert.ifError(err);
self.getStaticImageOptions(cdbUser, req.params, namedMapProvider, this);
self.getStaticImageOptions(cdbUser, res.locals, namedMapProvider, this);
},
function getImage(err, imageOpts) {
assert.ifError(err);
@@ -222,7 +222,7 @@ NamedMapsController.prototype.prepareLayerFilterFromPreviewLayers = function (
}
// overwrites 'all' default filter
req.params.layer = layerVisibilityFilter.join(',');
res.locals.layer = layerVisibilityFilter.join(',');
// recreates the provider
self.namedMapProviderCache.get(
@@ -74,6 +74,9 @@ module.exports = _.extend({}, serverOptions, {
}
req.params.dbname = 'test_windshaft_cartodb_user_1_db';
// add all params to res.locals
res.locals = _.extend({}, req.params);
// increment number of calls counter
global.req2params_calls = global.req2params_calls ? global.req2params_calls + 1 : 1;