datasource.ts 802 B

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