panelDirective.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. module.directive('queryEditorLoader', function($compile, $parse, datasourceSrv) {
  38. return {
  39. restrict: 'E',
  40. link: function(scope, elem) {
  41. var editorScope;
  42. scope.$watch("panel.datasource", function() {
  43. var datasource = scope.target.datasource || scope.panel.datasource;
  44. datasourceSrv.get(datasource).then(function(ds) {
  45. if (editorScope) {
  46. editorScope.$destroy();
  47. elem.empty();
  48. }
  49. editorScope = scope.$new();
  50. editorScope.datasource = ds;
  51. var panelEl = angular.element(document.createElement('metric-query-editor-' + ds.meta.type));
  52. elem.append(panelEl);
  53. $compile(panelEl)(editorScope);
  54. });
  55. });
  56. }
  57. };
  58. });
  59. module.directive('queryOptionsLoader', function($compile, $parse, datasourceSrv) {
  60. return {
  61. restrict: 'E',
  62. link: function(scope, elem) {
  63. var editorScope;
  64. scope.$watch("panel.datasource", function() {
  65. datasourceSrv.get(scope.panel.datasource).then(function(ds) {
  66. if (editorScope) {
  67. editorScope.$destroy();
  68. elem.empty();
  69. }
  70. editorScope = scope.$new();
  71. var panelEl = angular.element(document.createElement('metric-query-options-' + ds.meta.type));
  72. elem.append(panelEl);
  73. $compile(panelEl)(editorScope);
  74. });
  75. });
  76. }
  77. };
  78. });
  79. });