Commit 94a7e9b1 by Torkel Ödegaard

poc(panel): experimental panel stuff

parent 0796b2c0
///<reference path="../../headers/common.d.ts" />
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,
});
}
}
......@@ -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);
});
}
};
......
......@@ -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 = `<grafana-panel ctrl="ctrl">${template}</grafana-panel>`;
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);
});
......
......@@ -79,9 +79,10 @@
<div class="row-text pointer" ng-click="toggleRow(row)" ng-if="row.showTitle" ng-bind="row.title | interpolateTemplateVars:this">
</div>
<div ng-repeat="(name, panel) in row.panels track by panel.id" class="panel" ui-draggable="!dashboardViewState.fullscreen" drag="panel.id"
ui-on-Drop="onDrop($data, row, panel)" drag-handle-class="drag-handle" panel-width>
<panel-loader class="panel-margin"></panel-loader>
<div ng-repeat="panel in row.panels track by panel.id" class="panel" ui-draggable="!dashboardViewState.fullscreen" drag="panel.id"
ui-on-drop="onDrop($data, row, panel)" drag-handle-class="drag-handle" panel-width>
<panel-loader class="panel-margin" dashboard="dashboard" row="row" panel="panel">
</panel-loader>
</div>
<div panel-drop-zone class="panel panel-drop-zone" ui-on-drop="onDrop($data, row)" data-drop="true">
......
<h2 class="text-center">
Test panel!
panel.id: {{ctrl.panel.id}}
</h2>
///<reference path="../../../headers/common.d.ts" />
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: `
<grafana-panel ctrl="ctrl">
<div class="text-center" style="padding-top: 2rem">
<h2>Test Panel</h2>
</div>
</grafana-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,
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment