query_ctrl.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import './bucket_agg';
  3. import './metric_agg';
  4. import angular from 'angular';
  5. import _ from 'lodash';
  6. import {QueryCtrl} from 'app/features/panel/panel';
  7. export class ElasticQueryCtrl extends QueryCtrl {
  8. static templateUrl = 'public/app/plugins/datasource/elasticsearch/partials/query.editor.html';
  9. esVersion: any;
  10. rawQueryOld: string;
  11. /** @ngInject **/
  12. constructor($scope, $injector, private $rootScope, private $timeout, private uiSegmentSrv) {
  13. super($scope, $injector);
  14. this.esVersion = this.datasource.esVersion;
  15. this.queryUpdated();
  16. }
  17. getFields(type) {
  18. var jsonStr = angular.toJson({find: 'fields', type: type});
  19. return this.datasource.metricFindQuery(jsonStr)
  20. .then(this.uiSegmentSrv.transformToSegments(false))
  21. .catch(this.handleQueryError.bind(this));
  22. }
  23. queryUpdated() {
  24. var newJson = angular.toJson(this.datasource.queryBuilder.build(this.target), true);
  25. if (newJson !== this.rawQueryOld) {
  26. this.rawQueryOld = newJson;
  27. this.refresh();
  28. }
  29. this.$rootScope.appEvent('elastic-query-updated');
  30. }
  31. handleQueryError(err) {
  32. this.error = err.message || 'Failed to issue metric query';
  33. return [];
  34. }
  35. }