2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-14 00:46:58 +08:00
|
|
|
var parentFactory = require('../factory');
|
2019-10-07 15:40:50 +08:00
|
|
|
var dataviews = require('.');
|
2016-05-14 00:46:58 +08:00
|
|
|
|
2016-05-14 02:47:36 +08:00
|
|
|
function OverviewsDataviewFactory(queryRewriter, queryRewriteData, options) {
|
2016-05-14 00:46:58 +08:00
|
|
|
this.queryRewriter = queryRewriter;
|
|
|
|
this.queryRewriteData = queryRewriteData;
|
2016-05-14 02:47:36 +08:00
|
|
|
this.options = options;
|
2016-05-14 00:46:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
OverviewsDataviewFactory.prototype.getDataview = function(query, dataviewDefinition) {
|
|
|
|
var type = dataviewDefinition.type;
|
|
|
|
var dataviews = OverviewsDataviewMetaFactory.dataviews;
|
|
|
|
if ( !this.queryRewriter || !this.queryRewriteData || !dataviews[type] ) {
|
|
|
|
return parentFactory.getDataview(query, dataviewDefinition);
|
|
|
|
}
|
2016-05-14 02:47:36 +08:00
|
|
|
return new dataviews[type](
|
2017-03-17 02:15:34 +08:00
|
|
|
query, dataviewDefinition.options, this.queryRewriter, this.queryRewriteData, this.options,
|
|
|
|
dataviewDefinition.sql
|
2016-05-14 02:47:36 +08:00
|
|
|
);
|
2016-05-14 00:46:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var OverviewsDataviewMetaFactory = {
|
|
|
|
dataviews: Object.keys(dataviews).reduce(function(allDataviews, dataviewClassName) {
|
|
|
|
allDataviews[dataviewClassName.toLowerCase()] = dataviews[dataviewClassName];
|
|
|
|
return allDataviews;
|
|
|
|
}, {}),
|
|
|
|
|
2016-05-14 02:47:36 +08:00
|
|
|
getFactory: function(queryRewriter, queryRewriteData, options) {
|
|
|
|
return new OverviewsDataviewFactory(queryRewriter, queryRewriteData, options);
|
2016-05-14 00:46:58 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = OverviewsDataviewMetaFactory;
|