Templating: You can now select multiple template variables values at the same time. Closes #1922

This commit is contained in:
Torkel Ödegaard 2015-05-04 10:13:12 +02:00
parent e5c1169120
commit 385048b620
4 changed files with 54 additions and 2 deletions

View File

@ -2,6 +2,7 @@
**New dashboard features**
- [Issue #1144](https://github.com/grafana/grafana/issues/1144). Templating: You can now select multiple template variables values at the same time.
- [Issue #1922](https://github.com/grafana/grafana/issues/1922). Templating: Specify multiple variable values via URL params.
- [Issue #1888](https://github.com/grafana/grafana/issues/1144). Templating: Repeat panel or row for each selected template variable value
**User or Organization admin**

View File

@ -57,6 +57,10 @@ function (angular, _, kbn) {
var option = _.findWhere(variable.options, { text: urlValue });
option = option || { text: urlValue, value: urlValue };
if (_.isArray(urlValue)) {
option.text = urlValue.join(', ');
}
this.updateAutoInterval(variable);
return this.setVariableValue(variable, option);
};

View File

@ -69,6 +69,7 @@ define([
self.timeSrv = new TimeSrvStub();
self.datasourceSrv = {};
self.backendSrv = {};
self.$location = {};
self.$routeParams = {};
this.providePhase = function(mocks) {

View File

@ -10,7 +10,7 @@ define([
var ctx = new helpers.ServiceTestContext();
beforeEach(module('grafana.services'));
beforeEach(ctx.providePhase(['datasourceSrv', 'timeSrv', 'templateSrv', "$routeParams"]));
beforeEach(ctx.providePhase(['datasourceSrv', 'timeSrv', 'templateSrv', '$location']));
beforeEach(ctx.createService('templateValuesSrv'));
describe('update interval variable options', function() {
@ -27,11 +27,57 @@ define([
});
});
describe('when template variable is present in url', function() {
var variable = {
name: 'apps',
current: {text: "test", value: "test"},
options: [{text: "test", value: "test"}]
};
beforeEach(function() {
var dashboard = { templating: { list: [variable] } };
var urlParams = {};
urlParams["var-apps"] = "new";
ctx.$location.search = sinon.stub().returns(urlParams);
ctx.service.init(dashboard);
});
it('should update current value', function() {
expect(variable.current.value).to.be("new");
expect(variable.current.text).to.be("new");
});
});
describe('when template variable is present in url multiple times', function() {
var variable = {
name: 'apps',
multi: true,
current: {text: "test", value: "test"},
options: [{text: "test", value: "test"}]
};
beforeEach(function() {
var dashboard = { templating: { list: [variable] } };
var urlParams = {};
urlParams["var-apps"] = ["new", "other"];
ctx.$location.search = sinon.stub().returns(urlParams);
ctx.service.init(dashboard);
});
it('should update current value', function() {
expect(variable.current.value.length).to.be(2);
expect(variable.current.value[0]).to.be("new");
expect(variable.current.value[1]).to.be("other");
expect(variable.current.text).to.be("new, other");
});
});
function describeUpdateVariable(desc, fn) {
describe(desc, function() {
var scenario = {};
scenario.setup = function(setupFn) {
scenario.setupFn = setupFn;
scenario.setupFn = setupFn;
};
beforeEach(function() {