query_ctrl.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/plugins/sdk';
  7. export class ElasticQueryCtrl extends QueryCtrl {
  8. static templateUrl = '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. getCollapsedText() {
  32. var text = 'Count(), Avg(@value), Group by(@timestamp, 1min) Query';
  33. return text;
  34. }
  35. handleQueryError(err) {
  36. this.error = err.message || 'Failed to issue metric query';
  37. return [];
  38. }
  39. }