mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge branch 'template_sort' of https://github.com/mtanda/grafana into mtanda-template_sort
This commit is contained in:
@@ -13,6 +13,7 @@ function (angular, _) {
|
||||
type: 'query',
|
||||
datasource: null,
|
||||
refresh: 0,
|
||||
sort: 1,
|
||||
name: '',
|
||||
hide: 0,
|
||||
options: [],
|
||||
@@ -34,6 +35,14 @@ function (angular, _) {
|
||||
{value: 2, text: "On Time Range Change"},
|
||||
];
|
||||
|
||||
$scope.sortOptions = [
|
||||
{value: 0, text: "Without Sort"},
|
||||
{value: 1, text: "Alphabetical (asc)"},
|
||||
{value: 2, text: "Alphabetical (desc)"},
|
||||
{value: 3, text: "Numerical (asc)"},
|
||||
{value: 4, text: "Numerical (desc)"},
|
||||
];
|
||||
|
||||
$scope.hideOptions = [
|
||||
{value: 0, text: ""},
|
||||
{value: 1, text: "Label"},
|
||||
|
||||
@@ -181,6 +181,17 @@
|
||||
<select class="gf-form-input" ng-model="current.refresh" ng-options="f.value as f.text for f in refreshOptions"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gf-form max-width-21">
|
||||
<span class="gf-form-label width-7">
|
||||
Sort
|
||||
<info-popover mode="right-normal">
|
||||
How to sort the values of this variable.
|
||||
</info-popover>
|
||||
</span>
|
||||
<div class="gf-form-select-wrapper max-width-14">
|
||||
<select class="gf-form-input" ng-model="current.sort" ng-options="f.value as f.text for f in sortOptions" ng-change="runQuery()"></select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gf-form">
|
||||
<span class="gf-form-label width-7">Query</span>
|
||||
|
||||
@@ -342,7 +342,7 @@ function (angular, _, $, kbn) {
|
||||
|
||||
this.metricNamesToVariableValues = function(variable, metricNames) {
|
||||
var regex, options, i, matches;
|
||||
options = {}; // use object hash to remove duplicates
|
||||
options = [];
|
||||
|
||||
if (variable.regex) {
|
||||
regex = kbn.stringToJsRegex(templateSrv.replace(variable.regex));
|
||||
@@ -370,10 +370,33 @@ function (angular, _, $, kbn) {
|
||||
}
|
||||
}
|
||||
|
||||
options[value] = {text: text, value: value};
|
||||
options.push({text: text, value: value});
|
||||
}
|
||||
options = _.uniq(options, 'value');
|
||||
|
||||
if (variable.sort === 0) {
|
||||
return options;
|
||||
}
|
||||
|
||||
return _.sortBy(options, 'text');
|
||||
var sortType = Math.ceil(variable.sort / 2);
|
||||
var reverseSort = (variable.sort % 2 === 0);
|
||||
if (sortType === 1) {
|
||||
options = _.sortBy(options, 'text');
|
||||
} else if (sortType === 2) {
|
||||
options = _.sortBy(options, function(opt) {
|
||||
var matches = opt.text.match(/.*?(\d+).*/);
|
||||
if (!matches) {
|
||||
return 0;
|
||||
} else {
|
||||
return parseInt(matches[1], 10);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (reverseSort) {
|
||||
options = options.reverse();
|
||||
}
|
||||
|
||||
return options;
|
||||
};
|
||||
|
||||
this.addAllOption = function(variable) {
|
||||
|
||||
Reference in New Issue
Block a user