Various fixes

This avoids errors when trying to wrap dates or detect wrapped dates in non-mapnik layers
This commit is contained in:
Javier Goizueta 2018-06-12 12:05:31 +02:00
parent 251570b638
commit 4a52620d83
3 changed files with 20 additions and 15 deletions

View File

@ -28,7 +28,7 @@ class VectorMapConfigAdapter {
}
_wrapLayer(layer, user) {
if (!layer.options.dates_as_numbers) {
if (!layer.options.dates_as_numbers || !layer.options.sql) {
return Promise.resolve(layer);
}
const originalQuery = layer.options.sql;

View File

@ -35,6 +35,7 @@ function _castColumnToEpoch(columnName) {
}
function wrappedDates(query) {
if (query) {
if (query.match(/\b_cdb_epoch_transformation\b/)) {
const columns = [];
const fieldMatcher = /\bdate_part\('epoch', "([^"]+)"\) as "([^"]+)"/gmi;
@ -47,6 +48,7 @@ function wrappedDates(query) {
} while (match);
return columns;
}
}
}
module.exports = {

View File

@ -172,10 +172,13 @@ module.exports = class LayergroupMetadata {
if (layergroup.metadata && Array.isArray(layergroup.metadata.layers) && Array.isArray(mapConfig.layers)) {
layergroup.metadata.layers = layergroup.metadata.layers.map(function(layer, layerIndex) {
const mapConfigLayer = mapConfig.layers[layerIndex];
const wrappedColumns = dateWrapper.wrappedDates(mapConfigLayer.options.sql);
const layerOptions = mapConfigLayer.options;
if (layerOptions.dates_as_numbers && layerOptions.sql) {
const wrappedColumns = dateWrapper.wrappedDates(layerOptions.sql);
if (wrappedColumns) {
layer.meta.dates_as_numbers = wrappedColumns;
}
}
return layer;
});
}