Skip to content

Commit 03fb152

Browse files
committed
tech(templates): extract sort method
1 parent 9c5436c commit 03fb152

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

public/app/features/templating/templateValuesSrv.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,20 @@ function (angular, _, $, kbn) {
374374
}
375375
options = _.uniq(options, 'value');
376376

377-
if (variable.sort === 0) {
377+
return this.sortVariableValues(options, variable.sort);
378+
};
379+
380+
this.addAllOption = function(variable) {
381+
variable.options.unshift({text: 'All', value: "$__all"});
382+
};
383+
384+
this.sortVariableValues = function(options, sortOrder) {
385+
if (sortOrder === 0) {
378386
return options;
379387
}
380388

381-
var sortType = Math.ceil(variable.sort / 2);
382-
var reverseSort = (variable.sort % 2 === 0);
389+
var sortType = Math.ceil(sortOrder / 2);
390+
var reverseSort = (sortOrder % 2 === 0);
383391
if (sortType === 1) {
384392
options = _.sortBy(options, 'text');
385393
} else if (sortType === 2) {
@@ -399,10 +407,6 @@ function (angular, _, $, kbn) {
399407
return options;
400408
};
401409

402-
this.addAllOption = function(variable) {
403-
variable.options.unshift({text: 'All', value: "$__all"});
404-
};
405-
406410
});
407411

408412
});

0 commit comments

Comments
 (0)