mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
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).
84 lines
1.8 KiB
JavaScript
84 lines
1.8 KiB
JavaScript
var Summary = (function() {
|
|
|
|
|
|
var summary, templates;
|
|
|
|
render = function() {
|
|
var top_tags = [];
|
|
$.each(summary, function(k, v) {
|
|
top_tags.push({
|
|
name: k,
|
|
val: v
|
|
});
|
|
});
|
|
top_tags.sort(function(a, b) {
|
|
if (a.val > b.val) return 1;
|
|
if (a.val < b.val) return -1;
|
|
if (a.name > b.name) return -1;
|
|
if (a.name < b.name) return 1;
|
|
return 0;
|
|
}).reverse();
|
|
|
|
var tags = [];
|
|
$.each(top_tags.slice(0, 10), function(i, tag) {
|
|
var label_key = tag.name.split(': ')[0];
|
|
var label_val = tag.name.split(': ')[1];
|
|
tag.style = Colors.Get(label_key, label_val);
|
|
tag.cls = Colors.GetClass(label_key, label_val);
|
|
tags.push(tag);
|
|
});
|
|
|
|
return Templates.Render('breakdownContent', {tags: tags});
|
|
}
|
|
|
|
|
|
init = function() {
|
|
summary = {};
|
|
$('.navbar-header').popover({
|
|
trigger: 'hover',
|
|
container: 'body',
|
|
html: true,
|
|
placement: 'bottom',
|
|
title: 'Top labels',
|
|
content: render,
|
|
template: Templates.Render('breakdown', {})
|
|
});
|
|
}
|
|
|
|
|
|
update = function(data) {
|
|
summary = data;
|
|
}
|
|
|
|
|
|
reset = function() {
|
|
summary = {};
|
|
render();
|
|
}
|
|
|
|
|
|
push = function(labelKey, labelVal) {
|
|
var l = labelKey + ': ' + labelVal;
|
|
if (summary[l] == undefined) {
|
|
summary[l] = 1;
|
|
} else {
|
|
summary[l]++;
|
|
}
|
|
}
|
|
|
|
getCount = function(labelKey, labelVal) {
|
|
var l = labelKey + ': ' + labelVal;
|
|
return summary[l];
|
|
}
|
|
|
|
|
|
return {
|
|
Init: init,
|
|
Update: update,
|
|
Reset: reset,
|
|
Push: push,
|
|
Get: getCount
|
|
}
|
|
|
|
}());
|