datasource.ts 764 B

1234567891011121314151617181920212223242526272829
  1. import angular from 'angular';
  2. import _ from 'lodash';
  3. class MixedDatasource {
  4. /** @ngInject */
  5. constructor(private $q, private datasourceSrv) {}
  6. query(options) {
  7. var sets = _.groupBy(options.targets, 'datasource');
  8. var promises = _.map(sets, targets => {
  9. var dsName = targets[0].datasource;
  10. if (dsName === '-- Mixed --') {
  11. return this.$q([]);
  12. }
  13. return this.datasourceSrv.get(dsName).then(function(ds) {
  14. var opt = angular.copy(options);
  15. opt.targets = targets;
  16. return ds.query(opt);
  17. });
  18. });
  19. return this.$q.all(promises).then(function(results) {
  20. return { data: _.flatten(_.map(results, 'data')) };
  21. });
  22. }
  23. }
  24. export { MixedDatasource, MixedDatasource as Datasource };