|
@@ -10,23 +10,72 @@ function (angular, app, _) {
|
|
|
angular
|
|
angular
|
|
|
.module('grafana.directives')
|
|
.module('grafana.directives')
|
|
|
.directive('variableValueSelect', function($compile, $window, $timeout) {
|
|
.directive('variableValueSelect', function($compile, $window, $timeout) {
|
|
|
|
|
+
|
|
|
|
|
+ function openDropdown(inputEl, linkEl) {
|
|
|
|
|
+ inputEl.css('width', (linkEl.width() + 16) + 'px');
|
|
|
|
|
+
|
|
|
|
|
+ linkEl.hide();
|
|
|
|
|
+ inputEl.show();
|
|
|
|
|
+ inputEl.focus();
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
scope: {
|
|
scope: {
|
|
|
variable: "=",
|
|
variable: "=",
|
|
|
onUpdated: "&"
|
|
onUpdated: "&"
|
|
|
},
|
|
},
|
|
|
|
|
+
|
|
|
templateUrl: 'app/features/dashboard/partials/variableValueSelect.html',
|
|
templateUrl: 'app/features/dashboard/partials/variableValueSelect.html',
|
|
|
|
|
+
|
|
|
link: function(scope, elem) {
|
|
link: function(scope, elem) {
|
|
|
var bodyEl = angular.element($window.document.body);
|
|
var bodyEl = angular.element($window.document.body);
|
|
|
|
|
+ var linkEl = elem.find('.variable-value-link');
|
|
|
|
|
+ var inputEl = elem.find('input');
|
|
|
var variable = scope.variable;
|
|
var variable = scope.variable;
|
|
|
|
|
+ var cancelBlur = null;
|
|
|
|
|
|
|
|
- scope.show = function() {
|
|
|
|
|
- if (scope.selectorOpen) {
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ scope.openDropdown = function() {
|
|
|
|
|
+ inputEl.show();
|
|
|
|
|
+ linkEl.hide();
|
|
|
|
|
+ scope.dropdownVisible = true;
|
|
|
|
|
+
|
|
|
|
|
+ inputEl.css('width', (linkEl.width() + 16) + 'px');
|
|
|
|
|
+
|
|
|
|
|
+ linkEl.hide();
|
|
|
|
|
+ inputEl.show();
|
|
|
|
|
+ inputEl.focus();
|
|
|
|
|
+
|
|
|
|
|
+ $timeout(function() { bodyEl.on('click', scope.bodyOnClick); }, 0, false);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ scope.switchToLink = function(now) {
|
|
|
|
|
+ if (now === true || cancelBlur) {
|
|
|
|
|
+ clearTimeout(cancelBlur);
|
|
|
|
|
+ cancelBlur = null;
|
|
|
|
|
+ inputEl.hide();
|
|
|
|
|
+ linkEl.show();
|
|
|
|
|
+ scope.dropdownVisible = false;
|
|
|
|
|
+ scope.$digest();
|
|
|
|
|
+
|
|
|
|
|
+ scope.updateLinkText();
|
|
|
|
|
+ scope.onUpdated();
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ // need to have long delay because the blur
|
|
|
|
|
+ // happens long before the click event on the typeahead options
|
|
|
|
|
+ cancelBlur = setTimeout(scope.switchToLink, 50);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- scope.selectorOpen = true;
|
|
|
|
|
- scope.giveFocus = 1;
|
|
|
|
|
|
|
+ bodyEl.off('click', scope.bodyOnClick);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ scope.bodyOnClick = function(e) {
|
|
|
|
|
+ if (elem.has(e.target).length === 0) {
|
|
|
|
|
+ scope.switchToLink();
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ scope.show = function() {
|
|
|
scope.oldCurrentText = variable.current.text;
|
|
scope.oldCurrentText = variable.current.text;
|
|
|
scope.highlightIndex = -1;
|
|
scope.highlightIndex = -1;
|
|
|
|
|
|
|
@@ -45,9 +94,7 @@ function (angular, app, _) {
|
|
|
|
|
|
|
|
scope.search = {query: '', options: scope.options};
|
|
scope.search = {query: '', options: scope.options};
|
|
|
|
|
|
|
|
- $timeout(function() {
|
|
|
|
|
- bodyEl.on('click', scope.bodyOnClick);
|
|
|
|
|
- }, 0, false);
|
|
|
|
|
|
|
+ scope.openDropdown();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
scope.queryChanged = function() {
|
|
scope.queryChanged = function() {
|
|
@@ -79,7 +126,7 @@ function (angular, app, _) {
|
|
|
scope.optionSelected = function(option, event) {
|
|
scope.optionSelected = function(option, event) {
|
|
|
option.selected = !option.selected;
|
|
option.selected = !option.selected;
|
|
|
|
|
|
|
|
- var hideAfter = true;
|
|
|
|
|
|
|
+ var hideAfter = false;
|
|
|
var setAllExceptCurrentTo = function(newValue) {
|
|
var setAllExceptCurrentTo = function(newValue) {
|
|
|
_.each(scope.options, function(other) {
|
|
_.each(scope.options, function(other) {
|
|
|
if (option !== other) { other.selected = newValue; }
|
|
if (option !== other) { other.selected = newValue; }
|
|
@@ -91,13 +138,10 @@ function (angular, app, _) {
|
|
|
}
|
|
}
|
|
|
else if (!variable.multi) {
|
|
else if (!variable.multi) {
|
|
|
setAllExceptCurrentTo(false);
|
|
setAllExceptCurrentTo(false);
|
|
|
- } else {
|
|
|
|
|
- if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
|
|
|
- hideAfter = false;
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- setAllExceptCurrentTo(false);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ hideAfter = true;
|
|
|
|
|
+ } else if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
|
|
|
+ hideAfter = true;
|
|
|
|
|
+ setAllExceptCurrentTo(false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var selected = _.filter(scope.options, {selected: true});
|
|
var selected = _.filter(scope.options, {selected: true});
|
|
@@ -124,23 +168,8 @@ function (angular, app, _) {
|
|
|
variable.current.value = selected[0].value;
|
|
variable.current.value = selected[0].value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- scope.updateLinkText();
|
|
|
|
|
- scope.onUpdated();
|
|
|
|
|
-
|
|
|
|
|
if (hideAfter) {
|
|
if (hideAfter) {
|
|
|
- scope.hide();
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- scope.hide = function() {
|
|
|
|
|
- scope.selectorOpen = false;
|
|
|
|
|
- bodyEl.off('click', scope.bodyOnClick);
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- scope.bodyOnClick = function(e) {
|
|
|
|
|
- var dropdown = elem.find('.variable-value-dropdown');
|
|
|
|
|
- if (dropdown.has(e.target).length === 0) {
|
|
|
|
|
- scope.$apply(scope.hide);
|
|
|
|
|
|
|
+ scope.switchToLink();
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -152,6 +181,9 @@ function (angular, app, _) {
|
|
|
scope.$watchGroup(['variable.hideLabel', 'variable.name', 'variable.label', 'variable.current.text'], function() {
|
|
scope.$watchGroup(['variable.hideLabel', 'variable.name', 'variable.label', 'variable.current.text'], function() {
|
|
|
scope.updateLinkText();
|
|
scope.updateLinkText();
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ linkEl.click(scope.openDropdown);
|
|
|
|
|
+ //inputEl.blur(scope.switchToLink);
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
});
|
|
});
|