From 7d3146ed8d45a8d67a1381821a39cd6e5d2a59ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 5 Nov 2015 08:36:51 +0100 Subject: [PATCH] feat(tablepanel): fixed header, and pagination styling --- public/app/panels/table/table_model.ts | 5 +++ .../datasource/elasticsearch/datasource.js | 5 +-- .../datasource/elasticsearch/metric_agg.js | 8 +++-- .../elasticsearch/partials/metricAgg.html | 2 +- .../datasource/elasticsearch/query_def.js | 17 +++++----- .../elasticsearch/specs/datasource_specs.ts | 32 +++++++++++++++++++ 6 files changed, 56 insertions(+), 13 deletions(-) diff --git a/public/app/panels/table/table_model.ts b/public/app/panels/table/table_model.ts index 528d250fb99..943234bcd89 100644 --- a/public/app/panels/table/table_model.ts +++ b/public/app/panels/table/table_model.ts @@ -4,6 +4,11 @@ export class TableModel { columns: any[]; rows: any[]; + constructor() { + this.columns = []; + this.rows = []; + } + static transform(data, panel) { var model = new TableModel(); diff --git a/public/app/plugins/datasource/elasticsearch/datasource.js b/public/app/plugins/datasource/elasticsearch/datasource.js index 4e27da73850..f8770064b8e 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.js +++ b/public/app/plugins/datasource/elasticsearch/datasource.js @@ -170,7 +170,8 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes target = options.targets[i]; if (target.hide) {return;} - var esQuery = angular.toJson(this.queryBuilder.build(target)); + var queryObj = this.queryBuilder.build(target); + var esQuery = angular.toJson(queryObj); var luceneQuery = angular.toJson(target.query || '*'); // remove inner quotes luceneQuery = luceneQuery.substr(1, luceneQuery.length - 2); @@ -185,7 +186,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes payload = payload.replace(/\$timeTo/g, options.range.to.valueOf()); payload = templateSrv.replace(payload, options.scopedVars); - return this._post('/_msearch?search_type=count', payload).then(function(res) { + return this._post('/_msearch', payload).then(function(res) { return new ElasticResponse(sentTargets, res).getTimeSeries(); }); }; diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.js b/public/app/plugins/datasource/elasticsearch/metric_agg.js index fd748a1f8b0..c4e04dad325 100644 --- a/public/app/plugins/datasource/elasticsearch/metric_agg.js +++ b/public/app/plugins/datasource/elasticsearch/metric_agg.js @@ -28,6 +28,7 @@ function (angular, _, queryDef) { $scope.isFirst = $scope.index === 0; $scope.isSingle = metricAggs.length === 1; $scope.settingsLinkText = ''; + $scope.aggDef = _.findWhere($scope.metricAggTypes, {value: $scope.agg.type}); if (!$scope.agg.field) { $scope.agg.field = 'select field'; @@ -53,6 +54,11 @@ function (angular, _, queryDef) { $scope.agg.meta.std_deviation_bounds_lower = true; $scope.agg.meta.std_deviation_bounds_upper = true; } + break; + } + case 'raw_document': { + $scope.target.metrics = [$scope.agg]; + $scope.target.bucketAggs = []; } } }; @@ -65,8 +71,6 @@ function (angular, _, queryDef) { $scope.agg.settings = {}; $scope.agg.meta = {}; $scope.showOptions = false; - - $scope.validateModel(); $scope.onChange(); }; diff --git a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html index 7d58be38094..65030af5655 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html @@ -6,7 +6,7 @@
  • -
  • +
  • diff --git a/public/app/plugins/datasource/elasticsearch/query_def.js b/public/app/plugins/datasource/elasticsearch/query_def.js index ca915c68dd4..baab2378e9f 100644 --- a/public/app/plugins/datasource/elasticsearch/query_def.js +++ b/public/app/plugins/datasource/elasticsearch/query_def.js @@ -6,14 +6,15 @@ function (_) { return { metricAggTypes: [ - {text: "Count", value: 'count' }, - {text: "Average", value: 'avg' }, - {text: "Sum", value: 'sum' }, - {text: "Max", value: 'max' }, - {text: "Min", value: 'min' }, - {text: "Extended Stats", value: 'extended_stats' }, - {text: "Percentiles", value: 'percentiles' }, - {text: "Unique Count", value: "cardinality" } + {text: "Count", value: 'count', requiresField: false}, + {text: "Average", value: 'avg', requiresField: true}, + {text: "Sum", value: 'sum', requiresField: true}, + {text: "Max", value: 'max', requiresField: true}, + {text: "Min", value: 'min', requiresField: true}, + {text: "Extended Stats", value: 'extended_stats', requiresField: true}, + {text: "Percentiles", value: 'percentiles', requiresField: true}, + {text: "Unique Count", value: "cardinality", requiresField: true}, + {text: "Raw Document", value: "raw_document", requiresField: false} ], bucketAggTypes: [ diff --git a/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts index f087f847a19..4747030ff3d 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts @@ -80,4 +80,36 @@ describe('ElasticDatasource', function() { expect(body.query.filtered.query.query_string.query).to.be('escape\\:test'); }); }); + + describe('When issueing document query', function() { + var requestOptions, parts, header; + + beforeEach(function() { + ctx.ds = new ctx.service({url: 'http://es.com', index: 'test', jsonData: {}}); + + ctx.backendSrv.datasourceRequest = function(options) { + requestOptions = options; + return ctx.$q.when({data: {responses: []}}); + }; + + ctx.ds.query({ + range: { from: moment([2015, 4, 30, 10]), to: moment([2015, 5, 1, 10]) }, + targets: [{ bucketAggs: [], metrics: [{type: 'raw_document'}], query: 'test' }] + }); + + ctx.$rootScope.$apply(); + parts = requestOptions.data.split('\n'); + header = angular.fromJson(parts[0]); + }); + + it('should set search type to query_then_fetch', function() { + expect(header.search_type).to.eql('query_then_fetch'); + }); + + it('should set size', function() { + var body = angular.fromJson(parts[1]); + expect(body.query.size).to.be(500); + }); + }); + });