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