panelDirective.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. define([
  2. 'angular',
  3. 'jquery',
  4. 'config',
  5. ],
  6. function (angular, $, config) {
  7. 'use strict';
  8. var module = angular.module('grafana.directives');
  9. module.directive('panelLoader', function($compile, $parse) {
  10. return {
  11. restrict: 'E',
  12. link: function(scope, elem, attr) {
  13. var getter = $parse(attr.type), panelType = getter(scope);
  14. var panelPath = config.panels[panelType].path;
  15. scope.require([panelPath + "/module"], function () {
  16. var panelEl = angular.element(document.createElement('grafana-panel-' + panelType));
  17. elem.append(panelEl);
  18. $compile(panelEl)(scope);
  19. });
  20. }
  21. };
  22. });
  23. module.directive('grafanaPanel', function() {
  24. return {
  25. restrict: 'E',
  26. templateUrl: 'app/features/panel/partials/panel.html',
  27. transclude: true,
  28. link: function(scope, elem) {
  29. var panelContainer = elem.find('.panel-container');
  30. scope.$watchGroup(['fullscreen', 'height', 'panel.height', 'row.height'], function() {
  31. panelContainer.css({ minHeight: scope.height || scope.panel.height || scope.row.height, display: 'block' });
  32. elem.toggleClass('panel-fullscreen', scope.fullscreen ? true : false);
  33. });
  34. }
  35. };
  36. });
  37. var targetLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  38. module.directive('queryEditorLoader', function($compile, $parse, datasourceSrv) {
  39. return {
  40. restrict: 'E',
  41. link: function(scope, elem) {
  42. var editorScope;
  43. scope.$watch("panel.datasource", function() {
  44. var datasource = scope.target.datasource || scope.panel.datasource;
  45. datasourceSrv.get(datasource).then(function(ds) {
  46. if (editorScope) {
  47. editorScope.$destroy();
  48. elem.empty();
  49. }
  50. editorScope = scope.$new();
  51. editorScope.datasource = ds;
  52. editorScope.targetLetters = targetLetters;
  53. var panelEl = angular.element(document.createElement('metric-query-editor-' + ds.meta.type));
  54. elem.append(panelEl);
  55. $compile(panelEl)(editorScope);
  56. });
  57. });
  58. }
  59. };
  60. });
  61. module.directive('queryOptionsLoader', function($compile, $parse, datasourceSrv) {
  62. return {
  63. restrict: 'E',
  64. link: function(scope, elem) {
  65. var editorScope;
  66. scope.$watch("panel.datasource", function() {
  67. datasourceSrv.get(scope.panel.datasource).then(function(ds) {
  68. if (editorScope) {
  69. editorScope.$destroy();
  70. elem.empty();
  71. }
  72. editorScope = scope.$new();
  73. var panelEl = angular.element(document.createElement('metric-query-options-' + ds.meta.type));
  74. elem.append(panelEl);
  75. $compile(panelEl)(editorScope);
  76. });
  77. });
  78. }
  79. };
  80. });
  81. });