mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Reverted $q to Promise migration in datasource_srv
This commit is contained in:
@@ -7,7 +7,7 @@ export class DatasourceSrv {
|
|||||||
datasources: any;
|
datasources: any;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private $injector, private $rootScope, private templateSrv) {
|
constructor(private $q, private $injector, private $rootScope, private templateSrv) {
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ export class DatasourceSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.datasources[name]) {
|
if (this.datasources[name]) {
|
||||||
return Promise.resolve(this.datasources[name]);
|
return this.$q.when(this.datasources[name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.loadDatasource(name);
|
return this.loadDatasource(name);
|
||||||
@@ -36,16 +36,18 @@ export class DatasourceSrv {
|
|||||||
loadDatasource(name) {
|
loadDatasource(name) {
|
||||||
const dsConfig = config.datasources[name];
|
const dsConfig = config.datasources[name];
|
||||||
if (!dsConfig) {
|
if (!dsConfig) {
|
||||||
return Promise.reject({ message: 'Datasource named ' + name + ' was not found' });
|
return this.$q.reject({ message: 'Datasource named ' + name + ' was not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deferred = this.$q.defer();
|
||||||
const pluginDef = dsConfig.meta;
|
const pluginDef = dsConfig.meta;
|
||||||
|
|
||||||
return importPluginModule(pluginDef.module)
|
importPluginModule(pluginDef.module)
|
||||||
.then(plugin => {
|
.then(plugin => {
|
||||||
// check if its in cache now
|
// check if its in cache now
|
||||||
if (this.datasources[name]) {
|
if (this.datasources[name]) {
|
||||||
return this.datasources[name];
|
deferred.resolve(this.datasources[name]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// plugin module needs to export a constructor function named Datasource
|
// plugin module needs to export a constructor function named Datasource
|
||||||
@@ -57,11 +59,13 @@ export class DatasourceSrv {
|
|||||||
instance.meta = pluginDef;
|
instance.meta = pluginDef;
|
||||||
instance.name = name;
|
instance.name = name;
|
||||||
this.datasources[name] = instance;
|
this.datasources[name] = instance;
|
||||||
return instance;
|
deferred.resolve(instance);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
this.$rootScope.appEvent('alert-error', [dsConfig.name + ' plugin failed', err.toString()]);
|
this.$rootScope.appEvent('alert-error', [dsConfig.name + ' plugin failed', err.toString()]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAll() {
|
getAll() {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const templateSrv = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('datasource_srv', function() {
|
describe('datasource_srv', function() {
|
||||||
let _datasourceSrv = new DatasourceSrv({}, {}, templateSrv);
|
let _datasourceSrv = new DatasourceSrv({}, {}, {}, templateSrv);
|
||||||
|
|
||||||
describe('when loading explore sources', () => {
|
describe('when loading explore sources', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user