Commit 666013b0 by Torkel Ödegaard

fix(panel repeat): fixed issue with repeat panels in combination with setting…

fix(panel repeat): fixed issue with repeat panels in combination with setting variable values from URL, fixes #2351
parent c7dafd4b
......@@ -80,6 +80,7 @@ function (angular, _, kbn) {
if (_.isArray(variable.current.value)) {
variable.current.text = variable.current.value.join(' + ');
this.selectOptionsForCurrentValue(variable);
}
templateSrv.updateTemplateData();
......@@ -128,6 +129,18 @@ function (angular, _, kbn) {
.then(_.partial(this.validateVariableSelectionState, variable));
};
this.selectOptionsForCurrentValue = function(variable) {
for (var i = 0; i < variable.current.value.length; i++) {
var value = variable.current.value[i];
for (var y = 0; y < variable.options.length; y++) {
var option = variable.options[y];
if (option.value === value) {
option.selected = true;
}
}
}
};
this.validateVariableSelectionState = function(variable) {
if (!variable.current) {
if (!variable.options.length) { return; }
......@@ -135,15 +148,7 @@ function (angular, _, kbn) {
}
if (_.isArray(variable.current.value)) {
for (var i = 0; i < variable.current.value.length; i++) {
var value = variable.current.value[i];
for (var y = 0; y < variable.options.length; y++) {
var option = variable.options[y];
if (option.value === value) {
option.selected = true;
}
}
}
this.selectOptionsForCurrentValue(variable);
} else {
var currentOption = _.findWhere(variable.options, { text: variable.current.text });
if (currentOption) {
......@@ -225,17 +230,17 @@ function (angular, _, kbn) {
this.addAllOption = function(variable) {
var allValue = '';
switch(variable.allFormat) {
case 'wildcard':
allValue = '*';
case 'wildcard':
allValue = '*';
break;
case 'regex wildcard':
allValue = '.*';
case 'regex wildcard':
allValue = '.*';
break;
case 'regex values':
allValue = '(' + _.pluck(variable.options, 'text').join('|') + ')';
case 'regex values':
allValue = '(' + _.pluck(variable.options, 'text').join('|') + ')';
break;
default:
allValue = '{';
default:
allValue = '{';
allValue += _.pluck(variable.options, 'text').join(',');
allValue += '}';
}
......
......@@ -52,23 +52,25 @@ define([
var variable = {
name: 'apps',
multi: true,
current: {text: "test", value: "test"},
options: [{text: "test", value: "test"}]
current: {text: "val1", value: "val1"},
options: [{text: "val1", value: "val1"}, {text: 'val2', value: 'val2'}]
};
beforeEach(function() {
var dashboard = { templating: { list: [variable] } };
var urlParams = {};
urlParams["var-apps"] = ["new", "other"];
urlParams["var-apps"] = ["val1", "val2"];
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");
expect(variable.current.value[0]).to.be("val1");
expect(variable.current.value[1]).to.be("val2");
expect(variable.current.text).to.be("val1 + val2");
expect(variable.options[0].selected).to.be(true);
expect(variable.options[1].selected).to.be(true);
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment