From 94a7e9b18576f0d047ffeeb50fc48ce31b6bd3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 22 Jan 2016 19:59:36 +0100 Subject: [PATCH] poc(panel): experimental panel stuff --- public/app/features/panel/panel_ctrl.ts | 21 +++++++++ public/app/features/panel/panel_directive.js | 7 +-- public/app/features/panel/panel_loader.ts | 47 +++++++++++++++++--- public/app/partials/dashboard.html | 7 +-- public/app/plugins/panel/test/module.html | 4 ++ public/app/plugins/panel/test/module.ts | 39 +++------------- 6 files changed, 80 insertions(+), 45 deletions(-) create mode 100644 public/app/features/panel/panel_ctrl.ts create mode 100644 public/app/plugins/panel/test/module.html diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts new file mode 100644 index 00000000000..db8788ab306 --- /dev/null +++ b/public/app/features/panel/panel_ctrl.ts @@ -0,0 +1,21 @@ +/// + +import PanelMeta from './panel_meta2'; + +export class PanelCtrl { + panelMeta: any; + panel: any; + row: any; + dashboard: any; + + constructor(private $scope) { + this.panelMeta = new PanelMeta({ + panelName: 'Table', + editIcon: "fa fa-table", + fullscreen: true, + metricsEditor: true, + }); + } +} + + diff --git a/public/app/features/panel/panel_directive.js b/public/app/features/panel/panel_directive.js index 9d1b6b54b76..f8b9e724b32 100644 --- a/public/app/features/panel/panel_directive.js +++ b/public/app/features/panel/panel_directive.js @@ -15,9 +15,10 @@ function (angular, $) { 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); + var ctrl = scope.ctrl; + scope.$watchGroup(['ctrl.fullscreen', 'ctrl.height', 'ctrl.panel.height', 'ctrl.row.height'], function() { + panelContainer.css({ minHeight: ctrl.height || ctrl.panel.height || ctrl.row.height, display: 'block' }); + elem.toggleClass('panel-fullscreen', ctrl.fullscreen ? true : false); }); } }; diff --git a/public/app/features/panel/panel_loader.ts b/public/app/features/panel/panel_loader.ts index 612cacd3b98..dd0284138ab 100644 --- a/public/app/features/panel/panel_loader.ts +++ b/public/app/features/panel/panel_loader.ts @@ -8,34 +8,67 @@ import {unknownPanelDirective} from '../../plugins/panel/unknown/module'; var directiveModule = angular.module('grafana.directives'); /** @ngInject */ -function panelLoader($compile, dynamicDirectiveSrv) { +function panelLoader($compile, dynamicDirectiveSrv, $http, $q) { return { restrict: 'E', + scope: { + dashboard: "=", + row: "=", + panel: "=" + }, link: function(scope, elem, attrs) { - function addDirective(name, component) { - if (!component.registered) { - directiveModule.component(attrs.$normalize(name), component); - component.registered = true; + function getTemplate(component) { + if (component.template) { + return $q.when(component.template); } + return $http.get(component.templateUrl).then(res => { + return res.data; + }); + } + function addPanelAndCompile(name) { var child = angular.element(document.createElement(name)); child.attr('dashboard', 'dashboard'); child.attr('panel', 'panel'); + child.attr('row', 'row'); $compile(child)(scope); elem.empty(); elem.append(child); } + function addPanel(name, directive) { + if (!directive.registered) { + getTemplate(directive).then(template => { + directive.templateUrl = null; + directive.template = `${template}`; + directive.controllerAs = 'ctrl'; + directive.bindToController = true; + directive.scope = { + dashboard: "=", + panel: "=", + row: "=" + }; + + directiveModule.directive(attrs.$normalize(name), function() { + return directive; + }); + directive.registered = true; + addPanelAndCompile(name); + }); + } + addPanelAndCompile(name); + } + var panelElemName = 'panel-directive-' + scope.panel.type; let panelInfo = config.panels[scope.panel.type]; if (!panelInfo) { - addDirective(panelElemName, unknownPanelDirective); + addPanel(panelElemName, unknownPanelDirective); } System.import(panelInfo.module).then(function(panelModule) { - addDirective(panelElemName, panelModule.component); + addPanel(panelElemName, panelModule.panel); }).catch(err => { console.log('Panel err: ', err); }); diff --git a/public/app/partials/dashboard.html b/public/app/partials/dashboard.html index 9d20da3d7b4..7aeefb20730 100644 --- a/public/app/partials/dashboard.html +++ b/public/app/partials/dashboard.html @@ -79,9 +79,10 @@
-
- +
+ +
diff --git a/public/app/plugins/panel/test/module.html b/public/app/plugins/panel/test/module.html new file mode 100644 index 00000000000..47b59289210 --- /dev/null +++ b/public/app/plugins/panel/test/module.html @@ -0,0 +1,4 @@ +

+ Test panel! + panel.id: {{ctrl.panel.id}} +

diff --git a/public/app/plugins/panel/test/module.ts b/public/app/plugins/panel/test/module.ts index 5c4413ea144..ae9af416ed0 100644 --- a/public/app/plugins/panel/test/module.ts +++ b/public/app/plugins/panel/test/module.ts @@ -1,47 +1,22 @@ /// -import PanelMeta from 'app/features/panel/panel_meta2'; - -class PanelBaseCtrl { - panelMeta: any; - panel: any; - dashboard: any; - - constructor(private $scope) { - this.panelMeta = new PanelMeta({ - panelName: 'Table', - editIcon: "fa fa-table", - fullscreen: true, - metricsEditor: true, - }); - } -} - -class TestPanelCtrl extends PanelBaseCtrl { +import {PanelCtrl} from '../../../features/panel/panel_ctrl'; +class TestPanelCtrl extends PanelCtrl { constructor($scope) { super($scope); } } -var testPanelComponent = { - template: ` - -
-

Test Panel

-
-
- `, +var panel = { + templateUrl: `app/plugins/panel/test/module.html`, controller: TestPanelCtrl, - controllerAs: 'ctrl', - bindings: { - dashboard: "=", - panel: "=", + link: function(scope, elem) { + console.log('panel link'); } }; export { - PanelBaseCtrl, TestPanelCtrl, - testPanelComponent as component, + panel, }