|
@@ -79,7 +79,6 @@ function (angular, _, kbn) {
|
|
|
else if (variable.refresh === 1 || variable.refresh === 2) {
|
|
else if (variable.refresh === 1 || variable.refresh === 2) {
|
|
|
return self.updateOptions(variable).then(function() {
|
|
return self.updateOptions(variable).then(function() {
|
|
|
if (_.isEmpty(variable.current) && variable.options.length) {
|
|
if (_.isEmpty(variable.current) && variable.options.length) {
|
|
|
- console.log("setting current for %s", variable.name);
|
|
|
|
|
self.setVariableValue(variable, variable.options[0]);
|
|
self.setVariableValue(variable, variable.options[0]);
|
|
|
}
|
|
}
|
|
|
lock.resolve();
|
|
lock.resolve();
|
|
@@ -102,7 +101,10 @@ function (angular, _, kbn) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return promise.then(function() {
|
|
return promise.then(function() {
|
|
|
- var option = _.findWhere(variable.options, { text: urlValue });
|
|
|
|
|
|
|
+ var option = _.find(variable.options, function(op) {
|
|
|
|
|
+ return op.text === urlValue || op.value === urlValue;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
option = option || { text: urlValue, value: urlValue };
|
|
option = option || { text: urlValue, value: urlValue };
|
|
|
|
|
|
|
|
self.updateAutoInterval(variable);
|
|
self.updateAutoInterval(variable);
|
|
@@ -125,8 +127,8 @@ function (angular, _, kbn) {
|
|
|
this.setVariableValue = function(variable, option, initPhase) {
|
|
this.setVariableValue = function(variable, option, initPhase) {
|
|
|
variable.current = angular.copy(option);
|
|
variable.current = angular.copy(option);
|
|
|
|
|
|
|
|
- if (_.isArray(variable.current.value)) {
|
|
|
|
|
- variable.current.text = variable.current.value.join(' + ');
|
|
|
|
|
|
|
+ if (_.isArray(variable.current.text)) {
|
|
|
|
|
+ variable.current.text = variable.current.text.join(' + ');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
self.selectOptionsForCurrentValue(variable);
|
|
self.selectOptionsForCurrentValue(variable);
|
|
@@ -166,6 +168,11 @@ function (angular, _, kbn) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (variable.type === 'constant') {
|
|
|
|
|
+ variable.options = [{text: variable.query, value: variable.query}];
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// extract options in comma seperated string
|
|
// extract options in comma seperated string
|
|
|
variable.options = _.map(variable.query.split(/[,]+/), function(text) {
|
|
variable.options = _.map(variable.query.split(/[,]+/), function(text) {
|
|
|
return { text: text.trim(), value: text.trim() };
|
|
return { text: text.trim(), value: text.trim() };
|
|
@@ -173,6 +180,7 @@ function (angular, _, kbn) {
|
|
|
|
|
|
|
|
if (variable.type === 'interval') {
|
|
if (variable.type === 'interval') {
|
|
|
self.updateAutoInterval(variable);
|
|
self.updateAutoInterval(variable);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (variable.type === 'custom' && variable.includeAll) {
|
|
if (variable.type === 'custom' && variable.includeAll) {
|
|
@@ -224,6 +232,7 @@ function (angular, _, kbn) {
|
|
|
|
|
|
|
|
this.selectOptionsForCurrentValue = function(variable) {
|
|
this.selectOptionsForCurrentValue = function(variable) {
|
|
|
var i, y, value, option;
|
|
var i, y, value, option;
|
|
|
|
|
+ var selected = [];
|
|
|
|
|
|
|
|
for (i = 0; i < variable.options.length; i++) {
|
|
for (i = 0; i < variable.options.length; i++) {
|
|
|
option = variable.options[i];
|
|
option = variable.options[i];
|
|
@@ -233,28 +242,44 @@ function (angular, _, kbn) {
|
|
|
value = variable.current.value[y];
|
|
value = variable.current.value[y];
|
|
|
if (option.value === value) {
|
|
if (option.value === value) {
|
|
|
option.selected = true;
|
|
option.selected = true;
|
|
|
|
|
+ selected.push(option);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else if (option.value === variable.current.value) {
|
|
} else if (option.value === variable.current.value) {
|
|
|
option.selected = true;
|
|
option.selected = true;
|
|
|
|
|
+ selected.push(option);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ return selected;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
this.validateVariableSelectionState = function(variable) {
|
|
this.validateVariableSelectionState = function(variable) {
|
|
|
if (!variable.current) {
|
|
if (!variable.current) {
|
|
|
if (!variable.options.length) { return; }
|
|
if (!variable.options.length) { return; }
|
|
|
- return self.setVariableValue(variable, variable.options[0], true);
|
|
|
|
|
|
|
+ return self.setVariableValue(variable, variable.options[0], false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (_.isArray(variable.current.value)) {
|
|
if (_.isArray(variable.current.value)) {
|
|
|
- self.selectOptionsForCurrentValue(variable);
|
|
|
|
|
|
|
+ var selected = self.selectOptionsForCurrentValue(variable);
|
|
|
|
|
+
|
|
|
|
|
+ // if none pick first
|
|
|
|
|
+ if (selected.length === 0) {
|
|
|
|
|
+ selected = variable.options[0];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ selected = {
|
|
|
|
|
+ value: _.map(selected, function(val) {return val.value;}),
|
|
|
|
|
+ text: _.map(selected, function(val) {return val.text;}).join(' + '),
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return self.setVariableValue(variable, selected, false);
|
|
|
} else {
|
|
} else {
|
|
|
var currentOption = _.findWhere(variable.options, {text: variable.current.text});
|
|
var currentOption = _.findWhere(variable.options, {text: variable.current.text});
|
|
|
if (currentOption) {
|
|
if (currentOption) {
|
|
|
- return self.setVariableValue(variable, currentOption, true);
|
|
|
|
|
|
|
+ return self.setVariableValue(variable, currentOption, false);
|
|
|
} else {
|
|
} else {
|
|
|
- if (!variable.options.length) { return; }
|
|
|
|
|
|
|
+ if (!variable.options.length) { return $q.when(null); }
|
|
|
return self.setVariableValue(variable, variable.options[0]);
|
|
return self.setVariableValue(variable, variable.options[0]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -313,6 +338,14 @@ function (angular, _, kbn) {
|
|
|
var value = item.value || item.text;
|
|
var value = item.value || item.text;
|
|
|
var text = item.text || item.value;
|
|
var text = item.text || item.value;
|
|
|
|
|
|
|
|
|
|
+ if (_.isNumber(value)) {
|
|
|
|
|
+ value = value.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (_.isNumber(text)) {
|
|
|
|
|
+ text = text.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (regex) {
|
|
if (regex) {
|
|
|
matches = regex.exec(value);
|
|
matches = regex.exec(value);
|
|
|
if (!matches) { continue; }
|
|
if (!matches) { continue; }
|