From 4a636b6da754f6cd2873639e026c01a4c2e1157c Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Tue, 9 Feb 2016 01:06:17 -0800 Subject: [PATCH] add, edit, remove filters functionality implemented --- .../datasource/opentsdb/config_ctrl.ts | 2 +- .../opentsdb/partials/query.editor.html | 24 ++++++--- .../plugins/datasource/opentsdb/query_ctrl.ts | 53 +++++++++++++++++++ 3 files changed, 70 insertions(+), 9 deletions(-) diff --git a/public/app/plugins/datasource/opentsdb/config_ctrl.ts b/public/app/plugins/datasource/opentsdb/config_ctrl.ts index bbf7ced7ef1..55fa14d7493 100644 --- a/public/app/plugins/datasource/opentsdb/config_ctrl.ts +++ b/public/app/plugins/datasource/opentsdb/config_ctrl.ts @@ -15,7 +15,7 @@ export class OpenTsConfigCtrl { tsdbVersions = [ {name: '<=2.1', value: 1}, - {name: '>=2.2', value: 2}, + {name: '2.2', value: 2}, ]; } diff --git a/public/app/plugins/datasource/opentsdb/partials/query.editor.html b/public/app/plugins/datasource/opentsdb/partials/query.editor.html index 6dab02441cc..f01d63f356c 100644 --- a/public/app/plugins/datasource/opentsdb/partials/query.editor.html +++ b/public/app/plugins/datasource/opentsdb/partials/query.editor.html @@ -87,12 +87,12 @@
  • Filters
  • -
  • - {{filter.type}}:{{filter.key}} = {{filter.value}}:{{filter.groupByFlag}} - +
  • + {{fil.tagk}} = {{fil.type}}({{fil.filter}}) , groupBy = {{fil.groupBy}} + - +
  • @@ -102,15 +102,23 @@ -
  • +
  • + Type + + spellcheck='false' bs-typeahead="ctrl.suggestTagValues" + data-min-length=0 data-items=100 ng-model="ctrl.target.currentFilterValue" placeholder="filter"> + + groupBy + add filter diff --git a/public/app/plugins/datasource/opentsdb/query_ctrl.ts b/public/app/plugins/datasource/opentsdb/query_ctrl.ts index fa8cb2baa55..0ab2cd911aa 100644 --- a/public/app/plugins/datasource/opentsdb/query_ctrl.ts +++ b/public/app/plugins/datasource/opentsdb/query_ctrl.ts @@ -19,6 +19,7 @@ export class OpenTsQueryCtrl extends QueryCtrl { suggestTagKeys: any; suggestTagValues: any; addTagMode: boolean; + addFilterMode: boolean; /** @ngInject **/ constructor($scope, $injector) { @@ -108,6 +109,58 @@ export class OpenTsQueryCtrl extends QueryCtrl { this.addTag(); } + addFilter() { + if (!this.addFilterMode) { + this.addFilterMode = true; + return; + } + + if (!this.target.filters) { + this.target.filters = []; + } + + if (!this.target.currentFilterType) { + this.target.currentFilterType = 'literal_or'; + } + + if (!this.target.currentFilterGroupBy) { + this.target.currentFilterGroupBy = false; + } + + this.errors = this.validateTarget(); + + if (!this.errors.filters) { + var currentFilter = { + type: this.target.currentFilterType, + tagk: this.target.currentFilterKey, + filter: this.target.currentFilterValue, + groupBy: this.target.currentFilterGroupBy + }; + this.target.filters.push(currentFilter); + this.target.currentFilterType = 'literal_or'; + this.target.currentFilterKey = ''; + this.target.currentFilterValue = ''; + this.target.currentFilterGroupBy = false; + this.targetBlur(); + } + + this.addFilterMode = false; + } + + removeFilter(index) { + this.target.filters.splice(index, 1); + this.targetBlur(); + } + + editFilter(fil, index) { + this.removeFilter(index); + this.target.currentFilterKey = fil.tagk; + this.target.currentFilterValue = fil.filter; + this.target.currentFilterType = fil.type; + this.target.currentFilterGroupBy = fil.groupBy; + this.addFilter(); + } + validateTarget() { var errs: any = {};