plugin_directive.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. define([
  2. 'angular',
  3. ],
  4. function (angular) {
  5. 'use strict';
  6. var module = angular.module('grafana.directives');
  7. module.directive('pluginConfigLoader', function($compile) {
  8. return {
  9. restrict: 'E',
  10. link: function(scope, elem) {
  11. var directive = 'grafana-plugin-core';
  12. //wait for the parent scope to be applied.
  13. scope.$watch("current", function(newVal) {
  14. if (newVal) {
  15. if (newVal.module) {
  16. directive = 'grafana-plugin-'+newVal.type;
  17. }
  18. scope.require([newVal.module], function () {
  19. var panelEl = angular.element(document.createElement(directive));
  20. elem.append(panelEl);
  21. $compile(panelEl)(scope);
  22. });
  23. }
  24. });
  25. }
  26. };
  27. });
  28. module.directive('grafanaPluginCore', function() {
  29. return {
  30. restrict: 'E',
  31. templateUrl: 'app/features/org/partials/pluginConfigCore.html',
  32. transclude: true,
  33. link: function(scope) {
  34. scope.update = function() {
  35. //Perform custom save events to the plugins own backend if needed.
  36. // call parent update to commit the change to the plugin object.
  37. // this will cause the page to reload.
  38. scope._update();
  39. };
  40. }
  41. };
  42. });
  43. });