Windshaft-cartodb/lib/models/dataview/overviews/factory.js

36 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
var parentFactory = require('../factory');
2019-10-07 15:40:50 +08:00
var dataviews = require('.');
2019-10-22 01:07:24 +08:00
function OverviewsDataviewFactory (queryRewriter, queryRewriteData, options) {
this.queryRewriter = queryRewriter;
this.queryRewriteData = queryRewriteData;
this.options = options;
}
2019-10-22 01:07:24 +08:00
OverviewsDataviewFactory.prototype.getDataview = function (query, dataviewDefinition) {
var type = dataviewDefinition.type;
var dataviews = OverviewsDataviewMetaFactory.dataviews;
2019-10-22 01:07:24 +08:00
if (!this.queryRewriter || !this.queryRewriteData || !dataviews[type]) {
return parentFactory.getDataview(query, dataviewDefinition);
}
return new dataviews[type](
query, dataviewDefinition.options, this.queryRewriter, this.queryRewriteData, this.options,
dataviewDefinition.sql
);
};
var OverviewsDataviewMetaFactory = {
2019-10-22 01:07:24 +08:00
dataviews: Object.keys(dataviews).reduce(function (allDataviews, dataviewClassName) {
allDataviews[dataviewClassName.toLowerCase()] = dataviews[dataviewClassName];
return allDataviews;
}, {}),
2019-10-22 01:07:24 +08:00
getFactory: function (queryRewriter, queryRewriteData, options) {
return new OverviewsDataviewFactory(queryRewriter, queryRewriteData, options);
2019-10-22 01:07:24 +08:00
}
};
module.exports = OverviewsDataviewMetaFactory;