Optimise clickable rows

Set a click handler on the table instead of on every row.  This should
be faster on large tables.  Also, it's easier to use: you just set the
clickable-rows class on the table, and the row-link class on the <a>
element that contains the "main" link of the row.
This commit is contained in:
Eelco Dolstra 2013-02-22 18:05:04 +01:00
parent bd7be1cb84
commit 9422c9d2a7
7 changed files with 34 additions and 29 deletions

View file

@ -15,7 +15,7 @@
[% END %]
[% BLOCK renderBuildSteps %]
<table class="tablesorter table table-striped table-condensed">
<table class="tablesorter table table-striped table-condensed clickable-rows">
<thead>
<tr><th>Nr</th><th>What</th><th>Duration</th><th>Machine</th><th>Status</th></tr>
</thead>
@ -24,7 +24,7 @@
[% IF ( type == "All" ) || ( type == "Failed" && step.status != 0 ) || ( type == "Running" && step.busy == 1 ) %]
[% has_log = log_exists(step.drvpath);
log = c.uri_for('/build' build.id 'nixlog' step.stepnr); %]
<tr [% IF has_log %] onclick="window.location = '[% log %]'" [% END %]>
<tr>
<td>[% step.stepnr %]</td>
<td>
[% IF step.type == 0 %]
@ -53,7 +53,7 @@
[% ELSE %]
<span class="error">Failed: [% HTML.escape(step.errormsg) %]</span>
[% END %]
[%%] [%+ IF has_log; INCLUDE renderLogLinks url=log; END %]
[%%] [%+ IF has_log; INCLUDE renderLogLinks url=log inRow=1; END %]
</td>
</tr>
[% END %]

View file

@ -32,7 +32,7 @@ install the package simply by clicking on the packages below.</p>
<p>This channel contains the following packages.</p>
<table class="tablesorter table table-condensed table-striped">
<table class="tablesorter table table-condensed table-striped clickable-rows">
<thead>
<tr>
@ -50,9 +50,9 @@ install the package simply by clicking on the packages below.</p>
[% b = pkg.build %]
[% uri = "${curUri}/pkg/${pkg.name}.nixpkg" %]
<tr onclick="window.location = '[% uri %]'">
<tr>
<td><a href="[% c.uri_for('/build' b.id) %]">[% b.id %]</a></td>
<td><a href="[% uri %]"><tt>[% b.get_column('releasename') || b.nixname %]</tt></a></td>
<td><a class="row-link" href="[% uri %]"><tt>[% b.get_column('releasename') || b.nixname %]</tt></a></td>
<td><tt>[% b.system %]</tt></td>
<td>
[% IF b.homepage %]

View file

@ -24,12 +24,12 @@ END;
BLOCK renderProjectName %]
<a href="[% c.uri_for('/project' project) %]"><tt>[% project %]</tt></a>
<a [% IF inRow %]class="row-link"[% END %] href="[% c.uri_for('/project' project) %]"><tt>[% project %]</tt></a>
[% END;
BLOCK renderJobsetName %]
<a href="[% c.uri_for('/jobset' project jobset) %]"><tt>[% jobset %]</tt></a>
<a [% IF inRow %]class="row-link"[% END %] href="[% c.uri_for('/jobset' project jobset) %]"><tt>[% jobset %]</tt></a>
[% END;
@ -62,7 +62,7 @@ END;
BLOCK renderBuildListHeader %]
<table class="table table-striped table-condensed [% IF !unsortable %]tablesorter[% END %]">
<table class="table table-striped table-condensed clickable-rows [% IF !unsortable %]tablesorter[% END %]">
<thead>
<tr>
[% IF !hideResultInfo %]
@ -95,7 +95,7 @@ BLOCK renderBuildListHeader %]
BLOCK renderBuildListBody;
FOREACH build IN builds; %]
<tr onclick="if(event.which == 2) return true; window.location = '[% c.uri_for('/build' build.id) %]'">
<tr>
[% IF !hideResultInfo %]
<td>
[% INCLUDE renderBuildStatusIcon size=16 busy=(showSchedulingInfo ? 1 : 0) buildstatus=build.buildstatus %]
@ -104,7 +104,7 @@ BLOCK renderBuildListBody;
[% IF showSchedulingInfo %]
<td>[% IF build.busy %]<span class="label label-success">Started</span>[% ELSE %]<span class="label">Queued</span>[% END %]</td>
[% END %]
<td><a href="[% c.uri_for('/build' build.id) %]">[% build.id %]</a></td>
<td><a class="row-link" href="[% c.uri_for('/build' build.id) %]">[% build.id %]</a></td>
[% IF showSchedulingInfo %]
<td>[% build.priority %]</td>
[% END %]
@ -382,7 +382,7 @@ END;
BLOCK renderEvals %]
<table class="tablesorter table table-condensed table-striped">
<table class="tablesorter table table-condensed table-striped clickable-rows">
<thead>
<tr>
[% IF !jobset && !build %]
@ -398,11 +398,11 @@ BLOCK renderEvals %]
[% FOREACH e IN evals;
eval = e.eval;
link = c.uri_for(c.controller('JobsetEval').action_for('view'), [eval.id]) %]
<tr onclick="window.location = '[% link %]'">
<tr>
[% IF !jobset && !build %]
<td>[% INCLUDE renderFullJobsetName project=eval.get_column('project') jobset=eval.get_column('jobset') %]</td>
[% END %]
<td><a href="[% link %]">[% eval.id %]</a></td>
<td><a class="row-link" href="[% link %]">[% eval.id %]</a></td>
<td>[% INCLUDE renderDateTime timestamp = eval.timestamp %]</td>
<td>
[% IF e.changedInputs.size > 0;
@ -440,7 +440,7 @@ BLOCK renderEvals %]
BLOCK renderLogLinks %]
(<a href="[% url %]">log</a>, <a href="[% "$url/raw" %]">raw</a>, <a href="[% "$url/tail-reload" %]">tail</a>)
(<a [% IF inRow %]class="row-link"[% END %] href="[% url %]">log</a>, <a href="[% "$url/raw" %]">raw</a>, <a href="[% "$url/tail-reload" %]">tail</a>)
[% END;

View file

@ -72,6 +72,13 @@
});
});
$("table.clickable-rows").click(function(event) {
if ($(event.target).closest("a").length) return;
link = $(event.target).parents("tr").find("a.row-link");
if (link.length == 1)
window.location = link.attr("href");
});
});
</script>

View file

@ -15,7 +15,7 @@
<p>The following projects are hosted on this server:</p>
<table class="tablesorter table table-condensed table-striped">
<table class="tablesorter table table-condensed table-striped clickable-rows">
<thead>
<tr>
<th>Id</th>
@ -25,8 +25,8 @@
</thead>
<tbody>
[% FOREACH p IN projects %]
<tr onclick="window.location = '[% c.uri_for('/project' p.name) %]'">
<td><span class="[% IF !p.enabled %]disabled-project[% END %] [%+ IF p.hidden %]hidden-project[% END %]">[% INCLUDE renderProjectName project = p.name %]</span></td>
<tr>
<td><span class="[% IF !p.enabled %]disabled-project[% END %] [%+ IF p.hidden %]hidden-project[% END %]">[% INCLUDE renderProjectName project=p.name inRow=1 %]</span></td>
<td>[% HTML.escape(p.displayname) %]</td>
<td>[% WRAPPER maybeLink uri=p.homepage %][% HTML.escape(p.description) %][% END %]</td>
</tr>

View file

@ -14,7 +14,7 @@
[% IF project.jobsets.size > 0 %]
<p>This project has the following jobsets:</p>
<table class="tablesorter table table-striped table-condensed">
<table class="tablesorter table table-striped table-condensed clickable-rows">
<thead>
<tr>
<th></th>
@ -27,7 +27,7 @@
<tbody>
[% FOREACH j IN jobsets %]
[% successrate = 0 %]
<tr onclick="window.location = '[% c.uri_for('/jobset' project.name j.name) %]'">
<tr>
<td>
[% IF j.get_column('nrscheduled') > 0 %]
<img src="/static/images/help_16.png" alt="Scheduled" />
@ -39,7 +39,7 @@
<img src="/static/images/error_16.png" alt="All Failed" />
[% END %]
</td>
<td><span class="[% IF !j.enabled %]disabled-jobset[% END %] [%+ IF j.hidden %]hidden-jobset[% END %]">[% INCLUDE renderJobsetName project = project.name jobset = j.name %]</span></td>
<td><span class="[% IF !j.enabled %]disabled-jobset[% END %] [%+ IF j.hidden %]hidden-jobset[% END %]">[% INCLUDE renderJobsetName project=project.name jobset=j.name inRow=1 %]</span></td>
<td>[% HTML.escape(j.description) %]</td>
<td>[% INCLUDE renderDateTime timestamp = j.lastcheckedtime %]</td>
[% IF j.get_column('nrtotal') > 0 %]
@ -119,7 +119,7 @@
<p>This project has made the following releases:</p>
<table class="tablesorter table table-condensed table-striped">
<table class="tablesorter table table-condensed table-striped clickable-rows">
<thead>
<tr>
<th>Name</th>
@ -128,9 +128,8 @@
</thead>
<tbody>
[% FOREACH release IN releases %]
[% link = c.uri_for('/release' project.name release.name) %]
<tr onclick="window.location = '[% link %]'">
<td><a href="[% link %]"><tt>[% release.name %]</tt></a></td>
<tr>
<td><a class="row-link" href="[% c.uri_for('/release' project.name release.name) %]"><tt>[% release.name %]</tt></a></td>
<td>[% INCLUDE renderDateTime timestamp = release.timestamp %]</td>
</tr>
[% END %]

View file

@ -9,7 +9,7 @@
<p>Showing results [% (page - 1) * resultsPerPage + 1 %] - [% (page - 1) * resultsPerPage + results.size %] out of [% totalResults %].</p>
<table class="tablesorter table table-condensed table-striped">
<table class="tablesorter table table-condensed table-striped clickable-rows">
<thead>
<tr>
<th></th>
@ -24,8 +24,7 @@
<tbody>
[% FOREACH result IN results %]
[% link = c.uri_for('/view' project.name view.name result.id) %]
<tr onclick="window.location = '[% link %]'">
<tr>
<td>
[% IF result.status == 0 %]
<img src="/static/images/checkmark_16.png" />
@ -35,7 +34,7 @@
<img src="/static/images/help_16.png" />
[% END %]
</td>
<td><a href="[% link %]">[% result.id %]</a></td>
<td><a class="row-link" href="[% c.uri_for('/view' project.name view.name result.id) %]">[% result.id %]</a></td>
<td>
[% IF result.releasename %]
<tt>[% result.releasename %]</tt>