Fixed issue with new variable value select dropdown and parent -> child updates, Fixes #2215

This commit is contained in:
Torkel Ödegaard
2015-06-23 20:09:17 +02:00
parent ba2deb5f7b
commit ec98f9181b
4 changed files with 40 additions and 9 deletions
+9 -1
View File
@@ -215,7 +215,7 @@ function (angular, app, _) {
angular
.module('grafana.directives')
.directive('valueSelectDropdown', function($compile, $window, $timeout) {
.directive('valueSelectDropdown', function($compile, $window, $timeout, $rootScope) {
return {
scope: { variable: "=", onUpdated: "&", getValuesForTag: "&" },
@@ -260,6 +260,14 @@ function (angular, app, _) {
}
});
var cleanUp = $rootScope.$on('template-variable-value-updated', function() {
scope.vm.updateLinkText();
});
scope.$on("$destroy", function() {
cleanUp();
});
scope.vm.init();
},
};
+2 -7
View File
@@ -1,18 +1,12 @@
define([
'angular',
'lodash'
],
function (angular, _) {
function (angular) {
'use strict';
var module = angular.module('grafana.controllers');
module.controller('SubmenuCtrl', function($scope, $q, $rootScope, templateValuesSrv, dynamicDashboardSrv) {
var _d = {
enable: true
};
_.defaults($scope.pulldown,_d);
$scope.init = function() {
$scope.panel = $scope.pulldown;
@@ -33,6 +27,7 @@ function (angular, _) {
$scope.variableUpdated = function(variable) {
templateValuesSrv.variableUpdated(variable).then(function() {
dynamicDashboardSrv.update($scope.dashboard);
$rootScope.$emit('template-variable-value-updated');
$rootScope.$broadcast('refresh');
});
};
@@ -146,6 +146,9 @@ function (angular, _, kbn) {
var currentOption = _.findWhere(variable.options, { text: variable.current.text });
if (currentOption) {
return self.setVariableValue(variable, currentOption);
} else {
if (!variable.options.length) { return; }
return self.setVariableValue(variable, variable.options[0]);
}
}
};
+26 -1
View File
@@ -106,6 +106,31 @@ define([
});
});
describeUpdateVariable('query variable with empty current object and refresh', function(scenario) {
scenario.setup(function() {
scenario.variable = { type: 'query', query: '', name: 'test', current: {} };
scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
});
it('should set current value to first option', function() {
expect(scenario.variable.options.length).to.be(2);
expect(scenario.variable.current.value).to.be('backend1');
});
});
describeUpdateVariable('interval variable without auto', function(scenario) {
scenario.setup(function() {
scenario.variable = { type: 'interval', query: '1s,2h,5h,1d', name: 'test' };
});
it('should update options array', function() {
expect(scenario.variable.options.length).to.be(4);
expect(scenario.variable.options[0].text).to.be('1s');
expect(scenario.variable.options[0].value).to.be('1s');
});
});
describeUpdateVariable('interval variable with auto', function(scenario) {
scenario.setup(function() {
scenario.variable = { type: 'interval', query: '1s,2h,5h,1d', name: 'test', auto: true, auto_count: 10 };
@@ -171,7 +196,7 @@ define([
describeUpdateVariable('and existing value still exists in options', function(scenario) {
scenario.setup(function() {
scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
scenario.variable.current = { text: 'backend2'};
scenario.variable.current = { value: 'backend2', text: 'backend2'};
scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
});