Add support for no_filters params in dataviews
This commit is contained in:
parent
ad227a5240
commit
0c9d60b573
@ -24,7 +24,7 @@ module.exports = DataviewBackend;
|
||||
|
||||
DataviewBackend.prototype.getDataview = function (mapConfigProvider, user, params, callback) {
|
||||
|
||||
var dataviewName = params.dataviewName;
|
||||
var dataviewName = params.dataviewName;
|
||||
step(
|
||||
function getMapConfig() {
|
||||
mapConfigProvider.getMapConfig(this);
|
||||
@ -40,9 +40,8 @@ DataviewBackend.prototype.getDataview = function (mapConfigProvider, user, param
|
||||
var pg = new PSQL(dbParamsFromReqParams(params));
|
||||
|
||||
var ownFilter = +params.own_filter;
|
||||
ownFilter = !!ownFilter;
|
||||
|
||||
var query = (ownFilter) ? dataviewDefinition.sql.own_filter_on : dataviewDefinition.sql.own_filter_off;
|
||||
// ownFilter = !!ownFilter;
|
||||
var query = getDaviewQuery(dataviewDefinition, ownFilter);
|
||||
if (params.bbox) {
|
||||
var bboxFilter = new BBoxFilter({column: 'the_geom_webmercator', srid: 3857}, {bbox: params.bbox});
|
||||
query = bboxFilter.sql(query);
|
||||
@ -55,7 +54,7 @@ DataviewBackend.prototype.getDataview = function (mapConfigProvider, user, param
|
||||
);
|
||||
|
||||
var dataview = dataviewFactory.getDataview(query, dataviewDefinition);
|
||||
dataview.getResult(pg, getOverrideParams(params, ownFilter), this);
|
||||
dataview.getResult(pg, getOverrideParams(params, !!ownFilter), this);
|
||||
},
|
||||
function returnCallback(err, result) {
|
||||
return callback(err, result);
|
||||
@ -63,6 +62,16 @@ DataviewBackend.prototype.getDataview = function (mapConfigProvider, user, param
|
||||
);
|
||||
};
|
||||
|
||||
function getDaviewQuery(dataviewDefinition, ownFilter) {
|
||||
if (ownFilter === -1) {
|
||||
return dataviewDefinition.sql.no_filters;
|
||||
} else if (ownFilter === 0) {
|
||||
return dataviewDefinition.sql.own_filter_off;
|
||||
} else if (ownFilter === 1) {
|
||||
return dataviewDefinition.sql.own_filter_on;
|
||||
}
|
||||
}
|
||||
|
||||
function getQueryRewriteData(mapConfig, dataviewDefinition, params) {
|
||||
var sourceId = dataviewDefinition.source.id; // node.id
|
||||
var layer = _.find(mapConfig.obj().layers, function(l) {
|
||||
|
125
test/acceptance/analysis/analyses-filters-params.js
Normal file
125
test/acceptance/analysis/analyses-filters-params.js
Normal file
@ -0,0 +1,125 @@
|
||||
require('../../support/test_helper');
|
||||
|
||||
const assert = require('../../support/assert');
|
||||
const TestClient = require('../../support/test-client');
|
||||
|
||||
describe('analysis-filters-params', () => {
|
||||
|
||||
const CARTOCSS = `#layer {
|
||||
marker-fill-opacity: 1;
|
||||
marker-line-color: white;
|
||||
marker-line-width: 0.5;
|
||||
marker-line-opacity: 1;
|
||||
marker-placement: point;
|
||||
marker-type: ellipse;
|
||||
marker-width: 8;
|
||||
marker-fill: red;
|
||||
marker-allow-overlap: true;
|
||||
}`;
|
||||
|
||||
const mapConfig = {
|
||||
version: '1.6.0',
|
||||
layers: [
|
||||
{
|
||||
"type": "cartodb",
|
||||
"options": {
|
||||
"source": {
|
||||
"id": "a1"
|
||||
},
|
||||
"cartocss": CARTOCSS,
|
||||
"cartocss_version": "2.3.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
dataviews: {
|
||||
pop_max_histogram: {
|
||||
source: {
|
||||
id: 'a1'
|
||||
},
|
||||
type: 'histogram',
|
||||
options: {
|
||||
column: 'pop_max'
|
||||
}
|
||||
},
|
||||
pop_min_histogram: {
|
||||
source: {
|
||||
id: 'a1'
|
||||
},
|
||||
type: 'histogram',
|
||||
options: {
|
||||
column: 'pop_min'
|
||||
}
|
||||
}
|
||||
},
|
||||
analyses: [
|
||||
{
|
||||
"id": "a1",
|
||||
"type": "source",
|
||||
"params": {
|
||||
"query": "select * from populated_places_simple_reduced"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var params = {
|
||||
filters: {
|
||||
dataviews: {
|
||||
pop_max_histogram: {
|
||||
min: 2e6
|
||||
},
|
||||
pop_min_histogram: {
|
||||
max: 2e6
|
||||
}
|
||||
}
|
||||
},
|
||||
own_filter: -1
|
||||
};
|
||||
|
||||
|
||||
it('should get a filtered histogram dataview with all filters', function(done) {
|
||||
const testClient = new TestClient(mapConfig, 1234);
|
||||
|
||||
params.own_filter = 1;
|
||||
|
||||
testClient.getDataview('pop_max_histogram', params, (err, dataview) => {
|
||||
assert.ok(!err, err);
|
||||
|
||||
assert.equal(dataview.type, 'histogram');
|
||||
assert.equal(dataview.bins_count, 6);
|
||||
|
||||
testClient.drain(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should get a filtered histogram dataview with all filters except my own filter', function(done) {
|
||||
const testClient = new TestClient(mapConfig, 1234);
|
||||
|
||||
params.own_filter = 0;
|
||||
|
||||
testClient.getDataview('pop_max_histogram', params, (err, dataview) => {
|
||||
assert.ok(!err, err);
|
||||
|
||||
assert.equal(dataview.type, 'histogram');
|
||||
assert.equal(dataview.bins_count, 24);
|
||||
|
||||
testClient.drain(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should get a filtered histogram dataview without filters', function(done) {
|
||||
const testClient = new TestClient(mapConfig, 1234);
|
||||
|
||||
params.own_filter = -1;
|
||||
|
||||
testClient.getDataview('pop_max_histogram', params, (err, dataview) => {
|
||||
assert.ok(!err, err);
|
||||
|
||||
assert.equal(dataview.type, 'histogram');
|
||||
assert.equal(dataview.bins_count, 48);
|
||||
|
||||
testClient.drain(done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user