TemplateSrv: migrate to grafana/runtime
This commit is contained in:
@@ -6,6 +6,7 @@ import * as metricFunctions from './metricFunctions';
|
|||||||
import * as migrations from './migrations';
|
import * as migrations from './migrations';
|
||||||
import { ShowProblemTypes } from './types';
|
import { ShowProblemTypes } from './types';
|
||||||
import { CURRENT_SCHEMA_VERSION } from '../panel-triggers/migrations';
|
import { CURRENT_SCHEMA_VERSION } from '../panel-triggers/migrations';
|
||||||
|
import { getTemplateSrv, TemplateSrv } from '@grafana/runtime';
|
||||||
|
|
||||||
|
|
||||||
function getTargetDefaults() {
|
function getTargetDefaults() {
|
||||||
@@ -79,7 +80,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
|
|
||||||
zabbix: any;
|
zabbix: any;
|
||||||
replaceTemplateVars: any;
|
replaceTemplateVars: any;
|
||||||
templateSrv: any;
|
templateSrv: TemplateSrv;
|
||||||
editorModes: Array<{ value: string; text: string; queryType: number; }>;
|
editorModes: Array<{ value: string; text: string; queryType: number; }>;
|
||||||
slaPropertyList: Array<{ name: string; property: string; }>;
|
slaPropertyList: Array<{ name: string; property: string; }>;
|
||||||
slaIntervals: Array<{ text: string; value: string; }>;
|
slaIntervals: Array<{ text: string; value: string; }>;
|
||||||
@@ -104,13 +105,13 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
oldTarget: any;
|
oldTarget: any;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $injector, $rootScope, $sce, templateSrv) {
|
constructor($scope, $injector, $rootScope) {
|
||||||
super($scope, $injector);
|
super($scope, $injector);
|
||||||
this.zabbix = this.datasource.zabbix;
|
this.zabbix = this.datasource.zabbix;
|
||||||
|
|
||||||
// Use custom format for template variables
|
// Use custom format for template variables
|
||||||
this.replaceTemplateVars = this.datasource.replaceTemplateVars;
|
this.replaceTemplateVars = this.datasource.replaceTemplateVars;
|
||||||
this.templateSrv = templateSrv;
|
this.templateSrv = getTemplateSrv();
|
||||||
|
|
||||||
this.editorModes = [
|
this.editorModes = [
|
||||||
{value: 'num', text: 'Metrics', queryType: c.MODE_METRICS},
|
{value: 'num', text: 'Metrics', queryType: c.MODE_METRICS},
|
||||||
@@ -278,7 +279,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
const metrics = _.uniq(_.map(this.metric[metricList], 'name'));
|
const metrics = _.uniq(_.map(this.metric[metricList], 'name'));
|
||||||
|
|
||||||
// Add template variables
|
// Add template variables
|
||||||
_.forEach(this.templateSrv.variables, variable => {
|
_.forEach(this.templateSrv.getVariables(), variable => {
|
||||||
metrics.unshift('$' + variable.name);
|
metrics.unshift('$' + variable.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -290,7 +291,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTemplateVariables() {
|
getTemplateVariables() {
|
||||||
return _.map(this.templateSrv.variables, variable => {
|
return _.map(this.templateSrv.getVariables(), variable => {
|
||||||
return '$' + variable.name;
|
return '$' + variable.name;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -361,7 +362,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isVariable(str) {
|
isVariable(str) {
|
||||||
return utils.isTemplateVariable(str, this.templateSrv.variables);
|
return utils.isTemplateVariable(str, this.templateSrv.getVariables());
|
||||||
}
|
}
|
||||||
|
|
||||||
onTargetBlur() {
|
onTargetBlur() {
|
||||||
@@ -384,7 +385,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
isContainsVariables() {
|
isContainsVariables() {
|
||||||
return _.some(['group', 'host', 'application'], field => {
|
return _.some(['group', 'host', 'application'], field => {
|
||||||
if (this.target[field] && this.target[field].filter) {
|
if (this.target[field] && this.target[field].filter) {
|
||||||
return utils.isTemplateVariable(this.target[field].filter, this.templateSrv.variables);
|
return utils.isTemplateVariable(this.target[field].filter, this.templateSrv.getVariables());
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user