render query from query builder

This commit is contained in:
Sven Klemm 2018-08-31 15:40:58 +02:00
parent 41b5dae606
commit 390472aa99

View File

@ -1,16 +1,19 @@
import _ from 'lodash'; import _ from 'lodash';
import ResponseParser from './response_parser'; import ResponseParser from './response_parser';
import MysqlQuery from 'app/plugins/datasource/mysql/mysql_query';
export class MysqlDatasource { export class MysqlDatasource {
id: any; id: any;
name: any; name: any;
responseParser: ResponseParser; responseParser: ResponseParser;
queryModel: MysqlQuery;
/** @ngInject **/ /** @ngInject **/
constructor(instanceSettings, private backendSrv, private $q, private templateSrv) { constructor(instanceSettings, private backendSrv, private $q, private templateSrv) {
this.name = instanceSettings.name; this.name = instanceSettings.name;
this.id = instanceSettings.id; this.id = instanceSettings.id;
this.responseParser = new ResponseParser(this.$q); this.responseParser = new ResponseParser(this.$q);
this.queryModel = new MysqlQuery({});
} }
interpolateVariable(value, variable) { interpolateVariable(value, variable) {
@ -37,16 +40,18 @@ export class MysqlDatasource {
} }
query(options) { query(options) {
const queries = _.filter(options.targets, item => { const queries = _.filter(options.targets, target => {
return item.hide !== true; return target.hide !== true;
}).map(item => { }).map(target => {
let queryModel = new MysqlQuery(target, this.templateSrv, options.scopedVars);
return { return {
refId: item.refId, refId: target.refId,
intervalMs: options.intervalMs, intervalMs: options.intervalMs,
maxDataPoints: options.maxDataPoints, maxDataPoints: options.maxDataPoints,
datasourceId: this.id, datasourceId: this.id,
rawSql: this.templateSrv.replace(item.rawSql, options.scopedVars, this.interpolateVariable), rawSql: queryModel.render(this.interpolateVariable),
format: item.format, format: target.format,
}; };
}); });