From 024a3195121c7c6e13bda9552f29c12bc60c5647 Mon Sep 17 00:00:00 2001 From: ubhatnagar Date: Wed, 23 Sep 2015 11:22:57 +0530 Subject: [PATCH 1/3] Implemented Opentsdb MultiSelect Templating. --- public/app/features/templating/partials/editor.html | 2 +- public/app/features/templating/templateSrv.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/public/app/features/templating/partials/editor.html b/public/app/features/templating/partials/editor.html index a1dab0a6c36..98a966f5c42 100644 --- a/public/app/features/templating/partials/editor.html +++ b/public/app/features/templating/partials/editor.html @@ -217,7 +217,7 @@ Multi format
  • - +
  • diff --git a/public/app/features/templating/templateSrv.js b/public/app/features/templating/templateSrv.js index 0880df1a0c4..48aa4edde85 100644 --- a/public/app/features/templating/templateSrv.js +++ b/public/app/features/templating/templateSrv.js @@ -46,6 +46,9 @@ function (angular, _) { case "lucene": { return '(' + value.join(' OR ') + ')'; } + case "pipe": { + return value.join('|'); + } default: { return '{' + value.join(',') + '}'; } From 866f48f92db0131b374d0846d02e750944881433 Mon Sep 17 00:00:00 2001 From: ubhatnagar Date: Wed, 23 Sep 2015 13:12:35 +0530 Subject: [PATCH 2/3] Added pipe in All Format list. --- public/app/features/templating/partials/editor.html | 2 +- public/app/features/templating/templateValuesSrv.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/public/app/features/templating/partials/editor.html b/public/app/features/templating/partials/editor.html index 98a966f5c42..63ecd00adcf 100644 --- a/public/app/features/templating/partials/editor.html +++ b/public/app/features/templating/partials/editor.html @@ -186,7 +186,7 @@ All format
  • - +
  • diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index a3300853065..5ec9ae85e4a 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -271,6 +271,10 @@ function (angular, _, kbn) { }).join('|') + ')'; break; } + case 'pipe': { + allValue = _.pluck(variable.options, 'text').join('|'); + break; + } default: { allValue = '{'; allValue += _.pluck(variable.options, 'text').join(','); From 6f43cbf66596ea37dad7b5e56350310248a3f749 Mon Sep 17 00:00:00 2001 From: ubhatnagar Date: Wed, 23 Sep 2015 13:24:59 +0530 Subject: [PATCH 3/3] Added unit tests for all and multi format options. --- public/test/specs/templateSrv-specs.js | 10 ++++++++++ public/test/specs/templateValuesSrv-specs.js | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/public/test/specs/templateSrv-specs.js b/public/test/specs/templateSrv-specs.js index 1b43adff63e..36f303e55c6 100644 --- a/public/test/specs/templateSrv-specs.js +++ b/public/test/specs/templateSrv-specs.js @@ -81,6 +81,16 @@ define([ expect(result).to.be('(test|test2)'); }); + it('multi value and pipe should render pipe string', function() { + var result = _templateSrv.renderVariableValue({ + multiFormat: 'pipe', + current: { + value: ['test','test2'], + } + }); + expect(result).to.be('test|test2'); + }); + }); describe('can check if variable exists', function() { diff --git a/public/test/specs/templateValuesSrv-specs.js b/public/test/specs/templateValuesSrv-specs.js index feb13c37130..4c5b7e19a69 100644 --- a/public/test/specs/templateValuesSrv-specs.js +++ b/public/test/specs/templateValuesSrv-specs.js @@ -349,6 +349,17 @@ define([ }); }); + describeUpdateVariable('with include all pipe all values', function(scenario) { + scenario.setup(function() { + scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'pipe' }; + scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}]; + }); + + it('should add pipe delimited string', function() { + expect(scenario.variable.options[0].value).to.be('backend1|backend2|backend3'); + }); + }); + }); });