mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
More refinements of tag selection and state restoration after dashboard load
This commit is contained in:
parent
b5a846154a
commit
b0451dc1b3
@ -27,7 +27,6 @@ function (angular, app, _) {
|
||||
});
|
||||
|
||||
vm.selectedValues = _.filter(vm.options, {selected: true});
|
||||
vm.selectedTags = vm.selectedTags || [];
|
||||
|
||||
if (!vm.tags) {
|
||||
vm.tags = _.map(vm.variable.tags, function(value) {
|
||||
@ -40,21 +39,37 @@ function (angular, app, _) {
|
||||
};
|
||||
|
||||
vm.updateLinkText = function() {
|
||||
// var currentValues = vm.variable.current.text;
|
||||
//
|
||||
// if (vm.variable.current.tags) {
|
||||
// selectedOptions = _.filter(selectedOptions, function(test) {
|
||||
// for (var i = 0; i < vm.variable.current.tags; i++) {
|
||||
// var tag = vm.selectedTags[i];
|
||||
// if (_.indexOf(tag.values, test.text) !== -1) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// });
|
||||
// }
|
||||
//
|
||||
vm.linkText = vm.variable.current.text;
|
||||
var current = vm.variable.current;
|
||||
var currentValues = current.value;
|
||||
|
||||
if (_.isArray(currentValues) && current.tags.length) {
|
||||
// filer out values that are in selected tags
|
||||
currentValues = _.filter(currentValues, function(test) {
|
||||
for (var i = 0; i < current.tags.length; i++) {
|
||||
if (_.indexOf(current.tags[i].values, test) !== -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// convert values to text
|
||||
var currentTexts = _.map(currentValues, function(value) {
|
||||
for (var i = 0; i < vm.variable.options.length; i++) {
|
||||
var option = vm.variable.options[i];
|
||||
if (option.value === value) {
|
||||
return option.text;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
// join texts
|
||||
vm.linkText = currentTexts.join(' + ');
|
||||
if (vm.linkText.length > 0) {
|
||||
vm.linkText += ' + ';
|
||||
}
|
||||
} else {
|
||||
vm.linkText = vm.variable.current.text;
|
||||
}
|
||||
};
|
||||
|
||||
vm.clearSelections = function() {
|
||||
@ -202,6 +217,7 @@ function (angular, app, _) {
|
||||
};
|
||||
|
||||
vm.init = function() {
|
||||
vm.selectedTags = vm.variable.current.tags || [];
|
||||
vm.updateLinkText();
|
||||
};
|
||||
|
||||
|
@ -94,11 +94,10 @@ function () {
|
||||
it("should select values", function() {
|
||||
expect(ctrl.options[0].selected).to.be(true);
|
||||
expect(ctrl.options[2].selected).to.be(true);
|
||||
expect(ctrl.linkText).to.be('server-1 + server-2');
|
||||
});
|
||||
|
||||
it("link text should not include tag values", function() {
|
||||
expect(ctrl.linkText).to.not.contain('server-1');
|
||||
expect(ctrl.linkText).to.be('');
|
||||
});
|
||||
|
||||
describe('and then dropdown is opened and closed without changes', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user