Commit 6c32365e by Torkel Ödegaard

more work on refactoring ES usage

parent 95925aaf
......@@ -9,10 +9,9 @@ function (angular, _, config, $) {
var module = angular.module('kibana.controllers');
module.controller('SearchCtrl', function($scope, $rootScope, $element, $location, ejsResource, elasticClient) {
module.controller('SearchCtrl', function($scope, $rootScope, $element, $location, elastic) {
$scope.init = function() {
$scope.ejs = ejsResource(config.elasticsearch, config.elasticsearchBasicAuth);
$scope.giveSearchFocus = 0;
$scope.selectedIndex = -1;
$scope.results = {dashboards: [], tags: [], metrics: []};
......@@ -72,7 +71,7 @@ function (angular, _, config, $) {
sort: ["_uid"]
};
return elasticClient.post('dashboard/_search', query)
return elastic.post('dashboard/_search', query)
.then(function(results) {
if(_.isUndefined(results.hits)) {
$scope.results.dashboards = [];
......
......@@ -7,13 +7,12 @@ function(angular, config) {
var module = angular.module('kibana.services');
module.service('elasticClient', function($http) {
this.post = function(url, data) {
module.service('elastic', function($http) {
this._request = function(method, url, data) {
var options = {
url: config.elasticsearch + "/" + config.grafana_index + "/" + url,
method: 'POST',
method: method,
data: data
};
......@@ -23,11 +22,35 @@ function(angular, config) {
};
}
return $http(options)
return $http(options);
};
this.post = function(url, data) {
return this._request('POST', url, data)
.then(function(results) {
return results.data;
}, function(results) {
return results.data;
}, function(err) {
return err.data;
});
};
this.saveDashboard = function(dashboard, title, ttl) {
var dashboardClone = angular.copy(dashboard);
title = dashboardClone.title = title ? title : dashboard.title;
var data = {
user: 'guest',
group: 'guest',
title: title,
tags: dashboardClone.tags,
dashboard: angular.toJson(dashboardClone)
};
return this._request('PUT', '/dashboard/' + encodeURIComponent(title), data)
.then(function() {
return { title: title, url: '/dashboard/elasticsearch/' + title };
}, function(err) {
throw 'Failed to save to elasticsearch ' + err.data;
});
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment