2021-04-21 08:38:00 +01:00
|
|
|
import { extend } from 'lodash';
|
2021-11-09 08:37:16 +01:00
|
|
|
import coreModule from 'app/angular/core_module';
|
2019-08-01 14:38:34 +02:00
|
|
|
// @ts-ignore
|
2017-12-20 12:33:33 +01:00
|
|
|
import Drop from 'tether-drop';
|
2021-11-10 11:05:36 +01:00
|
|
|
import { GrafanaRootScope } from 'app/angular/GrafanaCtrl';
|
2016-02-22 14:20:34 +01:00
|
|
|
|
2018-08-31 16:40:43 +02:00
|
|
|
/** @ngInject */
|
2019-10-14 09:27:47 +01:00
|
|
|
function popoverSrv(this: any, $compile: any, $rootScope: GrafanaRootScope, $timeout: any) {
|
2019-08-01 14:38:34 +02:00
|
|
|
let openDrop: any = null;
|
2017-04-14 11:41:02 +02:00
|
|
|
|
2018-09-05 07:47:30 +02:00
|
|
|
this.close = () => {
|
2017-04-14 11:41:02 +02:00
|
|
|
if (openDrop) {
|
|
|
|
|
openDrop.close();
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-02-22 14:20:34 +01:00
|
|
|
|
2019-08-01 14:38:34 +02:00
|
|
|
this.show = (options: any) => {
|
2017-04-14 11:41:02 +02:00
|
|
|
if (openDrop) {
|
|
|
|
|
openDrop.close();
|
2017-04-14 12:23:32 +02:00
|
|
|
openDrop = null;
|
2017-04-14 11:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-21 08:38:00 +01:00
|
|
|
const scope = extend($rootScope.$new(true), options.model);
|
2019-08-01 14:38:34 +02:00
|
|
|
let drop: any;
|
2016-02-22 18:46:58 +01:00
|
|
|
|
2018-08-26 21:52:57 +02:00
|
|
|
const cleanUp = () => {
|
2017-04-14 11:41:02 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
|
scope.$destroy();
|
2017-04-14 12:23:32 +02:00
|
|
|
|
|
|
|
|
if (drop.tether) {
|
|
|
|
|
drop.destroy();
|
|
|
|
|
}
|
2017-04-13 18:39:49 +02:00
|
|
|
|
2017-04-14 11:41:02 +02:00
|
|
|
if (options.onClose) {
|
|
|
|
|
options.onClose();
|
2016-02-22 18:46:58 +01:00
|
|
|
}
|
|
|
|
|
});
|
2017-04-14 12:23:32 +02:00
|
|
|
|
|
|
|
|
openDrop = null;
|
2017-04-14 11:41:02 +02:00
|
|
|
};
|
2016-02-22 18:46:58 +01:00
|
|
|
|
2017-04-14 11:41:02 +02:00
|
|
|
scope.dismiss = () => {
|
|
|
|
|
drop.close();
|
2016-02-22 18:46:58 +01:00
|
|
|
};
|
|
|
|
|
|
2018-08-26 21:52:57 +02:00
|
|
|
const contentElement = document.createElement('div');
|
2016-02-22 18:46:58 +01:00
|
|
|
contentElement.innerHTML = options.template;
|
2016-02-22 14:20:34 +01:00
|
|
|
|
2017-04-14 11:41:02 +02:00
|
|
|
$compile(contentElement)(scope);
|
2016-02-22 18:46:58 +01:00
|
|
|
|
2017-04-14 12:23:32 +02:00
|
|
|
$timeout(() => {
|
|
|
|
|
drop = new Drop({
|
|
|
|
|
target: options.element,
|
|
|
|
|
content: contentElement,
|
|
|
|
|
position: options.position,
|
2017-12-20 12:33:33 +01:00
|
|
|
classes: options.classNames || 'drop-popover',
|
2017-04-14 12:23:32 +02:00
|
|
|
openOn: options.openOn,
|
|
|
|
|
hoverCloseDelay: 200,
|
|
|
|
|
tetherOptions: {
|
2017-12-20 12:33:33 +01:00
|
|
|
constraints: [{ to: 'scrollParent', attachment: 'together' }],
|
|
|
|
|
},
|
2017-04-14 12:23:32 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
drop.on('close', () => {
|
2017-04-14 12:23:32 +02:00
|
|
|
cleanUp();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
openDrop = drop;
|
|
|
|
|
openDrop.open();
|
2017-04-14 12:46:02 +02:00
|
|
|
}, 100);
|
2017-12-03 07:53:47 +01:00
|
|
|
|
|
|
|
|
// return close function
|
2018-09-05 07:47:30 +02:00
|
|
|
return () => {
|
2017-12-03 07:53:47 +01:00
|
|
|
if (drop) {
|
|
|
|
|
drop.close();
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-02-22 14:20:34 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
coreModule.service('popoverSrv', popoverSrv);
|