-
Notifications
You must be signed in to change notification settings - Fork 11.7k
/
datasource.ts
37 lines (30 loc) · 915 Bytes
/
datasource.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import angular from 'angular';
import _ from 'lodash';
class MixedDatasource {
/** @ngInject */
constructor(private $q, private datasourceSrv) {}
query(options) {
const sets = _.groupBy(options.targets, 'datasource');
const promises = _.map(sets, targets => {
const dsName = targets[0].datasource;
if (dsName === '-- Mixed --') {
return this.$q([]);
}
const filtered = _.filter(targets, t => {
return !t.hide;
});
if (filtered.length === 0) {
return { data: [] };
}
return this.datasourceSrv.get(dsName).then(ds => {
const opt = angular.copy(options);
opt.targets = filtered;
return ds.query(opt);
});
});
return this.$q.all(promises).then(results => {
return { data: _.flatten(_.map(results, 'data')) };
});
}
}
export { MixedDatasource, MixedDatasource as Datasource };