mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge branch 'v3.0.x'
Conflicts: public/app/features/templating/templateValuesSrv.js
This commit is contained in:
commit
696fad702f
@ -105,8 +105,6 @@ function (angular, _, kbn) {
|
|||||||
return op.text === urlValue || op.value === urlValue;
|
return op.text === urlValue || op.value === urlValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
option = option || { text: urlValue, value: urlValue };
|
|
||||||
|
|
||||||
self.updateAutoInterval(variable);
|
self.updateAutoInterval(variable);
|
||||||
return self.setVariableValue(variable, option, true);
|
return self.setVariableValue(variable, option, true);
|
||||||
});
|
});
|
||||||
@ -127,8 +125,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)) {
|
if (_.isArray(variable.current.text)) {
|
||||||
variable.current.text = variable.current.value.join(' + ');
|
variable.current.text = variable.current.text.join(' + ');
|
||||||
}
|
}
|
||||||
|
|
||||||
self.selectOptionsForCurrentValue(variable);
|
self.selectOptionsForCurrentValue(variable);
|
||||||
@ -226,6 +224,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];
|
||||||
@ -235,12 +234,16 @@ 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) {
|
||||||
@ -250,17 +253,18 @@ function (angular, _, kbn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_.isArray(variable.current.value)) {
|
if (_.isArray(variable.current.value)) {
|
||||||
self.selectOptionsForCurrentValue(variable);
|
var selected = self.selectOptionsForCurrentValue(variable);
|
||||||
// updated selected value
|
|
||||||
var selected = {
|
|
||||||
value: _.map(_.filter(variable.options, {selected: true}), function(op) {
|
|
||||||
return op.value;
|
|
||||||
})
|
|
||||||
};
|
|
||||||
// if none pick first
|
// if none pick first
|
||||||
if (selected.value.length === 0) {
|
if (selected.length === 0) {
|
||||||
selected = variable.options[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);
|
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});
|
||||||
|
@ -166,6 +166,27 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describeUpdateVariable('query variable with multi select and $__all selected', function(scenario) {
|
||||||
|
scenario.setup(function() {
|
||||||
|
scenario.variable = {
|
||||||
|
type: 'query',
|
||||||
|
query: '',
|
||||||
|
name: 'test',
|
||||||
|
includeAll: true,
|
||||||
|
current: {
|
||||||
|
value: ['$__all'],
|
||||||
|
text: 'All'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
scenario.queryResult = [{text: 'val5'}, {text: 'val6'}];
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should keep current All value', function() {
|
||||||
|
expect(scenario.variable.current.value).to.eql(['$__all']);
|
||||||
|
expect(scenario.variable.current.text).to.eql('All');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describeUpdateVariable('query variable with numeric results', function(scenario) {
|
describeUpdateVariable('query variable with numeric results', function(scenario) {
|
||||||
scenario.setup(function() {
|
scenario.setup(function() {
|
||||||
scenario.variable = { type: 'query', query: '', name: 'test', current: {} };
|
scenario.variable = { type: 'query', query: '', name: 'test', current: {} };
|
||||||
|
Loading…
Reference in New Issue
Block a user