Commit a867dc06 by Torkel Ödegaard

tech: got angular component to load inside react grid

parent 63bf2a02
......@@ -24,6 +24,7 @@ define([
'./ad_hoc_filters',
'./repeat_option/repeat_option',
'./dashgrid/DashboardGrid',
'./dashgrid/PanelLoader',
'./acl/acl',
'./folder_picker/picker',
'./folder_modal/folder'
......
///<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}],
]);
});
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() {
......
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);
......@@ -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&#45;grid dashboard="dashboard"></dash&#45;grid> -->
<dashboard-grid dashboard="dashboard"></dashboard-grid>
<dashboard-grid dashboard="dashboard" get-panel-loader="getPanelLoader">
</dashboard-grid>
</div>
</div>
......
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