Просмотр исходного кода

Merge pull request #2808 from utkarshcmu/master

Implemented Opentsdb MultiSelect Templating.
Torkel Ödegaard 10 лет назад
Родитель
Сommit
71984b25e9

+ 2 - 2
public/app/features/templating/partials/editor.html

@@ -186,7 +186,7 @@
 									All format
 									All format
 								</li>
 								</li>
 								<li ng-show="current.includeAll">
 								<li ng-show="current.includeAll">
-									<select class="input-medium tight-form-input last" ng-model="current.allFormat" ng-change="runQuery()" ng-options="f for f in ['glob', 'wildcard', 'regex wildcard', 'regex values', 'lucene']"></select>
+									<select class="input-medium tight-form-input last" ng-model="current.allFormat" ng-change="runQuery()" ng-options="f for f in ['glob', 'wildcard', 'regex wildcard', 'regex values', 'lucene', 'pipe']"></select>
 								</li>
 								</li>
 							</ul>
 							</ul>
 							<div class="clearfix"></div>
 							<div class="clearfix"></div>
@@ -217,7 +217,7 @@
 								Multi format
 								Multi format
 							</li>
 							</li>
 							<li ng-show="current.multi">
 							<li ng-show="current.multi">
-								<select class="input-medium tight-form-input last" ng-model="current.multiFormat" ng-change="runQuery()" ng-options="f for f in ['glob', 'regex values', 'lucene']"></select>
+								<select class="input-medium tight-form-input last" ng-model="current.multiFormat" ng-change="runQuery()" ng-options="f for f in ['glob', 'regex values', 'lucene', 'pipe']"></select>
 							</li>
 							</li>
 						</ul>
 						</ul>
 						<div class="clearfix"></div>
 						<div class="clearfix"></div>

+ 3 - 0
public/app/features/templating/templateSrv.js

@@ -46,6 +46,9 @@ function (angular, _) {
           case "lucene": {
           case "lucene": {
             return '(' + value.join(' OR ') + ')';
             return '(' + value.join(' OR ') + ')';
           }
           }
+          case "pipe": {
+            return value.join('|');
+          }
           default:  {
           default:  {
             return '{' + value.join(',') + '}';
             return '{' + value.join(',') + '}';
           }
           }

+ 4 - 0
public/app/features/templating/templateValuesSrv.js

@@ -271,6 +271,10 @@ function (angular, _, kbn) {
           }).join('|') + ')';
           }).join('|') + ')';
           break;
           break;
         }
         }
+        case 'pipe': {
+          allValue = _.pluck(variable.options, 'text').join('|');
+          break;
+        }
         default: {
         default: {
           allValue = '{';
           allValue = '{';
           allValue += _.pluck(variable.options, 'text').join(',');
           allValue += _.pluck(variable.options, 'text').join(',');

+ 10 - 0
public/test/specs/templateSrv-specs.js

@@ -81,6 +81,16 @@ define([
         expect(result).to.be('(test|test2)');
         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() {
     describe('can check if variable exists', function() {

+ 11 - 0
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');
+      });
+    });
+
   });
   });
 
 
 });
 });