2019-07-18 14:03:04 +08:00
|
|
|
// @ts-ignore
|
2018-03-28 04:27:23 +08:00
|
|
|
import baron from 'baron';
|
2022-04-22 21:33:13 +08:00
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
|
|
2019-10-31 17:48:05 +08:00
|
|
|
import { PanelEvents } from '@grafana/data';
|
2022-04-22 21:33:13 +08:00
|
|
|
import { RefreshEvent } from '@grafana/runtime';
|
|
|
|
|
import { coreModule } from 'app/angular/core_module';
|
|
|
|
|
import { PanelDirectiveReadyEvent, RenderEvent } from 'app/types/events';
|
|
|
|
|
|
2021-10-13 22:59:47 +08:00
|
|
|
import { PanelModel } from '../../features/dashboard/state';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
2020-02-09 17:53:34 +08:00
|
|
|
import { PanelCtrl } from './panel_ctrl';
|
2016-02-01 19:42:10 +08:00
|
|
|
|
2018-08-27 02:19:23 +08:00
|
|
|
const panelTemplate = `
|
2020-02-09 17:53:34 +08:00
|
|
|
<ng-transclude class="panel-height-helper"></ng-transclude>
|
2016-02-05 18:05:47 +08:00
|
|
|
`;
|
|
|
|
|
|
2021-04-01 16:32:00 +08:00
|
|
|
coreModule.directive('grafanaPanel', ($rootScope, $document, $timeout) => {
|
2016-02-01 19:42:10 +08:00
|
|
|
return {
|
2017-12-20 19:33:33 +08:00
|
|
|
restrict: 'E',
|
2016-02-05 18:05:47 +08:00
|
|
|
template: panelTemplate,
|
2016-02-01 19:42:10 +08:00
|
|
|
transclude: true,
|
2017-12-20 19:33:33 +08:00
|
|
|
scope: { ctrl: '=' },
|
2019-03-12 22:27:02 +08:00
|
|
|
link: (scope: any, elem) => {
|
2020-02-09 17:53:34 +08:00
|
|
|
const ctrl: PanelCtrl = scope.ctrl;
|
|
|
|
|
const panel: PanelModel = scope.ctrl.panel;
|
2020-12-23 17:45:31 +08:00
|
|
|
const subs = new Subscription();
|
2018-11-20 00:41:48 +08:00
|
|
|
|
2020-02-09 17:53:34 +08:00
|
|
|
let panelScrollbar: any;
|
2018-11-20 00:41:48 +08:00
|
|
|
|
2018-03-28 04:27:23 +08:00
|
|
|
function resizeScrollableContent() {
|
2017-11-22 14:05:33 +08:00
|
|
|
if (panelScrollbar) {
|
|
|
|
|
panelScrollbar.update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 16:27:47 +08:00
|
|
|
ctrl.events.on(PanelEvents.componentDidMount, () => {
|
2020-02-09 17:53:34 +08:00
|
|
|
if ((ctrl as any).__proto__.constructor.scrollable) {
|
2018-03-28 04:27:23 +08:00
|
|
|
const scrollRootClass = 'baron baron__root baron__clipper panel-content--scrollable';
|
|
|
|
|
const scrollerClass = 'baron__scroller';
|
|
|
|
|
const scrollBarHTML = `
|
|
|
|
|
<div class="baron__track">
|
|
|
|
|
<div class="baron__bar"></div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
2020-02-09 17:53:34 +08:00
|
|
|
const scrollRoot = elem;
|
|
|
|
|
const scroller = elem.find(':first').find(':first');
|
2018-04-11 23:38:53 +08:00
|
|
|
|
2018-03-28 04:27:23 +08:00
|
|
|
scrollRoot.addClass(scrollRootClass);
|
|
|
|
|
$(scrollBarHTML).appendTo(scrollRoot);
|
|
|
|
|
scroller.addClass(scrollerClass);
|
|
|
|
|
|
|
|
|
|
panelScrollbar = baron({
|
|
|
|
|
root: scrollRoot[0],
|
|
|
|
|
scroller: scroller[0],
|
|
|
|
|
bar: '.baron__bar',
|
|
|
|
|
barOnCls: '_scrollbar',
|
|
|
|
|
scrollingCls: '_scrolling',
|
2018-02-06 01:11:43 +08:00
|
|
|
});
|
2018-04-07 01:00:03 +08:00
|
|
|
|
|
|
|
|
panelScrollbar.scroll();
|
2017-11-22 21:46:17 +08:00
|
|
|
}
|
2017-11-22 20:32:54 +08:00
|
|
|
});
|
|
|
|
|
|
2020-12-23 17:45:31 +08:00
|
|
|
function updateDimensionsFromParentScope() {
|
2020-02-09 17:53:34 +08:00
|
|
|
ctrl.height = scope.$parent.$parent.size.height;
|
|
|
|
|
ctrl.width = scope.$parent.$parent.size.width;
|
|
|
|
|
}
|
2016-12-16 17:34:00 +08:00
|
|
|
|
2021-01-08 22:20:02 +08:00
|
|
|
updateDimensionsFromParentScope();
|
|
|
|
|
|
2020-12-23 17:45:31 +08:00
|
|
|
// Pass PanelModel events down to angular controller event emitter
|
|
|
|
|
subs.add(
|
|
|
|
|
panel.events.subscribe(RefreshEvent, () => {
|
|
|
|
|
updateDimensionsFromParentScope();
|
|
|
|
|
ctrl.events.emit('refresh');
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
subs.add(
|
2021-02-04 16:15:01 +08:00
|
|
|
panel.events.subscribe(RenderEvent, (event) => {
|
|
|
|
|
// this event originated from angular so no need to bubble it back
|
|
|
|
|
if (event.payload?.fromAngular) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 17:45:31 +08:00
|
|
|
updateDimensionsFromParentScope();
|
|
|
|
|
|
|
|
|
|
$timeout(() => {
|
|
|
|
|
resizeScrollableContent();
|
|
|
|
|
ctrl.events.emit('render');
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
);
|
2019-11-06 07:20:04 +08:00
|
|
|
|
2021-02-04 16:15:01 +08:00
|
|
|
subs.add(
|
|
|
|
|
ctrl.events.subscribe(RenderEvent, (event) => {
|
|
|
|
|
// this event originated from angular so bubble it to react so the PanelChromeAngular can update the panel header alert state
|
|
|
|
|
if (event.payload) {
|
|
|
|
|
event.payload.fromAngular = true;
|
|
|
|
|
panel.events.publish(event);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
2018-09-05 13:47:30 +08:00
|
|
|
scope.$on('$destroy', () => {
|
2016-11-03 05:08:17 +08:00
|
|
|
elem.off();
|
2016-12-16 17:34:00 +08:00
|
|
|
|
2020-12-23 17:45:31 +08:00
|
|
|
// Remove PanelModel.event subs
|
|
|
|
|
subs.unsubscribe();
|
|
|
|
|
// Remove Angular controller event subs
|
|
|
|
|
ctrl.events.emit(PanelEvents.panelTeardown);
|
|
|
|
|
ctrl.events.removeAllListeners();
|
2020-05-04 20:11:15 +08:00
|
|
|
|
2017-11-23 18:12:32 +08:00
|
|
|
if (panelScrollbar) {
|
2018-03-28 04:27:23 +08:00
|
|
|
panelScrollbar.dispose();
|
2017-11-23 18:12:32 +08:00
|
|
|
}
|
2016-11-02 22:16:48 +08:00
|
|
|
});
|
2021-06-02 20:35:12 +08:00
|
|
|
|
|
|
|
|
panel.events.publish(PanelDirectiveReadyEvent);
|
2017-12-20 19:33:33 +08:00
|
|
|
},
|
2016-02-01 19:42:10 +08:00
|
|
|
};
|
|
|
|
|
});
|