From 8af3bb739c1050656e853eedc4d9aa12bacd86e8 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Sun, 26 Jun 2016 22:15:57 +0900 Subject: [PATCH] refactor --- .../features/templating/templateValuesSrv.js | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index 38f305f3f40..cd74c2b665f 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -359,29 +359,29 @@ function (angular, _, kbn) { } options = _.uniq(options, 'value'); - var sortType = Math.ceil(variable.sort / 2); - if (sortType === 0) { - return options; - } else { - 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 (variable.sort % 2 === 0) { - options = options.reverse(); - } - + if (variable.sort === 0) { return options; } + + 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) {