mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
poc(panel as isolated compoennts): experimental panel stuff
This commit is contained in:
parent
7b4fe824ec
commit
0796b2c0e3
@ -12,9 +12,9 @@ function (angular, $) {
|
|||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
templateUrl: 'app/features/panel/partials/panel.html',
|
templateUrl: 'app/features/panel/partials/panel.html',
|
||||||
transclude: true,
|
transclude: true,
|
||||||
|
scope: { ctrl: "=" },
|
||||||
link: function(scope, elem) {
|
link: function(scope, elem) {
|
||||||
var panelContainer = elem.find('.panel-container');
|
var panelContainer = elem.find('.panel-container');
|
||||||
|
|
||||||
scope.$watchGroup(['fullscreen', 'height', 'panel.height', 'row.height'], function() {
|
scope.$watchGroup(['fullscreen', 'height', 'panel.height', 'row.height'], function() {
|
||||||
panelContainer.css({ minHeight: scope.height || scope.panel.height || scope.row.height, display: 'block' });
|
panelContainer.css({ minHeight: scope.height || scope.panel.height || scope.row.height, display: 'block' });
|
||||||
elem.toggleClass('panel-fullscreen', scope.fullscreen ? true : false);
|
elem.toggleClass('panel-fullscreen', scope.fullscreen ? true : false);
|
||||||
|
@ -5,26 +5,42 @@ import config from 'app/core/config';
|
|||||||
|
|
||||||
import {unknownPanelDirective} from '../../plugins/panel/unknown/module';
|
import {unknownPanelDirective} from '../../plugins/panel/unknown/module';
|
||||||
|
|
||||||
|
var directiveModule = angular.module('grafana.directives');
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
function panelLoader($parse, dynamicDirectiveSrv) {
|
function panelLoader($compile, dynamicDirectiveSrv) {
|
||||||
return dynamicDirectiveSrv.create({
|
return {
|
||||||
directive: scope => {
|
restrict: 'E',
|
||||||
let panelInfo = config.panels[scope.panel.type];
|
link: function(scope, elem, attrs) {
|
||||||
if (!panelInfo) {
|
|
||||||
return Promise.resolve({
|
function addDirective(name, component) {
|
||||||
name: 'panel-directive-' + scope.panel.type,
|
if (!component.registered) {
|
||||||
fn: unknownPanelDirective
|
directiveModule.component(attrs.$normalize(name), component);
|
||||||
});
|
component.registered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return System.import(panelInfo.module).then(function(panelModule) {
|
var child = angular.element(document.createElement(name));
|
||||||
return {
|
child.attr('dashboard', 'dashboard');
|
||||||
name: 'panel-directive-' + scope.panel.type,
|
child.attr('panel', 'panel');
|
||||||
fn: panelModule.panel,
|
$compile(child)(scope);
|
||||||
|
|
||||||
|
elem.empty();
|
||||||
|
elem.append(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
angular.module('grafana.directives').directive('panelLoader', panelLoader);
|
||||||
|
@ -11,16 +11,16 @@ function (angular, $, _) {
|
|||||||
.directive('panelMenu', function($compile, linkSrv) {
|
.directive('panelMenu', function($compile, linkSrv) {
|
||||||
var linkTemplate =
|
var linkTemplate =
|
||||||
'<span class="panel-title drag-handle pointer">' +
|
'<span class="panel-title drag-handle pointer">' +
|
||||||
'<span class="panel-title-text drag-handle">{{panel.title | interpolateTemplateVars:this}}</span>' +
|
'<span class="panel-title-text drag-handle">{{ctrl.panel.title}}</span>' +
|
||||||
'<span class="panel-links-btn"><i class="fa fa-external-link"></i></span>' +
|
'<span class="panel-links-btn"><i class="fa fa-external-link"></i></span>' +
|
||||||
'<span class="panel-time-info" ng-show="panelMeta.timeInfo"><i class="fa fa-clock-o"></i> {{panelMeta.timeInfo}}</span>' +
|
'<span class="panel-time-info" ng-show="ctrl.panelMeta.timeInfo"><i class="fa fa-clock-o"></i> {{panelMeta.timeInfo}}</span>' +
|
||||||
'</span>';
|
'</span>';
|
||||||
|
|
||||||
function createExternalLinkMenu($scope) {
|
function createExternalLinkMenu($scope) {
|
||||||
var template = '<div class="panel-menu small">';
|
var template = '<div class="panel-menu small">';
|
||||||
template += '<div class="panel-menu-row">';
|
template += '<div class="panel-menu-row">';
|
||||||
|
|
||||||
if ($scope.panel.links) {
|
if ($scope.ctrl.panel.links) {
|
||||||
_.each($scope.panel.links, function(link) {
|
_.each($scope.panel.links, function(link) {
|
||||||
var info = linkSrv.getPanelLinkAnchorInfo(link, $scope.panel.scopedVars);
|
var info = linkSrv.getPanelLinkAnchorInfo(link, $scope.panel.scopedVars);
|
||||||
template += '<a class="panel-menu-link" href="' + info.href + '" target="' + info.target + '">' + info.title + '</a>';
|
template += '<a class="panel-menu-link" href="' + info.href + '" target="' + info.target + '">' + info.title + '</a>';
|
||||||
@ -31,7 +31,7 @@ function (angular, $, _) {
|
|||||||
function createMenuTemplate($scope) {
|
function createMenuTemplate($scope) {
|
||||||
var template = '<div class="panel-menu small">';
|
var template = '<div class="panel-menu small">';
|
||||||
|
|
||||||
if ($scope.dashboardMeta.canEdit) {
|
if ($scope.ctrl.dashboard.meta.canEdit) {
|
||||||
template += '<div class="panel-menu-inner">';
|
template += '<div class="panel-menu-inner">';
|
||||||
template += '<div class="panel-menu-row">';
|
template += '<div class="panel-menu-row">';
|
||||||
template += '<a class="panel-menu-icon pull-left" ng-click="updateColumnSpan(-1)"><i class="fa fa-minus"></i></a>';
|
template += '<a class="panel-menu-icon pull-left" ng-click="updateColumnSpan(-1)"><i class="fa fa-minus"></i></a>';
|
||||||
@ -44,9 +44,9 @@ function (angular, $, _) {
|
|||||||
template += '<div class="panel-menu-row">';
|
template += '<div class="panel-menu-row">';
|
||||||
template += '<a class="panel-menu-link" gf-dropdown="extendedMenu"><i class="fa fa-bars"></i></a>';
|
template += '<a class="panel-menu-link" gf-dropdown="extendedMenu"><i class="fa fa-bars"></i></a>';
|
||||||
|
|
||||||
_.each($scope.panelMeta.menu, function(item) {
|
_.each($scope.ctrl.panelMeta.menu, function(item) {
|
||||||
// skip edit actions if not editor
|
// skip edit actions if not editor
|
||||||
if (item.role === 'Editor' && !$scope.dashboardMeta.canEdit) {
|
if (item.role === 'Editor' && !$scope.ctrl.dashboard.meta.canEdit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ function (angular, $, _) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getExtendedMenu($scope) {
|
function getExtendedMenu($scope) {
|
||||||
return angular.copy($scope.panelMeta.extendedMenu);
|
return angular.copy($scope.ctrl.panelMeta.extendedMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -3,14 +3,17 @@
|
|||||||
import PanelMeta from 'app/features/panel/panel_meta2';
|
import PanelMeta from 'app/features/panel/panel_meta2';
|
||||||
|
|
||||||
class PanelBaseCtrl {
|
class PanelBaseCtrl {
|
||||||
|
panelMeta: any;
|
||||||
|
panel: any;
|
||||||
|
dashboard: any;
|
||||||
|
|
||||||
constructor(private $scope) {
|
constructor(private $scope) {
|
||||||
$scope.panelMeta = new PanelMeta({
|
this.panelMeta = new PanelMeta({
|
||||||
panelName: 'Table',
|
panelName: 'Table',
|
||||||
editIcon: "fa fa-table",
|
editIcon: "fa fa-table",
|
||||||
fullscreen: true,
|
fullscreen: true,
|
||||||
metricsEditor: true,
|
metricsEditor: true,
|
||||||
});
|
});
|
||||||
$scope.testProp = "hello";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,26 +21,27 @@ class TestPanelCtrl extends PanelBaseCtrl {
|
|||||||
|
|
||||||
constructor($scope) {
|
constructor($scope) {
|
||||||
super($scope);
|
super($scope);
|
||||||
$scope.panelMeta.panelName = "Test";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testPanelDirective() {
|
var testPanelComponent = {
|
||||||
return {
|
|
||||||
restrict: 'E',
|
|
||||||
template: `
|
template: `
|
||||||
<grafana-panel>
|
<grafana-panel ctrl="ctrl">
|
||||||
<div class="text-center" style="padding-top: 2rem">
|
<div class="text-center" style="padding-top: 2rem">
|
||||||
<h2>Test Panel, {{testProp}}</h2>
|
<h2>Test Panel</h2>
|
||||||
</div>
|
</div>
|
||||||
</grafana-panel>
|
</grafana-panel>
|
||||||
`,
|
`,
|
||||||
controller: TestPanelCtrl
|
controller: TestPanelCtrl,
|
||||||
};
|
controllerAs: 'ctrl',
|
||||||
|
bindings: {
|
||||||
|
dashboard: "=",
|
||||||
|
panel: "=",
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
PanelBaseCtrl,
|
PanelBaseCtrl,
|
||||||
TestPanelCtrl,
|
TestPanelCtrl,
|
||||||
testPanelDirective as panel
|
testPanelComponent as component,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user