Overviews adapter with getMapConfig interface

This commit is contained in:
Raul Ochoa 2016-05-23 15:52:31 +02:00
parent 9f6ce64a31
commit 6ccdb6cefd
4 changed files with 23 additions and 18 deletions

View File

@ -188,17 +188,12 @@ MapController.prototype.create = function(req, res, prepareConfigFn) {
function addOverviewsInformation(err, requestMapConfig, datasource) {
assert.ifError(err);
var next = this;
self.overviewsAdapter.getLayers(
req.context.user, requestMapConfig.layers, analysesResults,
function(err, layers) {
self.overviewsAdapter.getMapConfig(req.context.user, requestMapConfig, analysesResults,
function(err, requestMapConfig) {
if (err) {
return next(err);
}
if (layers) {
requestMapConfig.layers = layers;
}
return next(null, requestMapConfig, datasource);
}
);

View File

@ -9,11 +9,13 @@ function MapConfigOverviewsAdapter(overviewsMetadataApi, filterStatsApi) {
module.exports = MapConfigOverviewsAdapter;
MapConfigOverviewsAdapter.prototype.getLayers = function(username, layers, analysesResults, callback) {
MapConfigOverviewsAdapter.prototype.getMapConfig = function(username, requestMapConfig, analysesResults, callback) {
var self = this;
var layers = requestMapConfig.layers;
if (!layers || layers.length === 0) {
return callback(null, layers);
return callback(null, requestMapConfig);
}
var augmentLayersQueue = queue(layers.length);
@ -85,7 +87,9 @@ MapConfigOverviewsAdapter.prototype.getLayers = function(username, layers, analy
return callback(new Error('Missing layers array from layergroup config'));
}
return callback(null, layers);
requestMapConfig.layers = layers;
return callback(null, requestMapConfig);
}
layers.forEach(function(layer) {

View File

@ -145,15 +145,11 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function(callback) {
assert.ifError(err);
var next = this;
self.overviewsAdapter.getLayers(self.owner, _mapConfig.layers, self.analysesResults, function(err, layers) {
self.overviewsAdapter.getMapConfig(self.owner, _mapConfig, self.analysesResults, function(err, _mapConfig) {
if (err) {
return next(err);
}
if (layers) {
_mapConfig.layers = layers;
}
return next(null, _mapConfig, datasource);
});
},

View File

@ -33,8 +33,13 @@ describe('MapConfigOverviewsAdapter', function() {
}
};
mapConfigOverviewsAdapter.getLayers('localhost', [layer_without_overviews], [], function(err, layers) {
var _mapConfig = {
layers: [layer_without_overviews]
};
mapConfigOverviewsAdapter.getMapConfig('localhost', _mapConfig, [], function(err, mapConfig) {
assert.ok(!err);
var layers = mapConfig.layers;
assert.equal(layers.length, 1);
assert.equal(layers[0].type, 'cartodb');
assert.equal(layers[0].options.sql, sql);
@ -52,7 +57,7 @@ describe('MapConfigOverviewsAdapter', function() {
var sql = 'SELECT * FROM test_table_overviews';
var cartocss = '#layer { marker-fill: black; }';
var cartocss_version = '2.3.0';
var layer_without_overviews = {
var layer_with_overviews = {
type: 'cartodb',
options: {
sql: sql,
@ -61,8 +66,13 @@ describe('MapConfigOverviewsAdapter', function() {
}
};
mapConfigOverviewsAdapter.getLayers('localhost', [layer_without_overviews], [], function(err, layers) {
var _mapConfig = {
layers: [layer_with_overviews]
};
mapConfigOverviewsAdapter.getMapConfig('localhost', _mapConfig, [], function(err, mapConfig) {
assert.ok(!err);
var layers = mapConfig.layers;
assert.equal(layers.length, 1);
assert.equal(layers[0].type, 'cartodb');
assert.equal(layers[0].options.sql, sql);