Added paging to the /shortlog action.
broquaint [Tue, 27 Oct 2009 22:08:21 +0000 (22:08 +0000)]
gitalist.conf
lib/Gitalist/Controller/Root.pm
templates/_shortlog.tt2

index 81b1fb4..60c71e4 100644 (file)
@@ -41,3 +41,8 @@ favicon /git-favicon.png
 # fs traversing limit for getting project list
 # the number is relative to the projectroot
 project_maxdepth 2007
+
+<paging>
+  log = 50
+  summary = 16
+</paging>
index 8f90b64..ef231b3 100644 (file)
@@ -117,10 +117,11 @@ sub summary : Local {
   $c->stash(
     commit    => $commit,
     info      => $c->model('Git')->project_info($c->model('Git')->project),
-    log_lines => [$c->model('Git')->list_revs(sha1 => $commit->sha1, count => 16)],
+    log_lines => [$c->model('Git')->list_revs(
+      sha1 => $commit->sha1, count => Gitalist->config->{paging}{summary}
+    )],
     refs      => $c->model('Git')->references,
     heads     => [$c->model('Git')->heads],
-    HEAD      => $c->model('Git')->head_hash,
     action    => 'summary',
   );
 }
@@ -137,7 +138,6 @@ sub heads : Local {
   $c->stash(
     commit => $self->_get_commit($c),
     heads  => [$c->model('Git')->heads],
-    HEAD   => $c->model('Git')->head_hash,
     action => 'heads',
   );
 }
@@ -251,16 +251,22 @@ sub shortlog : Local {
   my ( $self, $c ) = @_;
 
   my $commit  = $self->_get_commit($c);
-  my @logargs = (
-      sha1 => $commit->sha1,
+  my %logargs = (
+      sha1   => $commit->sha1,
+      count  => Gitalist->config->{paging}{log},
       ($c->req->param('f') ? (file => $c->req->param('f')) : ())
   );
-  # XXX Needs paging.
+
+  my $page = $c->req->param('pg') || 0;
+  $logargs{skip} = $c->req->param('pg') * $logargs{count}
+    if $c->req->param('pg');
+
   $c->stash(
       commit    => $commit,
-      log_lines => [$c->model('Git')->list_revs(@logargs)],
+      log_lines => [$c->model('Git')->list_revs(%logargs)],
       refs      => $c->model('Git')->references,
       action    => 'shortlog',
+      page      => $page + 1,
   );
 }
 
@@ -321,10 +327,6 @@ Populate the header and footer. Perhaps not the best location.
 sub auto : Private {
     my($self, $c) = @_;
 
-    # XXX Temp hack until a decent solution is invented.
-    $c->model('Git')->project($c->req->param('p'))
-      if $c->req->param('p');
-
     # Yes, this is hideous.
     $self->header($c);
     $self->footer($c);
@@ -512,7 +514,10 @@ Attempt to render a view, if needed.
 
 =cut
 
-sub end : ActionClass('RenderView') {}
+sub end : ActionClass('RenderView') {
+  # Give every view the current HEAD.
+  $_[1]->stash->{HEAD} = $_[1]->model('Git')->head_hash;
+}
 
 =head1 AUTHOR
 
index 7892534..26b6ad7 100644 (file)
@@ -1,3 +1,15 @@
+[% BLOCK pager %]
+<div class='pager'>
+ [% IF log_lines.size == 50 %]
+ <a href='/[% action %]?p=[% project %];h=[% commit.sha1 %];pg=[% page %]'>next</a>
+ [% END %]
+ [% IF log_lines.first.sha1 != HEAD %]
+ <a href='/[% action %]?p=[% project %];h=[% commit.sha1 %];pg=[% page - 1 %]'>prev</a>
+ [% END %]
+</div>
+[% END %]
+
+[% INCLUDE pager %]
 <table>
  <thead>
   <tr>
@@ -44,4 +56,4 @@
   </tr>
  </tfoot>
 </table>
-
+[% INCLUDE pager %]