* paging for releases page

This commit is contained in:
Rob Vermaas 2009-10-15 11:13:36 +00:00
parent 903ca3b246
commit d109910453
3 changed files with 91 additions and 21 deletions

View file

@ -137,7 +137,13 @@ sub releases :Local {
my ($project, $releaseSet, $primaryJob, $jobs) = getReleaseSet($c, $projectName, $releaseSetName); my ($project, $releaseSet, $primaryJob, $jobs) = getReleaseSet($c, $projectName, $releaseSetName);
if (defined $subcommand && $subcommand ne "") { my $resultsPerPage = 10;
my $page = 1;
if (defined $subcommand && $subcommand =~ /^\d+$/ ) {
$page = int($subcommand)
}
elsif (defined $subcommand && $subcommand ne "") {
requireProjectOwner($c, $project); requireProjectOwner($c, $project);
@ -166,8 +172,13 @@ sub releases :Local {
$c->stash->{template} = 'releases.tt'; $c->stash->{template} = 'releases.tt';
my @releases = (); my @releases = ();
push @releases, getRelease($_, $jobs) foreach getPrimaryBuildsForReleaseSet($project, $primaryJob); push @releases, getRelease($_, $jobs) foreach getPrimaryBuildsForReleaseSet($project, $primaryJob, $page, $resultsPerPage);
$c->stash->{baseUri} = $c->uri_for($self->action_for("releases"), $projectName, $releaseSetName);
$c->stash->{releases} = [@releases]; $c->stash->{releases} = [@releases];
$c->stash->{page} = $page;
$c->stash->{totalReleases} = getPrimaryBuildTotal($project, $primaryJob);
$c->stash->{resultsPerPage} = $resultsPerPage;
} }

View file

@ -10,7 +10,9 @@ our @EXPORT = qw(
isValidPath queryPathInfo isValidPath queryPathInfo
getHydraPath getHydraDBPath openHydraDB txn_do getHydraPath getHydraDBPath openHydraDB txn_do
registerRoot getGCRootsDir gcRootFor registerRoot getGCRootsDir gcRootFor
getPrimaryBuildsForReleaseSet getRelease getLatestSuccessfulRelease ); getPrimaryBuildsForReleaseSet
getPrimaryBuildTotal
getRelease getLatestSuccessfulRelease );
sub isValidPath { sub isValidPath {
@ -146,19 +148,76 @@ sub attrsToSQL {
return $query; return $query;
} }
sub allPrimaryBuilds {
my ($project, $primaryJob) = @_;
my $allPrimaryBuilds = $project->builds->search(
{ jobset => $primaryJob->get_column('jobset'), job => $primaryJob->get_column('job'), finished => 1 },
{ join => 'resultInfo', order_by => "timestamp DESC"
, '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"]
, '+as' => ["releasename", "buildstatus"]
, where => \ attrsToSQL($primaryJob->attrs, "me.id")
});
return $allPrimaryBuilds;
}
sub getPrimaryBuildTotal {
my ($project, $primaryJob) = @_;
return scalar(allPrimaryBuilds($project, $primaryJob)) ;
}
sub getPrimaryBuildsForReleaseSet { sub getPrimaryBuildsForReleaseSet {
my ($project, $primaryJob) = @_; my ($project, $primaryJob, $page, $resultsPerPage) = @_;
my @primaryBuilds = $project->builds->search( $page = (defined $page ? int($page) : 1) || 1;
{ jobset => $primaryJob->get_column('jobset'), job => $primaryJob->get_column('job'), finished => 1 }, $resultsPerPage = (defined $resultsPerPage ? int($resultsPerPage) : 20) || 20;
{ join => 'resultInfo', order_by => "timestamp DESC"
, '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"] my @primaryBuilds = allPrimaryBuilds($project, $primaryJob)->search( {},
, '+as' => ["releasename", "buildstatus"] { rows => $resultsPerPage
, where => \ attrsToSQL($primaryJob->attrs, "me.id") , page => $page
}); });
return @primaryBuilds; return @primaryBuilds;
} }
sub findLastJobForBuilds {
my ($builds, $job) = @_;
my $thisBuild;
# Find a build of this job that had the primary build
# as input. If there are multiple, prefer successful
# ones, and then oldest. !!! order_by buildstatus is hacky
($thisBuild) = $builds->search(
{ project => $job->get_column('project'), jobset => $job->get_column('jobset')
, job => $job->get_column('job'), finished => 1
}
, { join => 'resultInfo', rows => 1
, order_by => ["buildstatus", "timestamp"]
, where => \ attrsToSQL($job->attrs, "build.id")
, '+select' => ["resultInfo.buildstatus"], '+as' => ["buildstatus"]
});
return $thisBuild ;
}
sub findLastJobForPrimaryBuild {
my ($primaryBuild, $job) = @_;
my $thisBuild;
my $depBuilds;
$depBuilds = $primaryBuild->dependentBuilds;
$thisBuild = findLastJobForBuilds($depBuilds, $job) ;
# don't do recursive yet
# if (!defined $thisBuild) {
#
# foreach my $build ($depBuilds->all) {
# $thisBuild = findLastJobForPrimaryBuild($build, $job) ;
# if (defined $thisBuild) {
# last ;
# }
# }
# }
return $thisBuild;
}
sub getRelease { sub getRelease {
my ($primaryBuild, $jobs) = @_; my ($primaryBuild, $jobs) = @_;
@ -177,17 +236,7 @@ sub getRelease {
if ($job->isprimary) { if ($job->isprimary) {
$thisBuild = $primaryBuild; $thisBuild = $primaryBuild;
} else { } else {
# Find a build of this job that had the primary build $thisBuild = findLastJobForPrimaryBuild($primaryBuild, $job) ;
# as input. If there are multiple, prefer successful
# ones, and then oldest. !!! order_by buildstatus is hacky
($thisBuild) = $primaryBuild->dependentBuilds->search(
{ project => $job->get_column('project'), jobset => $job->get_column('jobset')
, job => $job->get_column('job'), finished => 1 },
{ join => 'resultInfo', rows => 1
, order_by => ["buildstatus", "timestamp"]
, where => \ attrsToSQL($job->attrs, "build.id")
, '+select' => ["resultInfo.buildstatus"], '+as' => ["buildstatus"]
});
} }
if ($job->mayfail != 1) { if ($job->mayfail != 1) {

View file

@ -9,6 +9,8 @@
[<a href="[% c.uri_for('/release' project.name releaseSet.name "latest") %]">Latest</a>] [<a href="[% c.uri_for('/release' project.name releaseSet.name "latest") %]">Latest</a>]
</p> </p>
<p>Showing releases [% (page - 1) * resultsPerPage + 1 %] - [% (page - 1) * resultsPerPage + releases.size %] out of [% totalReleases %].</p>
<table class="tablesorter"> <table class="tablesorter">
<thead> <thead>
<tr> <tr>
@ -62,4 +64,12 @@
</tbody> </tbody>
</table> </table>
[% IF page > 1 %]
[<a href="[% "$baseUri/"; (page - 1) %]">Prev</a>]
[% END %]
[% IF page * resultsPerPage < totalReleases %]
[<a href="[% "$baseUri/"; (page + 1) %]">Next</a>]
[% END %]
[<a href="[% "$baseUri/"; (totalReleases - 1) div resultsPerPage + 1 %]">Last</a>]
[% END %] [% END %]