The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/core/services/popover_srv.ts

79 lines
1.6 KiB

import _ from 'lodash';
import coreModule from 'app/core/core_module';
import Drop from 'tether-drop';
/** @ngInject */
function popoverSrv(this: any, $compile, $rootScope, $timeout) {
let openDrop = null;
this.close = () => {
if (openDrop) {
openDrop.close();
}
};
this.show = options => {
if (openDrop) {
openDrop.close();
openDrop = null;
}
const scope = _.extend($rootScope.$new(true), options.model);
let drop;
const cleanUp = () => {
setTimeout(() => {
scope.$destroy();
if (drop.tether) {
drop.destroy();
}
if (options.onClose) {
options.onClose();
}
});
openDrop = null;
};
scope.dismiss = () => {
drop.close();
};
const contentElement = document.createElement('div');
contentElement.innerHTML = options.template;
$compile(contentElement)(scope);
$timeout(() => {
drop = new Drop({
target: options.element,
content: contentElement,
position: options.position,
classes: options.classNames || 'drop-popover',
openOn: options.openOn,
hoverCloseDelay: 200,
tetherOptions: {
constraints: [{ to: 'scrollParent', attachment: 'together' }],
},
});
drop.on('close', () => {
cleanUp();
});
openDrop = drop;
openDrop.open();
}, 100);
// return close function
return () => {
if (drop) {
drop.close();
}
};
};
}
coreModule.service('popoverSrv', popoverSrv);