query_editor.ts 1.4 KB

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