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) { ...@@ -80,6 +80,7 @@ function (angular, _, kbn) {
if (_.isArray(variable.current.value)) { if (_.isArray(variable.current.value)) {
variable.current.text = variable.current.value.join(' + '); variable.current.text = variable.current.value.join(' + ');
this.selectOptionsForCurrentValue(variable);
} }
templateSrv.updateTemplateData(); templateSrv.updateTemplateData();
...@@ -128,6 +129,18 @@ function (angular, _, kbn) { ...@@ -128,6 +129,18 @@ function (angular, _, kbn) {
.then(_.partial(this.validateVariableSelectionState, variable)); .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) { this.validateVariableSelectionState = function(variable) {
if (!variable.current) { if (!variable.current) {
if (!variable.options.length) { return; } if (!variable.options.length) { return; }
...@@ -135,15 +148,7 @@ function (angular, _, kbn) { ...@@ -135,15 +148,7 @@ function (angular, _, kbn) {
} }
if (_.isArray(variable.current.value)) { if (_.isArray(variable.current.value)) {
for (var i = 0; i < variable.current.value.length; i++) { this.selectOptionsForCurrentValue(variable);
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;
}
}
}
} else { } else {
var currentOption = _.findWhere(variable.options, { text: variable.current.text }); var currentOption = _.findWhere(variable.options, { text: variable.current.text });
if (currentOption) { if (currentOption) {
...@@ -225,17 +230,17 @@ function (angular, _, kbn) { ...@@ -225,17 +230,17 @@ function (angular, _, kbn) {
this.addAllOption = function(variable) { this.addAllOption = function(variable) {
var allValue = ''; var allValue = '';
switch(variable.allFormat) { switch(variable.allFormat) {
case 'wildcard': case 'wildcard':
allValue = '*'; allValue = '*';
break; break;
case 'regex wildcard': case 'regex wildcard':
allValue = '.*'; allValue = '.*';
break; break;
case 'regex values': case 'regex values':
allValue = '(' + _.pluck(variable.options, 'text').join('|') + ')'; allValue = '(' + _.pluck(variable.options, 'text').join('|') + ')';
break; break;
default: default:
allValue = '{'; allValue = '{';
allValue += _.pluck(variable.options, 'text').join(','); allValue += _.pluck(variable.options, 'text').join(',');
allValue += '}'; allValue += '}';
} }
......
...@@ -52,23 +52,25 @@ define([ ...@@ -52,23 +52,25 @@ define([
var variable = { var variable = {
name: 'apps', name: 'apps',
multi: true, multi: true,
current: {text: "test", value: "test"}, current: {text: "val1", value: "val1"},
options: [{text: "test", value: "test"}] options: [{text: "val1", value: "val1"}, {text: 'val2', value: 'val2'}]
}; };
beforeEach(function() { beforeEach(function() {
var dashboard = { templating: { list: [variable] } }; var dashboard = { templating: { list: [variable] } };
var urlParams = {}; var urlParams = {};
urlParams["var-apps"] = ["new", "other"]; urlParams["var-apps"] = ["val1", "val2"];
ctx.$location.search = sinon.stub().returns(urlParams); ctx.$location.search = sinon.stub().returns(urlParams);
ctx.service.init(dashboard); ctx.service.init(dashboard);
}); });
it('should update current value', function() { it('should update current value', function() {
expect(variable.current.value.length).to.be(2); expect(variable.current.value.length).to.be(2);
expect(variable.current.value[0]).to.be("new"); expect(variable.current.value[0]).to.be("val1");
expect(variable.current.value[1]).to.be("other"); expect(variable.current.value[1]).to.be("val2");
expect(variable.current.text).to.be("new + other"); 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