|
|
@@ -6,18 +6,28 @@ import _ from 'lodash';
|
|
|
import coreModule from 'app/core/core_module';
|
|
|
import { variableTypes } from './variable';
|
|
|
import { Graph } from 'app/core/utils/dag';
|
|
|
+import { TemplateSrv } from 'app/features/templating/template_srv';
|
|
|
+import { TimeSrv } from 'app/features/dashboard/time_srv';
|
|
|
+import { DashboardModel } from 'app/features/dashboard/dashboard_model';
|
|
|
+
|
|
|
+// Types
|
|
|
import { TimeRange } from '@grafana/ui/src';
|
|
|
|
|
|
export class VariableSrv {
|
|
|
- dashboard: any;
|
|
|
- variables: any;
|
|
|
+ dashboard: DashboardModel;
|
|
|
+ variables: any[];
|
|
|
|
|
|
/** @ngInject */
|
|
|
- constructor(private $rootScope, private $q, private $location, private $injector, private templateSrv, private timeSrv) {
|
|
|
+ constructor(private $rootScope,
|
|
|
+ private $q,
|
|
|
+ private $location,
|
|
|
+ private $injector,
|
|
|
+ private templateSrv: TemplateSrv,
|
|
|
+ private timeSrv: TimeSrv) {
|
|
|
$rootScope.$on('template-variable-value-updated', this.updateUrlParamsWithCurrentVariables.bind(this), $rootScope);
|
|
|
}
|
|
|
|
|
|
- init(dashboard) {
|
|
|
+ init(dashboard: DashboardModel) {
|
|
|
this.dashboard = dashboard;
|
|
|
this.dashboard.events.on('time-range-updated', this.onTimeRangeUpdated.bind(this));
|
|
|
|
|
|
@@ -38,12 +48,12 @@ export class VariableSrv {
|
|
|
})
|
|
|
)
|
|
|
.then(() => {
|
|
|
- this.templateSrv.updateTemplateData();
|
|
|
+ this.templateSrv.updateIndex();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
onTimeRangeUpdated(timeRange: TimeRange) {
|
|
|
- this.templateSrv.updateTimeVariables(timeRange);
|
|
|
+ this.templateSrv.updateTimeRange(timeRange);
|
|
|
const promises = this.variables.filter(variable => variable.refresh === 2).map(variable => {
|
|
|
const previousOptions = variable.options.slice();
|
|
|
|
|
|
@@ -102,14 +112,14 @@ export class VariableSrv {
|
|
|
|
|
|
addVariable(variable) {
|
|
|
this.variables.push(variable);
|
|
|
- this.templateSrv.updateTemplateData();
|
|
|
+ this.templateSrv.updateIndex();
|
|
|
this.dashboard.updateSubmenuVisibility();
|
|
|
}
|
|
|
|
|
|
removeVariable(variable) {
|
|
|
const index = _.indexOf(this.variables, variable);
|
|
|
this.variables.splice(index, 1);
|
|
|
- this.templateSrv.updateTemplateData();
|
|
|
+ this.templateSrv.updateIndex();
|
|
|
this.dashboard.updateSubmenuVisibility();
|
|
|
}
|
|
|
|