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,17 +35,19 @@ function _castColumnToEpoch(columnName) {
}
function wrappedDates(query) {
if (query.match(/\b_cdb_epoch_transformation\b/)) {
const columns = [];
const fieldMatcher = /\bdate_part\('epoch', "([^"]+)"\) as "([^"]+)"/gmi;
let match;
do {
match = fieldMatcher.exec(query);
if (match && match[1] === match[2]) {
columns.push(match[1]);
}
} while (match);
return columns;
if (query) {
if (query.match(/\b_cdb_epoch_transformation\b/)) {
const columns = [];
const fieldMatcher = /\bdate_part\('epoch', "([^"]+)"\) as "([^"]+)"/gmi;
let match;
do {
match = fieldMatcher.exec(query);
if (match && match[1] === match[2]) {
columns.push(match[1]);
}
} while (match);
return columns;
}
}
}

View File

@ -172,9 +172,12 @@ 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);
if (wrappedColumns) {
layer.meta.dates_as_numbers = wrappedColumns;
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;
});