Commit 244cbe8c by Mitsuhiro Tanda

add csv templating format

parent 310d7406
...@@ -107,7 +107,6 @@ describe('templateSrv', function() { ...@@ -107,7 +107,6 @@ describe('templateSrv', function() {
]); ]);
}); });
it('should replace $test with globbed value', function() { it('should replace $test with globbed value', function() {
var target = _templateSrv.replace('this.$test.filters', {}, 'glob'); var target = _templateSrv.replace('this.$test.filters', {}, 'glob');
expect(target).toBe('this.{value1,value2}.filters'); expect(target).toBe('this.{value1,value2}.filters');
...@@ -261,6 +260,11 @@ describe('templateSrv', function() { ...@@ -261,6 +260,11 @@ describe('templateSrv', function() {
expect(result).toBe('test'); expect(result).toBe('test');
}); });
it('multi value and csv format should render csv string', function() {
var result = _templateSrv.formatValue(['test', 'test2'], 'csv');
expect(result).toBe('test,test2');
});
it('slash should be properly escaped in regex format', function() { it('slash should be properly escaped in regex format', function() {
var result = _templateSrv.formatValue('Gi3/14', 'regex'); var result = _templateSrv.formatValue('Gi3/14', 'regex');
expect(result).toBe('Gi3\\/14'); expect(result).toBe('Gi3\\/14');
......
...@@ -115,6 +115,12 @@ export class TemplateSrv { ...@@ -115,6 +115,12 @@ export class TemplateSrv {
} }
return this.distributeVariable(value, variable.name); return this.distributeVariable(value, variable.name);
} }
case 'csv': {
if (_.isArray(value)) {
return value.join(',');
}
return value;
}
default: { default: {
if (_.isArray(value)) { if (_.isArray(value)) {
return '{' + value.join(',') + '}'; return '{' + value.join(',') + '}';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment