mirror of
https://github.com/grafana/grafana.git
synced 2025-01-27 08:47:12 -06:00
tech: got angular component to load inside react grid
This commit is contained in:
parent
63bf2a0278
commit
a867dc069b
@ -24,6 +24,7 @@ define([
|
||||
'./ad_hoc_filters',
|
||||
'./repeat_option/repeat_option',
|
||||
'./dashgrid/DashboardGrid',
|
||||
'./dashgrid/PanelLoader',
|
||||
'./acl/acl',
|
||||
'./folder_picker/picker',
|
||||
'./folder_modal/folder'
|
||||
|
@ -1,5 +1,3 @@
|
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import config from 'app/core/config';
|
||||
import angular from 'angular';
|
||||
|
||||
@ -19,6 +17,7 @@ export class DashboardCtrl {
|
||||
unsavedChangesSrv,
|
||||
dynamicDashboardSrv,
|
||||
dashboardViewStateSrv,
|
||||
panelLoader,
|
||||
contextSrv,
|
||||
alertSrv,
|
||||
$timeout) {
|
||||
@ -131,6 +130,10 @@ export class DashboardCtrl {
|
||||
$scope.dashboard.meta.folderId = folder.id;
|
||||
$scope.dashboard.meta.folderTitle= folder.title;
|
||||
};
|
||||
|
||||
$scope.getPanelLoader = function() {
|
||||
return panelLoader;
|
||||
};
|
||||
}
|
||||
|
||||
init(dashboard) {
|
||||
|
@ -3,9 +3,10 @@ import coreModule from 'app/core/core_module';
|
||||
import ReactGridLayout from 'react-grid-layout';
|
||||
import {DashboardModel} from '../model';
|
||||
import {DashboardPanel} from './DashboardPanel';
|
||||
import {PanelLoader} from './PanelLoader';
|
||||
import sizeMe from 'react-sizeme';
|
||||
|
||||
const COLUMN_COUNT = 24;
|
||||
const COLUMN_COUNT = 12;
|
||||
const ROW_HEIGHT = 30;
|
||||
|
||||
function GridWrapper({size, layout, onLayoutChange, children}) {
|
||||
@ -37,6 +38,7 @@ const SizedReactLayoutGrid = sizeMe({monitorWidth: true})(GridWrapper);
|
||||
|
||||
export interface DashboardGridProps {
|
||||
dashboard: DashboardModel;
|
||||
getPanelLoader: () => PanelLoader;
|
||||
}
|
||||
|
||||
export class DashboardGrid extends React.Component<DashboardGridProps, any> {
|
||||
@ -69,7 +71,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
|
||||
for (let panel of this.props.dashboard.panels) {
|
||||
panelElements.push(
|
||||
<div key={panel.id.toString()} className="panel">
|
||||
<DashboardPanel panel={panel} />
|
||||
<DashboardPanel panel={panel} getPanelLoader={this.props.getPanelLoader} dashboard={this.props.dashboard} />
|
||||
</div>,
|
||||
);
|
||||
}
|
||||
@ -86,5 +88,8 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
|
||||
}
|
||||
|
||||
coreModule.directive('dashboardGrid', function(reactDirective) {
|
||||
return reactDirective(DashboardGrid, [['dashboard', {watchDepth: 'reference'}]]);
|
||||
return reactDirective(DashboardGrid, [
|
||||
['dashboard', {watchDepth: 'reference'}],
|
||||
['getPanelLoader', {watchDepth: 'reference', wrapApply: false}],
|
||||
]);
|
||||
});
|
||||
|
@ -1,7 +1,10 @@
|
||||
import React from 'react';
|
||||
import {PanelLoader} from './PanelLoader';
|
||||
|
||||
export interface DashboardPanelProps {
|
||||
panel: any;
|
||||
dashboard: any;
|
||||
getPanelLoader: () => PanelLoader;
|
||||
}
|
||||
|
||||
export class DashboardPanel extends React.Component<DashboardPanelProps, any> {
|
||||
@ -13,6 +16,8 @@ export class DashboardPanel extends React.Component<DashboardPanelProps, any> {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
var loader = this.props.getPanelLoader();
|
||||
loader.load(this.element, this.props.panel, this.props.dashboard);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
33
public/app/features/dashboard/dashgrid/PanelLoader.ts
Normal file
33
public/app/features/dashboard/dashgrid/PanelLoader.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import angular from 'angular';
|
||||
import coreModule from 'app/core/core_module';
|
||||
|
||||
export interface AttachedPanel {
|
||||
destroy();
|
||||
}
|
||||
|
||||
export class PanelLoader {
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private $compile, private $rootScope) {
|
||||
}
|
||||
|
||||
load(elem, panel, dashboard): AttachedPanel {
|
||||
var template = '<plugin-component type="panel"></plugin-component>';
|
||||
var panelScope = this.$rootScope.$new();
|
||||
panelScope.panel = panel;
|
||||
panelScope.dashboard = dashboard;
|
||||
|
||||
const compiledElem = this.$compile(template)(panelScope);
|
||||
const rootNode = angular.element(elem);
|
||||
rootNode.append(compiledElem);
|
||||
|
||||
return {
|
||||
destroy: () => {
|
||||
panelScope.$destroy();
|
||||
compiledElem.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
coreModule.service('panelLoader', PanelLoader);
|
@ -1,3 +0,0 @@
|
||||
import coreModule from 'app/core/core';
|
||||
|
||||
|
@ -68,7 +68,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
||||
var componentInfo: any = {
|
||||
name: 'panel-plugin-' + scope.panel.type,
|
||||
bindings: {dashboard: "=", panel: "=", row: "="},
|
||||
attrs: {dashboard: "ctrl.dashboard", panel: "panel", row: "ctrl.row"},
|
||||
attrs: {dashboard: "dashboard", panel: "panel"},
|
||||
};
|
||||
|
||||
let panelInfo = config.panels[scope.panel.type];
|
||||
|
@ -9,7 +9,8 @@
|
||||
<dashboard-submenu ng-if="dashboard.meta.submenuEnabled" dashboard="dashboard"></dashboard-submenu>
|
||||
|
||||
<!-- <dash-grid dashboard="dashboard"></dash-grid> -->
|
||||
<dashboard-grid dashboard="dashboard"></dashboard-grid>
|
||||
<dashboard-grid dashboard="dashboard" get-panel-loader="getPanelLoader">
|
||||
</dashboard-grid>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user