datasource.ts 758 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. const sets = _.groupBy(options.targets, 'datasource');
  8. const promises = _.map(sets, targets => {
  9. const dsName = targets[0].datasource;
  10. if (dsName === '-- Mixed --') {
  11. return this.$q([]);
  12. }
  13. return this.datasourceSrv.get(dsName).then(ds => {
  14. const opt = angular.copy(options);
  15. opt.targets = targets;
  16. return ds.query(opt);
  17. });
  18. });
  19. return this.$q.all(promises).then(results => {
  20. return { data: _.flatten(_.map(results, 'data')) };
  21. });
  22. }
  23. }
  24. export { MixedDatasource, MixedDatasource as Datasource };