Files
karma/assets/static/ui.js
Łukasz Mierzwa f1e90e054d Rewrite clientside-haml-js templates using underscore
Drop haml templates in favor of underscore. Haml templates are harder to maintain and require extra dependencies, we already have underscore.js included and it provides a fast templating engine. Rewrite all client side templates using it.
Performance with underscore is pretty much the same as with haml (with 10k alerts).
2017-04-10 11:38:34 -07:00

90 lines
2.8 KiB
JavaScript

var UI = (function(params) {
// when user click on any alert label modal popup with a list of possible
// filter will show, this function is used to setup that modal
setupModal = function() {
$('#labelModal').on('show.bs.modal', function(event) {
Unsee.Pause();
var modal = $(this);
var label = $(event.relatedTarget);
var label_key = label.data('label-key');
var label_val = label.data('label-val');
var attrs = Alerts.GetLabelAttrs(label_key, label_val);
var counter = Summary.Get(label_key, label_val);
modal.find('.modal-title').html(
Templates.Render('modalTitle', {
attrs: attrs,
counter: counter
})
);
var hints = Autocomplete.GenerateHints(label_key, label_val);
modal.find('.modal-body').html(
Templates.Render('modalBody', {hints: hints})
);
modal.on('click', '.modal-button-filter', function(elem) {
var filter = $(elem.target).data('filter-append-value');
$('#labelModal').modal('hide');
Filters.AddFilter(filter);
});
});
$('#labelModal').on('hidden.bs.modal', function(event) {
var modal = $(this);
modal.find('.modal-title').children().remove();
modal.find('.modal-body').children().remove();
Unsee.WaitForNextReload();
});
}
// each alert group have a link generated for it, but we hide it until
// user hovers over that group so it doesn't trash the UI
setupGroupLinkHover = function(elem) {
$(elem).on('mouseenter', function() {
$(this).find('.alert-group-link > a').finish().animate({
opacity: 100
}, 200);
});
$(elem).on('mouseleave', function() {
$(this).find('.alert-group-link > a').finish().animate({
opacity: 0
}, 200);
});
}
// find all elements inside alert group panel that will use tooltips
// and setup those
setupGroupTooltips = function(groupElem) {
$.each(groupElem.find('[data-toggle=tooltip]'), function(i, elem) {
$(elem).tooltip({
animation: false, // slows down tooltip removal
delay: {
show: 500,
hide: 0
},
title: $(elem).attr('title') || $(elem).data('ts-title'),
trigger: 'hover'
});
});
}
setupAlertGroupUI = function(elem) {
setupGroupLinkHover(elem);
setupGroupTooltips(elem);
}
init = function() {
setupModal();
}
return {
Init: init,
SetupAlertGroupUI: setupAlertGroupUI
}
})();