Extract context metadata (turbo-carto) functionallity to its own middleware
This commit is contained in:
@@ -183,6 +183,7 @@ MapController.prototype.create = function(req, res, prepareConfigFn, next) {
|
||||
res.locals.mapconfig = mapConfig;
|
||||
res.locals.analysesResults = context.analysesResults;
|
||||
res.locals.layergroup = layergroup;
|
||||
res.locals.context = context;
|
||||
|
||||
const afterLayergroupCreate = self.afterLayergroupCreateBuilder({
|
||||
includeQuery: true
|
||||
@@ -199,7 +200,6 @@ MapController.prototype.create = function(req, res, prepareConfigFn, next) {
|
||||
|
||||
const { layergroup } = res.locals;
|
||||
|
||||
addContextMetadata(layergroup, mapConfig.obj(), context);
|
||||
res.set('X-Layergroup-Id', layergroup.layergroupid);
|
||||
|
||||
res.status(200);
|
||||
@@ -232,17 +232,6 @@ function populateError(err, mapConfig) {
|
||||
return error;
|
||||
}
|
||||
|
||||
function addContextMetadata(layergroup, mapConfig, context) {
|
||||
if (layergroup.metadata && Array.isArray(layergroup.metadata.layers) && Array.isArray(mapConfig.layers)) {
|
||||
layergroup.metadata.layers = layergroup.metadata.layers.map(function(layer, layerIndex) {
|
||||
if (context.turboCarto && Array.isArray(context.turboCarto.layers)) {
|
||||
layer.meta.cartocss_meta = context.turboCarto.layers[layerIndex];
|
||||
}
|
||||
return layer;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
MapController.prototype.instantiateTemplate = function(req, res, prepareParamsFn, next) {
|
||||
var self = this;
|
||||
|
||||
@@ -286,6 +275,7 @@ MapController.prototype.instantiateTemplate = function(req, res, prepareParamsFn
|
||||
res.locals.analysesResults = mapConfigProvider.analysesResults;
|
||||
res.locals.layergroup = layergroup;
|
||||
res.locals.template = mapConfigProvider.template;
|
||||
res.locals.context = mapConfigProvider.context;
|
||||
|
||||
const afterLayergroupCreate = self.afterLayergroupCreateBuilder({
|
||||
useTemplateHash: true
|
||||
@@ -301,8 +291,6 @@ MapController.prototype.instantiateTemplate = function(req, res, prepareParamsFn
|
||||
|
||||
const { layergroup } = res.locals;
|
||||
|
||||
addContextMetadata(layergroup, mapConfig.obj(), mapConfigProvider.context);
|
||||
|
||||
res.set('X-Layergroup-Id', layergroup.layergroupid);
|
||||
self.surrogateKeysCache.tag(res, new NamedMapsCacheEntry(cdbuser, mapConfigProvider.getTemplateName()));
|
||||
|
||||
@@ -373,6 +361,10 @@ MapController.prototype.afterLayergroupCreateBuilder = function (options = {}) {
|
||||
|
||||
setAnalysesMetadataToLayergroup(req, res, this);
|
||||
},
|
||||
function setTurboCartoMetadataToLayergroup (err) {
|
||||
assert.ifError(err);
|
||||
self.setTurboCartoMetadataToLayergroup(req, res, this);
|
||||
},
|
||||
function finish(err) {
|
||||
callback(err);
|
||||
}
|
||||
@@ -534,6 +526,25 @@ MapController.prototype.setAnalysesMetadataToLayergroupBuilder = function (inclu
|
||||
};
|
||||
};
|
||||
|
||||
MapController.prototype.setTurboCartoMetadataToLayergroup = function (req, res, callback) {
|
||||
const { layergroup, mapconfig, context } = res.locals;
|
||||
|
||||
addContextMetadata(layergroup, mapconfig.obj(), context);
|
||||
|
||||
callback();
|
||||
};
|
||||
|
||||
function addContextMetadata(layergroup, mapConfig, context) {
|
||||
if (layergroup.metadata && Array.isArray(layergroup.metadata.layers) && Array.isArray(mapConfig.layers)) {
|
||||
layergroup.metadata.layers = layergroup.metadata.layers.map(function(layer, layerIndex) {
|
||||
if (context.turboCarto && Array.isArray(context.turboCarto.layers)) {
|
||||
layer.meta.cartocss_meta = context.turboCarto.layers[layerIndex];
|
||||
}
|
||||
return layer;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getLastUpdatedTime(analysesResults, lastUpdateTime) {
|
||||
if (!Array.isArray(analysesResults)) {
|
||||
return lastUpdateTime;
|
||||
|
||||
Reference in New Issue
Block a user