Commit 605888bb by Torkel Odegaard

finished refactoring of GraphiteDatasource to angular service and fixed jshint errors

parent ef69d692
...@@ -12,14 +12,14 @@ function (angular, _, config) { ...@@ -12,14 +12,14 @@ function (angular, _, config) {
var defaultDatasource = _.findWhere(_.values(config.datasources), { default: true } ); var defaultDatasource = _.findWhere(_.values(config.datasources), { default: true } );
this.default = new GraphiteDatasource(defaultDatasource, $q, filterSrv, $http); this.default = new GraphiteDatasource(defaultDatasource);
this.get = function(name) { this.get = function(name) {
if (!name) { if (!name) {
return this.default; return this.default;
} }
return new GraphiteDatasource(config.datasources[name], $q, filterSrv, $http); return new GraphiteDatasource(config.datasources[name]);
}; };
this.listOptions = function() { this.listOptions = function() {
......
...@@ -13,13 +13,10 @@ function (angular, _, $, config, kbn, moment) { ...@@ -13,13 +13,10 @@ function (angular, _, $, config, kbn, moment) {
module.factory('GraphiteDatasource', function(dashboard, $q, filterSrv, $http) { module.factory('GraphiteDatasource', function(dashboard, $q, filterSrv, $http) {
function GraphiteDatasource(datasource, $q, filterSrv, $http) { function GraphiteDatasource(datasource) {
this.url = datasource.url; this.url = datasource.url;
this.type = 'graphite'; this.type = 'graphite';
this.basicAuth = datasource.basicAuth; this.basicAuth = datasource.basicAuth;
this.$q = $q;
this.filterSrv = filterSrv;
this.$http = $http;
} }
GraphiteDatasource.prototype.query = function(options) { GraphiteDatasource.prototype.query = function(options) {
...@@ -35,7 +32,7 @@ function (angular, _, $, config, kbn, moment) { ...@@ -35,7 +32,7 @@ function (angular, _, $, config, kbn, moment) {
var params = this.buildGraphiteParams(graphOptions); var params = this.buildGraphiteParams(graphOptions);
if (options.format === 'png') { if (options.format === 'png') {
return this.$q.when(this.url + '/render' + '?' + params.join('&')); return $q.when(this.url + '/render' + '?' + params.join('&'));
} }
return this.doGraphiteRequest({ return this.doGraphiteRequest({
...@@ -48,7 +45,7 @@ function (angular, _, $, config, kbn, moment) { ...@@ -48,7 +45,7 @@ function (angular, _, $, config, kbn, moment) {
}); });
} }
catch(err) { catch(err) {
return this.$q.reject(err); return $q.reject(err);
} }
}; };
...@@ -65,7 +62,7 @@ function (angular, _, $, config, kbn, moment) { ...@@ -65,7 +62,7 @@ function (angular, _, $, config, kbn, moment) {
}); });
} }
catch(err) { catch(err) {
return this.$q.reject(err); return $q.reject(err);
} }
}; };
...@@ -100,10 +97,10 @@ function (angular, _, $, config, kbn, moment) { ...@@ -100,10 +97,10 @@ function (angular, _, $, config, kbn, moment) {
GraphiteDatasource.prototype.metricFindQuery = function(query) { GraphiteDatasource.prototype.metricFindQuery = function(query) {
var interpolated; var interpolated;
try { try {
interpolated = this.filterSrv.applyFilterToTarget(query); interpolated = filterSrv.applyFilterToTarget(query);
} }
catch(err) { catch(err) {
return this.$q.reject(err); return $q.reject(err);
} }
return this.doGraphiteRequest({method: 'GET', url: '/metrics/find/?query=' + interpolated }) return this.doGraphiteRequest({method: 'GET', url: '/metrics/find/?query=' + interpolated })
...@@ -137,7 +134,7 @@ function (angular, _, $, config, kbn, moment) { ...@@ -137,7 +134,7 @@ function (angular, _, $, config, kbn, moment) {
options.url = this.url + options.url; options.url = this.url + options.url;
return this.$http(options); return $http(options);
}; };
GraphiteDatasource.prototype.buildGraphiteParams = function(options) { GraphiteDatasource.prototype.buildGraphiteParams = function(options) {
...@@ -156,7 +153,7 @@ function (angular, _, $, config, kbn, moment) { ...@@ -156,7 +153,7 @@ function (angular, _, $, config, kbn, moment) {
if (key === "targets") { if (key === "targets") {
_.each(value, function (value) { _.each(value, function (value) {
if (!value.hide) { if (!value.hide) {
var targetValue = this.filterSrv.applyFilterToTarget(value.target); var targetValue = filterSrv.applyFilterToTarget(value.target);
clean_options.push("target=" + encodeURIComponent(targetValue)); clean_options.push("target=" + encodeURIComponent(targetValue));
} }
}, this); }, this);
......
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