mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
finished refactoring of GraphiteDatasource to angular service and fixed jshint errors
This commit is contained in:
parent
ef69d692ef
commit
605888bb78
@ -12,14 +12,14 @@ function (angular, _, config) {
|
||||
|
||||
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) {
|
||||
if (!name) {
|
||||
return this.default;
|
||||
}
|
||||
|
||||
return new GraphiteDatasource(config.datasources[name], $q, filterSrv, $http);
|
||||
return new GraphiteDatasource(config.datasources[name]);
|
||||
};
|
||||
|
||||
this.listOptions = function() {
|
||||
|
@ -13,13 +13,10 @@ function (angular, _, $, config, kbn, moment) {
|
||||
|
||||
module.factory('GraphiteDatasource', function(dashboard, $q, filterSrv, $http) {
|
||||
|
||||
function GraphiteDatasource(datasource, $q, filterSrv, $http) {
|
||||
function GraphiteDatasource(datasource) {
|
||||
this.url = datasource.url;
|
||||
this.type = 'graphite';
|
||||
this.basicAuth = datasource.basicAuth;
|
||||
this.$q = $q;
|
||||
this.filterSrv = filterSrv;
|
||||
this.$http = $http;
|
||||
}
|
||||
|
||||
GraphiteDatasource.prototype.query = function(options) {
|
||||
@ -35,7 +32,7 @@ function (angular, _, $, config, kbn, moment) {
|
||||
var params = this.buildGraphiteParams(graphOptions);
|
||||
|
||||
if (options.format === 'png') {
|
||||
return this.$q.when(this.url + '/render' + '?' + params.join('&'));
|
||||
return $q.when(this.url + '/render' + '?' + params.join('&'));
|
||||
}
|
||||
|
||||
return this.doGraphiteRequest({
|
||||
@ -48,7 +45,7 @@ function (angular, _, $, config, kbn, moment) {
|
||||
});
|
||||
}
|
||||
catch(err) {
|
||||
return this.$q.reject(err);
|
||||
return $q.reject(err);
|
||||
}
|
||||
};
|
||||
|
||||
@ -65,7 +62,7 @@ function (angular, _, $, config, kbn, moment) {
|
||||
});
|
||||
}
|
||||
catch(err) {
|
||||
return this.$q.reject(err);
|
||||
return $q.reject(err);
|
||||
}
|
||||
};
|
||||
|
||||
@ -100,10 +97,10 @@ function (angular, _, $, config, kbn, moment) {
|
||||
GraphiteDatasource.prototype.metricFindQuery = function(query) {
|
||||
var interpolated;
|
||||
try {
|
||||
interpolated = this.filterSrv.applyFilterToTarget(query);
|
||||
interpolated = filterSrv.applyFilterToTarget(query);
|
||||
}
|
||||
catch(err) {
|
||||
return this.$q.reject(err);
|
||||
return $q.reject(err);
|
||||
}
|
||||
|
||||
return this.doGraphiteRequest({method: 'GET', url: '/metrics/find/?query=' + interpolated })
|
||||
@ -137,7 +134,7 @@ function (angular, _, $, config, kbn, moment) {
|
||||
|
||||
options.url = this.url + options.url;
|
||||
|
||||
return this.$http(options);
|
||||
return $http(options);
|
||||
};
|
||||
|
||||
GraphiteDatasource.prototype.buildGraphiteParams = function(options) {
|
||||
@ -156,7 +153,7 @@ function (angular, _, $, config, kbn, moment) {
|
||||
if (key === "targets") {
|
||||
_.each(value, function (value) {
|
||||
if (!value.hide) {
|
||||
var targetValue = this.filterSrv.applyFilterToTarget(value.target);
|
||||
var targetValue = filterSrv.applyFilterToTarget(value.target);
|
||||
clean_options.push("target=" + encodeURIComponent(targetValue));
|
||||
}
|
||||
}, this);
|
||||
|
Loading…
Reference in New Issue
Block a user