Commit bd0f694f by Torkel Ödegaard

small refactoring and jshint fix for datasourceFactory func

parent c018b4bd
...@@ -12,18 +12,21 @@ function (angular, _, config) { ...@@ -12,18 +12,21 @@ function (angular, _, config) {
module.service('datasourceSrv', function($q, filterSrv, $http, GraphiteDatasource, InfluxDatasource) { module.service('datasourceSrv', function($q, filterSrv, $http, GraphiteDatasource, InfluxDatasource) {
this.init = function() {
var defaultDatasource = _.findWhere(_.values(config.datasources), { default: true } ); var defaultDatasource = _.findWhere(_.values(config.datasources), { default: true } );
this.default = this.datasourceFactory(defaultDatasource);
this.default = datasourceFactory(defaultDatasource); };
function datasourceFactory(ds) { this.datasourceFactory = function(ds) {
switch(ds.type) { switch(ds.type) {
case 'graphite': case 'graphite':
return new GraphiteDatasource(ds); return new GraphiteDatasource(ds);
case 'influxdb': case 'influxdb':
return new InfluxDatasource(ds); return new InfluxDatasource(ds);
} }
} };
this.get = function(name) { this.get = function(name) {
if (!name) { return this.default; } if (!name) { return this.default; }
...@@ -33,7 +36,7 @@ function (angular, _, config) { ...@@ -33,7 +36,7 @@ function (angular, _, config) {
return null; return null;
} }
return datasourceFactory(ds); return this.datasourceFactory(ds);
}; };
this.listOptions = function() { this.listOptions = function() {
...@@ -44,5 +47,7 @@ function (angular, _, config) { ...@@ -44,5 +47,7 @@ function (angular, _, config) {
}; };
}); });
}; };
this.init();
}); });
}); });
\ No newline at end of file
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