mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fixed template variable value changed handling
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import _ from 'lodash';
|
||||
import angular from 'angular';
|
||||
import coreModule from 'app/core/core_module';
|
||||
import { DashboardModel } from 'app/features/dashboard/state';
|
||||
|
||||
export class AdHocFiltersCtrl {
|
||||
segments: any;
|
||||
variable: any;
|
||||
dashboard: DashboardModel;
|
||||
removeTagFilterSegment: any;
|
||||
|
||||
/** @ngInject */
|
||||
@@ -14,14 +16,13 @@ export class AdHocFiltersCtrl {
|
||||
private $q,
|
||||
private variableSrv,
|
||||
$scope,
|
||||
private $rootScope
|
||||
) {
|
||||
this.removeTagFilterSegment = uiSegmentSrv.newSegment({
|
||||
fake: true,
|
||||
value: '-- remove filter --',
|
||||
});
|
||||
this.buildSegmentModel();
|
||||
this.$rootScope.onAppEvent('template-variable-value-updated', this.buildSegmentModel.bind(this), $scope);
|
||||
this.dashboard.events.on('template-variable-value-updated', this.buildSegmentModel.bind(this), $scope);
|
||||
}
|
||||
|
||||
buildSegmentModel() {
|
||||
@@ -171,6 +172,7 @@ export function adHocFiltersComponent() {
|
||||
controllerAs: 'ctrl',
|
||||
scope: {
|
||||
variable: '=',
|
||||
dashboard: '=',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ export class DashboardRow extends React.Component<DashboardRowProps, any> {
|
||||
collapsed: this.props.panel.collapsed,
|
||||
};
|
||||
|
||||
appEvents.on('template-variable-value-updated', this.onVariableUpdated);
|
||||
this.props.dashboard.on('template-variable-value-updated', this.onVariableUpdated);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
appEvents.off('template-variable-value-updated', this.onVariableUpdated);
|
||||
this.props.dashboard.off('template-variable-value-updated', this.onVariableUpdated);
|
||||
}
|
||||
|
||||
onVariableUpdated = () => {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<value-select-dropdown ng-if="variable.type !== 'adhoc' && variable.type !== 'textbox'" variable="variable" on-updated="ctrl.variableUpdated(variable)"></value-select-dropdown>
|
||||
<input type="text" ng-if="variable.type === 'textbox'" ng-model="variable.query" class="gf-form-input width-12" ng-blur="variable.current.value != variable.query && variable.updateOptions() && ctrl.variableUpdated(variable);" ng-keydown="$event.keyCode === 13 && variable.current.value != variable.query && variable.updateOptions() && ctrl.variableUpdated(variable);" ></input>
|
||||
</div>
|
||||
<ad-hoc-filters ng-if="variable.type === 'adhoc'" variable="variable"></ad-hoc-filters>
|
||||
<ad-hoc-filters ng-if="variable.type === 'adhoc'" variable="variable" dashboard="ctrl.dashboard"></ad-hoc-filters>
|
||||
</div>
|
||||
|
||||
<div ng-if="ctrl.dashboard.annotations.list.length > 0">
|
||||
|
||||
@@ -900,4 +900,9 @@ export class DashboardModel {
|
||||
panel.gridPos.h = Math.round(panel.gridPos.h / scaleFactor) || 1;
|
||||
});
|
||||
}
|
||||
|
||||
templateVariableValueUpdated() {
|
||||
this.processRepeats();
|
||||
this.events.emit('template-variable-value-updated');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,6 @@ export function initDashboard({
|
||||
dispatch(updateLocation({path: dashboardUrl, partial: true, replace: true}));
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case DashboardRouteInfo.New: {
|
||||
|
||||
@@ -48,7 +48,6 @@ describe('VariableSrv', function(this: any) {
|
||||
ds.metricFindQuery = () => Promise.resolve(scenario.queryResult);
|
||||
|
||||
ctx.variableSrv = new VariableSrv(
|
||||
ctx.$rootScope,
|
||||
$q,
|
||||
ctx.$location,
|
||||
ctx.$injector,
|
||||
|
||||
@@ -25,9 +25,6 @@ describe('VariableSrv init', function(this: any) {
|
||||
};
|
||||
|
||||
const $injector = {} as any;
|
||||
const $rootscope = {
|
||||
$on: () => {},
|
||||
};
|
||||
|
||||
let ctx = {} as any;
|
||||
|
||||
@@ -54,7 +51,7 @@ describe('VariableSrv init', function(this: any) {
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
ctx.variableSrv = new VariableSrv($rootscope, $q, {}, $injector, templateSrv, timeSrv);
|
||||
ctx.variableSrv = new VariableSrv($q, {}, $injector, templateSrv, timeSrv);
|
||||
|
||||
$injector.instantiate = (variable, model) => {
|
||||
return getVarMockConstructor(variable, model, ctx);
|
||||
|
||||
@@ -18,18 +18,18 @@ export class VariableSrv {
|
||||
variables: any[];
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private $rootScope,
|
||||
private $q,
|
||||
constructor(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: DashboardModel) {
|
||||
this.dashboard = dashboard;
|
||||
this.dashboard.events.on('time-range-updated', this.onTimeRangeUpdated.bind(this));
|
||||
this.dashboard.events.on('template-variable-value-updated', this.updateUrlParamsWithCurrentVariables.bind(this));
|
||||
|
||||
// create working class models representing variables
|
||||
this.variables = dashboard.templating.list = dashboard.templating.list.map(this.createVariableFromModel.bind(this));
|
||||
@@ -59,7 +59,7 @@ export class VariableSrv {
|
||||
|
||||
return variable.updateOptions().then(() => {
|
||||
if (angular.toJson(previousOptions) !== angular.toJson(variable.options)) {
|
||||
this.$rootScope.$emit('template-variable-value-updated');
|
||||
this.dashboard.templateVariableValueUpdated();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -144,7 +144,7 @@ export class VariableSrv {
|
||||
|
||||
return this.$q.all(promises).then(() => {
|
||||
if (emitChangeEvents) {
|
||||
this.$rootScope.appEvent('template-variable-value-updated');
|
||||
this.dashboard.templateVariableValueUpdated();
|
||||
this.dashboard.startRefresh();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user