panel_loader.ts 845 B

123456789101112131415161718192021222324252627282930
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import config from 'app/core/config';
  4. import {unknownPanelDirective} from '../../plugins/panel/unknown/module';
  5. /** @ngInject */
  6. function panelLoader($parse, dynamicDirectiveSrv) {
  7. return dynamicDirectiveSrv.create({
  8. directive: scope => {
  9. let panelInfo = config.panels[scope.panel.type];
  10. if (!panelInfo) {
  11. return Promise.resolve({
  12. name: 'panel-directive-' + scope.panel.type,
  13. fn: unknownPanelDirective
  14. });
  15. }
  16. return System.import(panelInfo.module).then(function(panelModule) {
  17. return {
  18. name: 'panel-directive-' + scope.panel.type,
  19. fn: panelModule.panel,
  20. };
  21. });
  22. },
  23. });
  24. }
  25. angular.module('grafana.directives').directive('panelLoader', panelLoader);