Commit b0451dc1 by Torkel Ödegaard

More refinements of tag selection and state restoration after dashboard load

parent b5a84615
...@@ -27,7 +27,6 @@ function (angular, app, _) { ...@@ -27,7 +27,6 @@ function (angular, app, _) {
}); });
vm.selectedValues = _.filter(vm.options, {selected: true}); vm.selectedValues = _.filter(vm.options, {selected: true});
vm.selectedTags = vm.selectedTags || [];
if (!vm.tags) { if (!vm.tags) {
vm.tags = _.map(vm.variable.tags, function(value) { vm.tags = _.map(vm.variable.tags, function(value) {
...@@ -40,21 +39,37 @@ function (angular, app, _) { ...@@ -40,21 +39,37 @@ function (angular, app, _) {
}; };
vm.updateLinkText = function() { vm.updateLinkText = function() {
// var currentValues = vm.variable.current.text; var current = vm.variable.current;
// var currentValues = current.value;
// if (vm.variable.current.tags) {
// selectedOptions = _.filter(selectedOptions, function(test) { if (_.isArray(currentValues) && current.tags.length) {
// for (var i = 0; i < vm.variable.current.tags; i++) { // filer out values that are in selected tags
// var tag = vm.selectedTags[i]; currentValues = _.filter(currentValues, function(test) {
// if (_.indexOf(tag.values, test.text) !== -1) { for (var i = 0; i < current.tags.length; i++) {
// return false; if (_.indexOf(current.tags[i].values, test) !== -1) {
// } return false;
// } }
// return true; }
// }); return true;
// } });
// // convert values to text
vm.linkText = vm.variable.current.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() { vm.clearSelections = function() {
...@@ -202,6 +217,7 @@ function (angular, app, _) { ...@@ -202,6 +217,7 @@ function (angular, app, _) {
}; };
vm.init = function() { vm.init = function() {
vm.selectedTags = vm.variable.current.tags || [];
vm.updateLinkText(); vm.updateLinkText();
}; };
......
...@@ -94,11 +94,10 @@ function () { ...@@ -94,11 +94,10 @@ function () {
it("should select values", function() { it("should select values", function() {
expect(ctrl.options[0].selected).to.be(true); expect(ctrl.options[0].selected).to.be(true);
expect(ctrl.options[2].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() { 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() { describe('and then dropdown is opened and closed without changes', function() {
......
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