Skip to content

Instantly share code, notes, and snippets.

@vglebov
Last active May 8, 2017 11:16
Show Gist options
  • Save vglebov/c212e75f921b1c077f481172b8920b87 to your computer and use it in GitHub Desktop.
Save vglebov/c212e75f921b1c077f481172b8920b87 to your computer and use it in GitHub Desktop.
Trac total for custom fields time_planned time_spent
...
<py:match path="div[@class=&quot;query&quot;]">
<div py:attrs="select('@*')">${select('*|comment()|text()')}</div>
<script language="JavaScript">
//<![CDATA[
var columns = [];
function getTotal(row_class, self) {
var total = 0;
if ($(self).find('th'+row_class).length) {
columns[row_class] = $(self).find('th'+row_class).first();
}
$(self).find(row_class).each(function() {
var time = $(this).text().trim().replace(new RegExp('[,]', 'g'),'.');
if (time) { total += parseFloat(time); }
});
if (!isNaN(total) && total > 0 ) {
$(columns[row_class]).html($(columns[row_class]).html() + ' (' + total + ')');
}
}
$('.listing.tickets thead,tbody').each(function() {
getTotal('.time_planned', this);
getTotal('.time_spent', this);
});
// ]]>
</script>
</py:match>
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment