From 7d25d6f1915e56477504416584ccdf8f48ad5d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 28 May 2015 18:38:53 +0200 Subject: [PATCH] progress on tag selection in variable dropdown --- public/app/directives/variableValueSelect.js | 47 ++++++++++++++++++- .../partials/variableValueSelect.html | 8 +++- public/app/features/templating/editorCtrl.js | 1 - public/css/less/overrides.less | 2 +- public/css/less/submenu.less | 3 ++ 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/public/app/directives/variableValueSelect.js b/public/app/directives/variableValueSelect.js index e74564369c2..c22154f68a6 100644 --- a/public/app/directives/variableValueSelect.js +++ b/public/app/directives/variableValueSelect.js @@ -95,6 +95,12 @@ function (angular, app, _) { scope.search = {query: '', options: scope.options}; scope.selectedValuesCount = currentValues.length; + if (!scope.tags) { + scope.tags = _.map(variable.tags, function(value) { + return { text: value, selected: false }; + }); + } + scope.openDropdown(); }; @@ -158,11 +164,15 @@ function (angular, app, _) { setAllExceptCurrentTo(false); } + scope.selectionsChanged(option, commitChange); + }; + + scope.selectionsChanged = function(defaultItem, commitChange) { var selected = _.filter(scope.options, {selected: true}); if (selected.length === 0) { - option.selected = true; - selected = [option]; + defaultItem.selected = true; + selected = [defaultItem]; } if (selected.length > 1 && selected.length !== scope.options.length) { @@ -177,6 +187,18 @@ function (angular, app, _) { value: _.pluck(selected, 'value'), }; + var valuesNotInTag = _.filter(selected, function(test) { + for (var i = 0; i < scope.selectedTags.length; i++) { + var tag = scope.selectedTags[i]; + if (_.indexOf(tag.values, test.value) !== -1) { + return false; + } + } + return true; + }); + + variable.current.text = _.pluck(valuesNotInTag, 'text').join(', '); + scope.selectedValuesCount = variable.current.value.length; // only single value @@ -189,6 +211,27 @@ function (angular, app, _) { } }; + scope.selectTag = function(tag) { + tag.selected = !tag.selected; + if (!tag.values) { + if (tag.text === 'backend') { + tag.values = ['backend_01', 'backend_02', 'backend_03', 'backend_04']; + } else { + tag.values = ['web_server_01', 'web_server_02', 'web_server_03', 'web_server_04']; + } + console.log('querying for tag values'); + } + + _.each(scope.options, function(option) { + if (_.indexOf(tag.values, option.value) !== -1) { + option.selected = tag.selected; + } + }); + + scope.selectedTags = _.filter(scope.tags, {selected: true}); + scope.selectionsChanged(scope.options[0], false); + }; + scope.updateLinkText = function() { scope.labelText = variable.label || '$' + variable.name; scope.linkText = variable.current.text; diff --git a/public/app/features/dashboard/partials/variableValueSelect.html b/public/app/features/dashboard/partials/variableValueSelect.html index de22c9cc54e..bb4f0ac03e6 100644 --- a/public/app/features/dashboard/partials/variableValueSelect.html +++ b/public/app/features/dashboard/partials/variableValueSelect.html @@ -5,6 +5,10 @@
{{linkText}} + + {{tag.text}} +     + @@ -22,9 +26,9 @@
Tags
- + - {{tag}}    + {{tag.text}}   
diff --git a/public/app/features/templating/editorCtrl.js b/public/app/features/templating/editorCtrl.js index aeb27b3c832..f48452e4569 100644 --- a/public/app/features/templating/editorCtrl.js +++ b/public/app/features/templating/editorCtrl.js @@ -82,7 +82,6 @@ function (angular, _) { }; $scope.update = function() { - $scope.current.tags = []; if ($scope.isValid()) { $scope.runQuery().then(function() { $scope.reset(); diff --git a/public/css/less/overrides.less b/public/css/less/overrides.less index b03cb7f7e6b..6ac6a385b60 100644 --- a/public/css/less/overrides.less +++ b/public/css/less/overrides.less @@ -542,7 +542,7 @@ div.flot-text { background-color: @purple; color: darken(@white, 5%); white-space: nowrap; - border-radius: 2px; + border-radius: 3px; text-shadow: none; font-size: 13px; padding: 2px 6px; diff --git a/public/css/less/submenu.less b/public/css/less/submenu.less index cbdff413a0b..e2d6b0639dd 100644 --- a/public/css/less/submenu.less +++ b/public/css/less/submenu.less @@ -39,6 +39,9 @@ .variable-value-link { font-size: 16px; padding-right: 10px; + .label-tag { + margin: 0 5px; + } } .variable-value-dropdown {