query_editor.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. /** @ngInject */
  4. function metricsQueryEditor(dynamicDirectiveSrv, datasourceSrv) {
  5. return dynamicDirectiveSrv.create({
  6. watchPath: "ctrl.panel.datasource",
  7. directive: scope => {
  8. let datasource = scope.target.datasource || scope.ctrl.panel.datasource;
  9. return datasourceSrv.get(datasource).then(ds => {
  10. scope.ctrl.datasource = ds;
  11. if (!scope.target.refId) {
  12. scope.target.refId = 'A';
  13. }
  14. return System.import(ds.meta.module).then(dsModule => {
  15. return {
  16. name: 'metrics-query-editor-' + ds.meta.id,
  17. fn: dsModule.metricsQueryEditor,
  18. };
  19. });
  20. });
  21. }
  22. });
  23. }
  24. /** @ngInject */
  25. function metricsQueryOptions(dynamicDirectiveSrv, datasourceSrv) {
  26. return dynamicDirectiveSrv.create({
  27. watchPath: "ctrl.panel.datasource",
  28. directive: scope => {
  29. return datasourceSrv.get(scope.ctrl.panel.datasource).then(ds => {
  30. return System.import(ds.meta.module).then(dsModule => {
  31. return {
  32. name: 'metrics-query-options-' + ds.meta.id,
  33. fn: dsModule.metricsQueryOptions
  34. };
  35. });
  36. });
  37. }
  38. });
  39. }
  40. angular.module('grafana.directives')
  41. .directive('metricsQueryEditor', metricsQueryEditor)
  42. .directive('metricsQueryOptions', metricsQueryOptions);