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 %] [% END %]
[% BLOCK renderBuildSteps %] [% BLOCK renderBuildSteps %]
<table class="tablesorter table table-striped table-condensed"> <table class="tablesorter table table-striped table-condensed clickable-rows">
<thead> <thead>
<tr><th>Nr</th><th>What</th><th>Duration</th><th>Machine</th><th>Status</th></tr> <tr><th>Nr</th><th>What</th><th>Duration</th><th>Machine</th><th>Status</th></tr>
</thead> </thead>
@ -24,7 +24,7 @@
[% IF ( type == "All" ) || ( type == "Failed" && step.status != 0 ) || ( type == "Running" && step.busy == 1 ) %] [% IF ( type == "All" ) || ( type == "Failed" && step.status != 0 ) || ( type == "Running" && step.busy == 1 ) %]
[% has_log = log_exists(step.drvpath); [% has_log = log_exists(step.drvpath);
log = c.uri_for('/build' build.id 'nixlog' step.stepnr); %] 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>[% step.stepnr %]</td>
<td> <td>
[% IF step.type == 0 %] [% IF step.type == 0 %]
@ -53,7 +53,7 @@
[% ELSE %] [% ELSE %]
<span class="error">Failed: [% HTML.escape(step.errormsg) %]</span> <span class="error">Failed: [% HTML.escape(step.errormsg) %]</span>
[% END %] [% END %]
[%%] [%+ IF has_log; INCLUDE renderLogLinks url=log; END %] [%%] [%+ IF has_log; INCLUDE renderLogLinks url=log inRow=1; END %]
</td> </td>
</tr> </tr>
[% END %] [% 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> <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> <thead>
<tr> <tr>
@ -50,9 +50,9 @@ install the package simply by clicking on the packages below.</p>
[% b = pkg.build %] [% b = pkg.build %]
[% uri = "${curUri}/pkg/${pkg.name}.nixpkg" %] [% 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="[% 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><tt>[% b.system %]</tt></td>
<td> <td>
[% IF b.homepage %] [% IF b.homepage %]

View file

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

View file

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

View file

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

View file

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