diff --git a/public/app/directives/all.js b/public/app/directives/all.js
index 0a9ac603c57..13a8accffbd 100644
--- a/public/app/directives/all.js
+++ b/public/app/directives/all.js
@@ -11,7 +11,7 @@ define([
'./spectrumPicker',
'./tags',
'./bodyClass',
- './selectDropDown',
+ './valueSelectDropdown',
'./metric.segment',
'./grafanaVersionCheck',
'./dropdown.typeahead',
diff --git a/public/app/directives/selectDropDown.js b/public/app/directives/valueSelectDropdown.js
similarity index 94%
rename from public/app/directives/selectDropDown.js
rename to public/app/directives/valueSelectDropdown.js
index 312b6cdd7d1..14791eba0f3 100644
--- a/public/app/directives/selectDropDown.js
+++ b/public/app/directives/valueSelectDropdown.js
@@ -9,7 +9,7 @@ function (angular, app, _) {
angular
.module('grafana.controllers')
- .controller('SelectDropdownCtrl', function($q) {
+ .controller('ValueSelectDropdownCtrl', function($q) {
var vm = this;
vm.show = function() {
@@ -31,7 +31,13 @@ function (angular, app, _) {
vm.selectedValues = _.filter(vm.options, {selected: true});
vm.tags = _.map(vm.variable.tags, function(value) {
- return { text: value, selected: false };
+ var tag = { text: value, selected: false };
+ _.each(vm.variable.current.tags, function(tagObj) {
+ if (tagObj.text === value) {
+ tag.selected = true;
+ }
+ });
+ return tag;
});
vm.search = {query: '', options: vm.options};
@@ -225,12 +231,12 @@ function (angular, app, _) {
angular
.module('grafana.directives')
- .directive('selectDropdown', function($compile, $window, $timeout) {
+ .directive('valueSelectDropdown', function($compile, $window, $timeout) {
return {
scope: { variable: "=", onUpdated: "&", getValuesForTag: "&" },
- templateUrl: 'app/partials/selectDropdown.html',
- controller: 'SelectDropdownCtrl',
+ templateUrl: 'app/partials/valueSelectDropdown.html',
+ controller: 'ValueSelectDropdownCtrl',
controllerAs: 'vm',
bindToController: true,
link: function(scope, elem) {
diff --git a/public/app/partials/submenu.html b/public/app/partials/submenu.html
index 0246d4a7673..2feec7edbca 100644
--- a/public/app/partials/submenu.html
+++ b/public/app/partials/submenu.html
@@ -6,7 +6,7 @@
{{variable.label || variable.name}}:
-
+
diff --git a/public/app/partials/selectDropdown.html b/public/app/partials/valueSelectDropdown.html
similarity index 100%
rename from public/app/partials/selectDropdown.html
rename to public/app/partials/valueSelectDropdown.html
diff --git a/public/test/specs/selectDropdownCtrl-specs.js b/public/test/specs/valueSelectDropdown-specs.js
similarity index 83%
rename from public/test/specs/selectDropdownCtrl-specs.js
rename to public/test/specs/valueSelectDropdown-specs.js
index 3aae3429a7c..9fadb893467 100644
--- a/public/test/specs/selectDropdownCtrl-specs.js
+++ b/public/test/specs/valueSelectDropdown-specs.js
@@ -1,5 +1,5 @@
define([
- 'directives/variableValueSelect',
+ 'directives/valueSelectDropdown',
],
function () {
'use strict';
@@ -15,7 +15,7 @@ function () {
beforeEach(inject(function($controller, $rootScope, $q) {
rootScope = $rootScope;
scope = $rootScope.$new();
- ctrl = $controller('SelectDropdownCtrl', {$scope: scope});
+ ctrl = $controller('ValueSelectDropdownCtrl', {$scope: scope});
ctrl.getValuesForTag = function(obj) {
return $q.when(tagValuesMap[obj.tagKey]);
};
@@ -134,5 +134,28 @@ function () {
});
});
});
+
+ describe("Given variable with selected tags", function() {
+ beforeEach(function() {
+ ctrl.variable = {
+ current: {text: 'server-1', value: 'server-1', tags: [{text: 'key1'}] },
+ options: [
+ {text: 'server-1', value: 'server-1'},
+ {text: 'server-2', value: 'server-2'},
+ {text: 'server-3', value: 'server-3'},
+ ],
+ tags: ["key1", "key2", "key3"],
+ multi: true
+ };
+ ctrl.init();
+ ctrl.show();
+ });
+
+ it("should set tag as selected", function() {
+ expect(ctrl.tags[0].selected).to.be(true);
+ });
+
+ });
+
});
});
diff --git a/public/test/test-main.js b/public/test/test-main.js
index 6b62df02102..bbc6b239fa0 100644
--- a/public/test/test-main.js
+++ b/public/test/test-main.js
@@ -144,7 +144,7 @@ require([
'specs/singlestat-specs',
'specs/dynamicDashboardSrv-specs',
'specs/unsavedChangesSrv-specs',
- 'specs/selectDropdownCtrl-specs',
+ 'specs/valueSelectDropdown-specs',
];
var pluginSpecs = (config.plugins.specs || []).map(function (spec) {