2015-07-01 14:45:55 -04:00
|
|
|
define([
|
|
|
|
|
'angular',
|
|
|
|
|
],
|
2015-11-23 14:18:21 +01:00
|
|
|
function (angular) {
|
2015-07-01 14:45:55 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var module = angular.module('grafana.controllers');
|
|
|
|
|
|
2015-11-23 14:18:21 +01:00
|
|
|
module.controller('ElasticQueryCtrl', function($scope, $timeout, uiSegmentSrv) {
|
2015-12-14 15:08:34 +01:00
|
|
|
$scope.esVersion = $scope.datasource.esVersion;
|
2015-07-01 14:45:55 -04:00
|
|
|
|
|
|
|
|
$scope.init = function() {
|
|
|
|
|
var target = $scope.target;
|
2015-09-04 09:41:23 +02:00
|
|
|
if (!target) { return; }
|
|
|
|
|
|
2015-12-03 16:32:35 +01:00
|
|
|
$scope.queryUpdated();
|
2015-09-03 15:56:41 +02:00
|
|
|
};
|
|
|
|
|
|
2015-09-22 09:31:58 +02:00
|
|
|
$scope.getFields = function(type) {
|
|
|
|
|
var jsonStr = angular.toJson({find: 'fields', type: type});
|
|
|
|
|
return $scope.datasource.metricFindQuery(jsonStr)
|
2015-11-23 14:18:21 +01:00
|
|
|
.then(uiSegmentSrv.transformToSegments(false))
|
2015-09-04 11:17:52 +02:00
|
|
|
.then(null, $scope.handleQueryError);
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-04 09:41:23 +02:00
|
|
|
$scope.queryUpdated = function() {
|
2015-09-07 08:57:46 +02:00
|
|
|
var newJson = angular.toJson($scope.datasource.queryBuilder.build($scope.target), true);
|
2015-09-04 09:41:23 +02:00
|
|
|
if (newJson !== $scope.oldQueryRaw) {
|
|
|
|
|
$scope.rawQueryOld = newJson;
|
|
|
|
|
$scope.get_data();
|
|
|
|
|
}
|
2015-09-05 15:41:04 +02:00
|
|
|
|
|
|
|
|
$scope.appEvent('elastic-query-updated');
|
2015-09-03 11:14:25 +02:00
|
|
|
};
|
|
|
|
|
|
2015-07-01 14:45:55 -04:00
|
|
|
$scope.handleQueryError = function(err) {
|
|
|
|
|
$scope.parserError = err.message || 'Failed to issue metric query';
|
|
|
|
|
return [];
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-02 15:25:40 +02:00
|
|
|
$scope.init();
|
2015-07-01 14:45:55 -04:00
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|