2016-02-03 09:31:07 -06:00
|
|
|
///<reference path="../../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import './bucket_agg';
|
|
|
|
import './metric_agg';
|
|
|
|
|
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
2016-02-05 11:08:21 -06:00
|
|
|
import {QueryCtrl} from 'app/plugins/sdk';
|
2016-02-03 09:31:07 -06:00
|
|
|
|
|
|
|
export class ElasticQueryCtrl extends QueryCtrl {
|
2016-02-09 11:17:32 -06:00
|
|
|
static templateUrl = 'partials/query.editor.html';
|
2016-02-03 09:31:07 -06:00
|
|
|
|
|
|
|
esVersion: any;
|
|
|
|
rawQueryOld: string;
|
|
|
|
|
|
|
|
/** @ngInject **/
|
|
|
|
constructor($scope, $injector, private $rootScope, private $timeout, private uiSegmentSrv) {
|
|
|
|
super($scope, $injector);
|
|
|
|
|
|
|
|
this.esVersion = this.datasource.esVersion;
|
|
|
|
this.queryUpdated();
|
|
|
|
}
|
|
|
|
|
|
|
|
getFields(type) {
|
|
|
|
var jsonStr = angular.toJson({find: 'fields', type: type});
|
|
|
|
return this.datasource.metricFindQuery(jsonStr)
|
|
|
|
.then(this.uiSegmentSrv.transformToSegments(false))
|
|
|
|
.catch(this.handleQueryError.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
queryUpdated() {
|
|
|
|
var newJson = angular.toJson(this.datasource.queryBuilder.build(this.target), true);
|
|
|
|
if (newJson !== this.rawQueryOld) {
|
|
|
|
this.rawQueryOld = newJson;
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$rootScope.appEvent('elastic-query-updated');
|
|
|
|
}
|
|
|
|
|
2016-04-17 21:04:43 -05:00
|
|
|
getCollapsedText() {
|
|
|
|
var text = 'Count(), Avg(@value), Group by(@timestamp, 1min) Query';
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2016-02-03 09:31:07 -06:00
|
|
|
handleQueryError(err) {
|
|
|
|
this.error = err.message || 'Failed to issue metric query';
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|