Files
karma/assets/static/templates.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

68 lines
1.9 KiB
JavaScript

var Templates = (function(params) {
var templates = {},
config = {
// popover with the list of most common labels
breakdown: '#breakdown',
breakdownContent: '#breakdown-content',
// reload message if backend version bump is detected
reloadNeeded: '#reload-needed',
// errors
fatalError: '#fatal-error',
internalError: '#internal-error',
updateError: '#update-error',
// modal popup with label filters
modalTitle: '#modal-title',
modalBody: '#modal-body',
// label button
buttonLabel: '#label-button-filter',
// alert group
alertGroup: '#alert-group',
alertGroupTitle: '#alert-group-title',
alertGroupAnnotations: '#alert-group-annotations',
alertGroupLabels: '#alert-group-labels',
alertGroupElements: '#alert-group-elements',
alertGroupSilence: '#alert-group-silence',
alertGroupLabelMap: '#alert-group-label-map'
}
init = function() {
$.each(config, function(name, selector) {
try {
templates[name] = _.template($(selector).html());
} catch (err) {
console.error('Failed to parse template ' + name + ' ' + selector);
console.error(err);
}
});
}
renderTemplate = function(name, context) {
var t = templates[name];
if (t == undefined) {
console.error('Unknown template ' + name);
return '<div class="jumbotron"><h1>Internal error: unknown template ' + name + '</h1></div>';
}
try {
return t(context);
} catch (err) {
return '<div class="jumbotron">Failed to render template "' + name + '"<h1><p>' + err + '</p></h1></div>'
}
}
return {
Init: init,
Render: renderTemplate
}
})();