Commit b72eba1e by Anthony Woods

refactor handling of refresh when urlValues being used for templates. fixes #1862

parent b6a4db3f
...@@ -28,17 +28,11 @@ function (angular, _, kbn) { ...@@ -28,17 +28,11 @@ function (angular, _, kbn) {
for (var i = 0; i < this.variables.length; i++) { for (var i = 0; i < this.variables.length; i++) {
var variable = this.variables[i]; var variable = this.variables[i];
var urlValue = queryParams['var-' + variable.name]; var urlValue = queryParams['var-' + variable.name];
if (variable.refresh) {
promises.push(this.updateOptions(variable));
}
if (urlValue !== void 0) { if (urlValue !== void 0) {
var option = _.findWhere(variable.options, { text: urlValue }); promises.push(this.setVariableFromUrl(variable, urlValue));
option = option || { text: urlValue, value: urlValue }; }
else if (variable.refresh) {
var promise = this.setVariableValue(variable, option, true); promises.push(this.updateOptions(variable));
this.updateAutoInterval(variable);
promises.push(promise);
} }
else if (variable.type === 'interval') { else if (variable.type === 'interval') {
this.updateAutoInterval(variable); this.updateAutoInterval(variable);
...@@ -48,6 +42,25 @@ function (angular, _, kbn) { ...@@ -48,6 +42,25 @@ function (angular, _, kbn) {
return $q.all(promises); return $q.all(promises);
}; };
this.setVariableFromUrl = function(variable, urlValue) {
if (variable.refresh) {
var self = this;
//refresh the list of options before setting the value
return this.updateOptions(variable).then(function() {
var option = _.findWhere(variable.options, { text: urlValue });
option = option || { text: urlValue, value: urlValue };
self.updateAutoInterval(variable);
return self.setVariableValue(variable, option);
});
}
var option = _.findWhere(variable.options, { text: urlValue });
option = option || { text: urlValue, value: urlValue };
this.updateAutoInterval(variable);
return this.setVariableValue(variable, option);
};
this.updateAutoInterval = function(variable) { this.updateAutoInterval = function(variable) {
if (!variable.auto) { return; } if (!variable.auto) { return; }
......
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