panelDirective.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. define([
  2. 'angular',
  3. 'jquery',
  4. 'config',
  5. ],
  6. function (angular, $, config) {
  7. 'use strict';
  8. angular
  9. .module('grafana.directives')
  10. .directive('panelLoader', function($compile, $parse) {
  11. return {
  12. restrict: 'E',
  13. link: function(scope, elem, attr) {
  14. var getter = $parse(attr.type), panelType = getter(scope);
  15. var panelPath = config.panels[panelType].path;
  16. scope.require([panelPath + "/module"], function () {
  17. var panelEl = angular.element(document.createElement('grafana-panel-' + panelType));
  18. elem.append(panelEl);
  19. $compile(panelEl)(scope);
  20. });
  21. }
  22. };
  23. }).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. });