diff --git a/public/app/features/panel/panel_directive.js b/public/app/features/panel/panel_directive.js index b4c1a2d6a0f..9d1b6b54b76 100644 --- a/public/app/features/panel/panel_directive.js +++ b/public/app/features/panel/panel_directive.js @@ -12,9 +12,9 @@ function (angular, $) { restrict: 'E', templateUrl: 'app/features/panel/partials/panel.html', transclude: true, + scope: { ctrl: "=" }, link: function(scope, elem) { var panelContainer = elem.find('.panel-container'); - scope.$watchGroup(['fullscreen', 'height', 'panel.height', 'row.height'], function() { panelContainer.css({ minHeight: scope.height || scope.panel.height || scope.row.height, display: 'block' }); elem.toggleClass('panel-fullscreen', scope.fullscreen ? true : false); diff --git a/public/app/features/panel/panel_loader.ts b/public/app/features/panel/panel_loader.ts index 8dc46f494a1..612cacd3b98 100644 --- a/public/app/features/panel/panel_loader.ts +++ b/public/app/features/panel/panel_loader.ts @@ -5,26 +5,42 @@ import config from 'app/core/config'; import {unknownPanelDirective} from '../../plugins/panel/unknown/module'; +var directiveModule = angular.module('grafana.directives'); + /** @ngInject */ -function panelLoader($parse, dynamicDirectiveSrv) { - return dynamicDirectiveSrv.create({ - directive: scope => { - let panelInfo = config.panels[scope.panel.type]; - if (!panelInfo) { - return Promise.resolve({ - name: 'panel-directive-' + scope.panel.type, - fn: unknownPanelDirective - }); +function panelLoader($compile, dynamicDirectiveSrv) { + return { + restrict: 'E', + link: function(scope, elem, attrs) { + + function addDirective(name, component) { + if (!component.registered) { + directiveModule.component(attrs.$normalize(name), component); + component.registered = true; + } + + var child = angular.element(document.createElement(name)); + child.attr('dashboard', 'dashboard'); + child.attr('panel', 'panel'); + $compile(child)(scope); + + elem.empty(); + elem.append(child); } - return System.import(panelInfo.module).then(function(panelModule) { - return { - name: 'panel-directive-' + scope.panel.type, - fn: panelModule.panel, - }; + var panelElemName = 'panel-directive-' + scope.panel.type; + let panelInfo = config.panels[scope.panel.type]; + if (!panelInfo) { + addDirective(panelElemName, unknownPanelDirective); + } + + System.import(panelInfo.module).then(function(panelModule) { + addDirective(panelElemName, panelModule.component); + }).catch(err => { + console.log('Panel err: ', err); }); - }, - }); + } + }; } angular.module('grafana.directives').directive('panelLoader', panelLoader); diff --git a/public/app/features/panel/panel_menu.js b/public/app/features/panel/panel_menu.js index 30b61418d72..ec0f2301675 100644 --- a/public/app/features/panel/panel_menu.js +++ b/public/app/features/panel/panel_menu.js @@ -11,16 +11,16 @@ function (angular, $, _) { .directive('panelMenu', function($compile, linkSrv) { var linkTemplate = '' + - '{{panel.title | interpolateTemplateVars:this}}' + + '{{ctrl.panel.title}}' + '' + - ' {{panelMeta.timeInfo}}' + + ' {{panelMeta.timeInfo}}' + ''; function createExternalLinkMenu($scope) { var template = '
'; template += '
'; - if ($scope.panel.links) { + if ($scope.ctrl.panel.links) { _.each($scope.panel.links, function(link) { var info = linkSrv.getPanelLinkAnchorInfo(link, $scope.panel.scopedVars); template += '' + info.title + ''; @@ -31,7 +31,7 @@ function (angular, $, _) { function createMenuTemplate($scope) { var template = '
'; - if ($scope.dashboardMeta.canEdit) { + if ($scope.ctrl.dashboard.meta.canEdit) { template += '
'; template += '
'; template += ''; @@ -44,9 +44,9 @@ function (angular, $, _) { template += '
'; template += ''; - _.each($scope.panelMeta.menu, function(item) { + _.each($scope.ctrl.panelMeta.menu, function(item) { // skip edit actions if not editor - if (item.role === 'Editor' && !$scope.dashboardMeta.canEdit) { + if (item.role === 'Editor' && !$scope.ctrl.dashboard.meta.canEdit) { return; } @@ -64,7 +64,7 @@ function (angular, $, _) { } function getExtendedMenu($scope) { - return angular.copy($scope.panelMeta.extendedMenu); + return angular.copy($scope.ctrl.panelMeta.extendedMenu); } return { diff --git a/public/app/plugins/panel/test/module.ts b/public/app/plugins/panel/test/module.ts index 4fb2c4a66eb..5c4413ea144 100644 --- a/public/app/plugins/panel/test/module.ts +++ b/public/app/plugins/panel/test/module.ts @@ -3,14 +3,17 @@ import PanelMeta from 'app/features/panel/panel_meta2'; class PanelBaseCtrl { + panelMeta: any; + panel: any; + dashboard: any; + constructor(private $scope) { - $scope.panelMeta = new PanelMeta({ + this.panelMeta = new PanelMeta({ panelName: 'Table', editIcon: "fa fa-table", fullscreen: true, metricsEditor: true, }); - $scope.testProp = "hello"; } } @@ -18,26 +21,27 @@ class TestPanelCtrl extends PanelBaseCtrl { constructor($scope) { super($scope); - $scope.panelMeta.panelName = "Test"; } } -function testPanelDirective() { - return { - restrict: 'E', - template: ` - +var testPanelComponent = { + template: ` +
-

Test Panel, {{testProp}}

+

Test Panel

`, - controller: TestPanelCtrl - }; -} + controller: TestPanelCtrl, + controllerAs: 'ctrl', + bindings: { + dashboard: "=", + panel: "=", + } +}; export { PanelBaseCtrl, TestPanelCtrl, - testPanelDirective as panel + testPanelComponent as component, }