2017-12-20 12:33:33 +01:00
|
|
|
import _ from 'lodash';
|
2018-11-14 13:20:19 +01:00
|
|
|
import config from 'app/core/config';
|
2020-02-09 10:53:34 +01:00
|
|
|
import { profiler } from 'app/core/core';
|
|
|
|
|
import { Emitter } from 'app/core/utils/emitter';
|
2019-06-13 20:04:15 +02:00
|
|
|
import { auto } from 'angular';
|
2020-02-09 10:53:34 +01:00
|
|
|
import { AppEvent, PanelEvents, PanelPluginMeta, AngularPanelMenuItem } from '@grafana/data';
|
2020-01-02 08:11:28 -08:00
|
|
|
import { DashboardModel } from '../dashboard/state';
|
2019-06-25 11:38:51 +02:00
|
|
|
|
2016-01-24 18:44:21 -05:00
|
|
|
export class PanelCtrl {
|
|
|
|
|
panel: any;
|
2016-12-16 10:34:00 +01:00
|
|
|
error: any;
|
2020-01-02 08:11:28 -08:00
|
|
|
dashboard: DashboardModel;
|
2016-01-26 17:28:07 -05:00
|
|
|
pluginName: string;
|
|
|
|
|
pluginId: string;
|
2016-01-24 18:44:21 -05:00
|
|
|
editorTabs: any;
|
|
|
|
|
$scope: any;
|
2019-06-13 20:04:15 +02:00
|
|
|
$injector: auto.IInjectorService;
|
2018-04-27 18:21:20 +02:00
|
|
|
$location: any;
|
2016-01-27 13:22:37 -05:00
|
|
|
$timeout: any;
|
2016-01-26 17:28:07 -05:00
|
|
|
editModeInitiated: boolean;
|
2020-02-09 10:53:34 +01:00
|
|
|
height: number;
|
|
|
|
|
width: number;
|
2016-03-06 12:34:47 +01:00
|
|
|
containerHeight: any;
|
2016-03-22 18:21:21 +01:00
|
|
|
events: Emitter;
|
2017-11-20 11:27:18 +01:00
|
|
|
loading: boolean;
|
2019-02-01 08:12:58 +01:00
|
|
|
timing: any;
|
2016-01-24 18:44:21 -05:00
|
|
|
|
2019-06-13 20:04:15 +02:00
|
|
|
constructor($scope: any, $injector: auto.IInjectorService) {
|
2016-01-25 15:58:24 -05:00
|
|
|
this.$injector = $injector;
|
2018-04-27 18:21:20 +02:00
|
|
|
this.$location = $injector.get('$location');
|
2016-01-24 18:44:21 -05:00
|
|
|
this.$scope = $scope;
|
2017-12-20 12:33:33 +01:00
|
|
|
this.$timeout = $injector.get('$timeout');
|
2018-12-19 17:00:26 +01:00
|
|
|
this.editorTabs = [];
|
2017-10-10 14:20:53 +02:00
|
|
|
this.events = this.panel.events;
|
2019-02-01 08:12:58 +01:00
|
|
|
this.timing = {}; // not used but here to not break plugins
|
2016-01-25 11:41:20 -05:00
|
|
|
|
2018-08-29 14:26:50 +02:00
|
|
|
const plugin = config.panels[this.panel.type];
|
2016-01-27 17:16:00 -05:00
|
|
|
if (plugin) {
|
|
|
|
|
this.pluginId = plugin.id;
|
|
|
|
|
this.pluginName = plugin.name;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 09:27:47 +01:00
|
|
|
$scope.$on(PanelEvents.componentDidMount.name, () => this.panelDidMount());
|
2016-01-25 11:41:20 -05:00
|
|
|
}
|
|
|
|
|
|
2017-11-22 13:32:54 +01:00
|
|
|
panelDidMount() {
|
2019-10-14 09:27:47 +01:00
|
|
|
this.events.emit(PanelEvents.componentDidMount);
|
2018-09-10 16:19:28 +02:00
|
|
|
this.dashboard.panelInitialized(this.panel);
|
2016-01-25 17:51:18 -05:00
|
|
|
}
|
|
|
|
|
|
2016-01-25 17:58:41 -05:00
|
|
|
renderingCompleted() {
|
2019-05-13 09:38:19 +02:00
|
|
|
profiler.renderingCompleted();
|
2016-01-25 17:58:41 -05:00
|
|
|
}
|
|
|
|
|
|
2016-01-25 11:41:20 -05:00
|
|
|
refresh() {
|
2018-08-25 08:49:39 -07:00
|
|
|
this.panel.refresh();
|
2016-01-24 18:44:21 -05:00
|
|
|
}
|
|
|
|
|
|
2019-10-14 09:27:47 +01:00
|
|
|
publishAppEvent<T>(event: AppEvent<T>, payload?: T) {
|
|
|
|
|
this.$scope.$root.appEvent(event, payload);
|
2016-01-24 18:44:21 -05:00
|
|
|
}
|
|
|
|
|
|
2016-01-26 12:22:46 -05:00
|
|
|
initEditMode() {
|
2018-12-19 17:00:26 +01:00
|
|
|
if (!this.editModeInitiated) {
|
|
|
|
|
this.editModeInitiated = true;
|
2019-10-14 09:27:47 +01:00
|
|
|
this.events.emit(PanelEvents.editModeInitialized);
|
2018-12-19 17:00:26 +01:00
|
|
|
}
|
2016-05-19 08:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 20:04:15 +02:00
|
|
|
addEditorTab(title: string, directiveFn: any, index?: number, icon?: any) {
|
2018-09-10 15:42:36 +02:00
|
|
|
const editorTab = { title, directiveFn, icon };
|
2016-01-28 12:48:43 -05:00
|
|
|
|
|
|
|
|
if (_.isString(directiveFn)) {
|
2018-09-04 17:02:32 +02:00
|
|
|
editorTab.directiveFn = () => {
|
2017-12-19 14:55:03 +01:00
|
|
|
return { templateUrl: directiveFn };
|
2016-01-28 12:48:43 -05:00
|
|
|
};
|
|
|
|
|
}
|
2018-06-19 16:57:55 +02:00
|
|
|
|
2016-01-28 16:48:37 -05:00
|
|
|
if (index) {
|
|
|
|
|
this.editorTabs.splice(index, 0, editorTab);
|
|
|
|
|
} else {
|
|
|
|
|
this.editorTabs.push(editorTab);
|
|
|
|
|
}
|
2016-01-24 18:44:21 -05:00
|
|
|
}
|
|
|
|
|
|
2016-01-27 17:16:00 -05:00
|
|
|
getExtendedMenu() {
|
2020-02-09 10:53:34 +01:00
|
|
|
const menu: AngularPanelMenuItem[] = [];
|
2019-10-14 09:27:47 +01:00
|
|
|
this.events.emit(PanelEvents.initPanelActions, menu);
|
2017-10-14 21:17:16 +02:00
|
|
|
return menu;
|
2016-01-27 17:16:00 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-29 14:02:32 +02:00
|
|
|
// Override in sub-class to add items before extended menu
|
2019-09-02 12:47:33 +02:00
|
|
|
async getAdditionalMenuItems(): Promise<any[]> {
|
2018-04-29 14:02:32 +02:00
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 15:09:37 -05:00
|
|
|
otherPanelInFullscreenMode() {
|
2020-04-10 16:37:26 +02:00
|
|
|
return this.dashboard.otherPanelInFullscreen(this.panel);
|
2016-01-25 15:09:37 -05:00
|
|
|
}
|
2016-01-26 17:28:07 -05:00
|
|
|
|
2019-06-13 20:04:15 +02:00
|
|
|
render(payload?: any) {
|
2019-10-14 09:27:47 +01:00
|
|
|
this.events.emit(PanelEvents.render, payload);
|
2016-01-26 17:28:07 -05:00
|
|
|
}
|
2016-01-26 18:08:08 -05:00
|
|
|
|
2019-08-18 15:01:07 -07:00
|
|
|
// overriden from react
|
|
|
|
|
onPluginTypeChange = (plugin: PanelPluginMeta) => {};
|
2016-01-24 18:44:21 -05:00
|
|
|
}
|