mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
mysql: added basic templating support
This commit is contained in:
@@ -7,11 +7,22 @@ export class MysqlDatasource {
|
|||||||
name: any;
|
name: any;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(instanceSettings, private backendSrv, private $q) {
|
constructor(instanceSettings, private backendSrv, private $q, private templateSrv) {
|
||||||
this.name = instanceSettings.name;
|
this.name = instanceSettings.name;
|
||||||
this.id = instanceSettings.id;
|
this.id = instanceSettings.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interpolateVariable(value) {
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
return '\"' + value + '\"';
|
||||||
|
}
|
||||||
|
|
||||||
|
var quotedValues = _.map(value, function(val) {
|
||||||
|
return '\"' + val + '\"';
|
||||||
|
});
|
||||||
|
return quotedValues.join(',');
|
||||||
|
}
|
||||||
|
|
||||||
query(options) {
|
query(options) {
|
||||||
var queries = _.filter(options.targets, item => {
|
var queries = _.filter(options.targets, item => {
|
||||||
return item.hide !== true;
|
return item.hide !== true;
|
||||||
@@ -21,7 +32,7 @@ export class MysqlDatasource {
|
|||||||
intervalMs: options.intervalMs,
|
intervalMs: options.intervalMs,
|
||||||
maxDataPoints: options.maxDataPoints,
|
maxDataPoints: options.maxDataPoints,
|
||||||
datasourceId: this.id,
|
datasourceId: this.id,
|
||||||
rawSql: item.rawSql,
|
rawSql: this.templateSrv.replace(item.rawSql, options.scopedVars, this.interpolateVariable),
|
||||||
format: item.format,
|
format: item.format,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user