tooltips for function definitions

This commit is contained in:
Dan Cech 2017-12-27 22:29:19 -05:00
parent 80a6e0d8d1
commit 4d3bac0284
No known key found for this signature in database
GPG Key ID: 6F1146C5B66FBD41
2 changed files with 59 additions and 5 deletions

View File

@ -2,13 +2,15 @@ define([
'angular', 'angular',
'lodash', 'lodash',
'jquery', 'jquery',
'rst2html',
'tether-drop',
], ],
function (angular, _, $) { function (angular, _, $, rst2html, Drop) {
'use strict'; 'use strict';
angular angular
.module('grafana.directives') .module('grafana.directives')
.directive('graphiteAddFunc', function($compile) { .directive('graphiteAddFunc', function($compile) {
var inputTemplate = '<input type="text"'+ var inputTemplate = '<input type="text"'+
' class="gf-form-input"' + ' class="gf-form-input"' +
' spellcheck="false" style="display:none"></input>'; ' spellcheck="false" style="display:none"></input>';
@ -81,6 +83,52 @@ function (angular, _, $) {
$compile(elem.contents())($scope); $compile(elem.contents())($scope);
}); });
var drops = [];
$(elem)
.on('mouseenter', 'ul.dropdown-menu li', function () {
while (drops.length > 0) {
drops.pop().remove();
}
var funcDef;
try {
funcDef = ctrl.datasource.getFuncDef($('a', this).text());
} catch (e) {
// ignore
}
if (funcDef && funcDef.description) {
var shortDesc = funcDef.description;
if (shortDesc.length > 500) {
shortDesc = shortDesc.substring(0, 497) + '...';
}
var contentElement = document.createElement('div');
contentElement.innerHTML = '<h4>' + funcDef.name + '</h4>' + rst2html(shortDesc);
var drop = new Drop({
target: this,
content: contentElement,
classes: 'drop-popover',
openOn: 'always',
tetherOptions: {
attachment: 'bottom left',
targetAttachment: 'bottom right',
},
});
drops.push(drop);
drop.open();
}
})
.on('mouseout', 'ul.dropdown-menu li', function() {
while (drops.length > 0) {
drops.pop().remove();
}
});
} }
}; };
}); });

View File

@ -9,7 +9,7 @@ function (angular, _, $, rst2html) {
angular angular
.module('grafana.directives') .module('grafana.directives')
.directive('graphiteFuncEditor', function($compile, templateSrv) { .directive('graphiteFuncEditor', function($compile, templateSrv, popoverSrv) {
var funcSpanTemplate = '<a ng-click="">{{func.def.name}}</a><span>(</span>'; var funcSpanTemplate = '<a ng-click="">{{func.def.name}}</a><span>(</span>';
var paramTemplate = '<input type="text" style="display:none"' + var paramTemplate = '<input type="text" style="display:none"' +
@ -259,8 +259,14 @@ function (angular, _, $, rst2html) {
} }
if ($target.hasClass('fa-question-circle')) { if ($target.hasClass('fa-question-circle')) {
if (func.def.description) { var funcDef = ctrl.datasource.getFuncDef(func.def.name);
alert(rst2html(func.def.description)); if (funcDef && funcDef.description) {
popoverSrv.show({
element: e.target,
position: 'bottom left',
template: '<div><h4>' + funcDef.name + '</h4>' + rst2html(funcDef.description) + '</div>',
openOn: 'click',
});
} else { } else {
window.open( window.open(
"http://graphite.readthedocs.org/en/latest/functions.html#graphite.render.functions." + func.def.name,'_blank'); "http://graphite.readthedocs.org/en/latest/functions.html#graphite.render.functions." + func.def.name,'_blank');