datasource.ts 820 B

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