From 03fb152d4b323c08ce216222a26f52f327bfca95 Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 13 Sep 2016 08:11:04 +0200 Subject: [PATCH] tech(templates): extract sort method --- .../features/templating/templateValuesSrv.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index 1059d1a19c4..6125a4b44a9 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -374,12 +374,20 @@ function (angular, _, $, kbn) { } options = _.uniq(options, 'value'); - if (variable.sort === 0) { + return this.sortVariableValues(options, variable.sort); + }; + + this.addAllOption = function(variable) { + variable.options.unshift({text: 'All', value: "$__all"}); + }; + + this.sortVariableValues = function(options, sortOrder) { + if (sortOrder === 0) { return options; } - var sortType = Math.ceil(variable.sort / 2); - var reverseSort = (variable.sort % 2 === 0); + var sortType = Math.ceil(sortOrder / 2); + var reverseSort = (sortOrder % 2 === 0); if (sortType === 1) { options = _.sortBy(options, 'text'); } else if (sortType === 2) { @@ -399,10 +407,6 @@ function (angular, _, $, kbn) { return options; }; - this.addAllOption = function(variable) { - variable.options.unshift({text: 'All', value: "$__all"}); - }; - }); });