2019-06-13 20:04:15 +02:00
|
|
|
import { auto } from 'angular';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { isString } from 'lodash';
|
|
|
|
|
|
2020-12-23 10:45:31 +01:00
|
|
|
import {
|
|
|
|
|
AppEvent,
|
|
|
|
|
PanelEvents,
|
|
|
|
|
PanelPluginMeta,
|
|
|
|
|
AngularPanelMenuItem,
|
|
|
|
|
EventBusExtended,
|
|
|
|
|
EventBusSrv,
|
|
|
|
|
} from '@grafana/data';
|
2021-07-07 18:39:10 +02:00
|
|
|
import { AngularLocationWrapper } from 'app/angular/AngularLocationWrapper';
|
2022-04-22 14:33:13 +01:00
|
|
|
import config from 'app/core/config';
|
|
|
|
|
import { profiler } from 'app/core/core';
|
|
|
|
|
|
|
|
|
|
import { DashboardModel } from '../../features/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;
|
2021-07-23 15:33:53 +01:00
|
|
|
declare dashboard: DashboardModel;
|
2021-04-29 16:54:38 +03:00
|
|
|
pluginName = '';
|
|
|
|
|
pluginId = '';
|
2016-01-24 18:44:21 -05:00
|
|
|
editorTabs: any;
|
|
|
|
|
$scope: any;
|
2019-06-13 20:04:15 +02:00
|
|
|
$injector: auto.IInjectorService;
|
2016-01-27 13:22:37 -05:00
|
|
|
$timeout: any;
|
2021-04-29 16:54:38 +03:00
|
|
|
editModeInitiated = false;
|
2021-07-22 08:09:55 +01:00
|
|
|
declare height: number;
|
|
|
|
|
declare width: number;
|
2016-03-06 12:34:47 +01:00
|
|
|
containerHeight: any;
|
2020-11-03 13:08:54 +01:00
|
|
|
events: EventBusExtended;
|
2021-04-29 16:54:38 +03:00
|
|
|
loading = false;
|
2019-02-01 08:12:58 +01:00
|
|
|
timing: any;
|
2021-07-07 18:39:10 +02:00
|
|
|
$location: AngularLocationWrapper;
|
2016-01-24 18:44:21 -05:00
|
|
|
|
2019-06-13 20:04:15 +02:00
|
|
|
constructor($scope: any, $injector: auto.IInjectorService) {
|
2021-03-31 17:03:07 +02:00
|
|
|
this.panel = this.panel ?? $scope.$parent.panel;
|
|
|
|
|
this.dashboard = this.dashboard ?? $scope.$parent.dashboard;
|
2016-01-25 15:58:24 -05:00
|
|
|
this.$injector = $injector;
|
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 = [];
|
2021-07-07 18:39:10 +02:00
|
|
|
this.$location = new AngularLocationWrapper();
|
2020-12-23 10:45:31 +01:00
|
|
|
this.events = new EventBusSrv();
|
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);
|
2021-01-08 14:25:37 +01:00
|
|
|
this.events.emit(PanelEvents.initialized);
|
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
|
|
|
|
2021-04-21 08:38:00 +01: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
|
|
|
}
|