Get the index page working with the content in a fragment and all the URIs moved
Tomas Doran [Sun, 17 Jan 2010 21:02:08 +0000 (21:02 +0000)]
lib/Gitalist/Controller/Fragment.pm
lib/Gitalist/Controller/Fragment/Repository.pm
lib/Gitalist/Controller/Repository.pm
lib/Gitalist/Controller/Root.pm
root/fragment/collectionofrepositories.tt2 [new file with mode: 0644]
root/index.tt2

index 869c5b7..15c4511 100644 (file)
@@ -5,6 +5,28 @@ use namespace::autoclean;
 
 BEGIN { extends 'Catalyst::Controller' }
 
-sub base : Chained('/root') PathPart('fragment') CaptureArgs(0) {}
+sub base : Chained('/root') PathPart('fragment') CaptureArgs(0) {
+    my ($self, $c) = @_;
+    $c->stash(no_wrapper => 1);
+}
+
+sub collectionofrepositories : Chained('base') Args(0) {
+    my ($self, $c) = @_;
+    my @list = @{ $c->model()->repositories };
+    die 'No repositories found in '. $c->model->repo_dir
+      unless @list;
+
+    my $search = $c->req->param('s') || '';
+    if($search) {
+      @list = grep {
+           index($_->name, $search) > -1
+        or ( $_->description !~ /^Unnamed repository/ and index($_->description, $search) > -1 )
+      } @list
+    }
+
+    $c->stash(
+      repositories    => \@list,
+    );
+}
 
 __PACKAGE__->meta->make_immutable;
index cee32d9..db1557e 100644 (file)
@@ -5,10 +5,7 @@ use namespace::autoclean;
 BEGIN { extends 'Catalyst::Controller' }
 with 'Gitalist::URIStructure::Repository';
 
-sub base : Chained('/fragment/base') PathPart('') CaptureArgs(0) {
-    my ($self, $c) = @_;
-    $c->stash(no_wrapper => 1);
-}
+sub base : Chained('/fragment/base') PathPart('') CaptureArgs(0) {}
 
 after shortlog => sub {
     my ($self, $c) = @_;
index b79e51b..96fe14f 100644 (file)
@@ -5,6 +5,6 @@ use namespace::autoclean;
 BEGIN { extends 'Catalyst::Controller' }
 with 'Gitalist::URIStructure::Repository';
 
-sub base : Chained('/root') PathPart('') CaptureArgs(0) {}
+sub base : Chained('/base') PathPart('') CaptureArgs(0) {}
 
 __PACKAGE__->meta->make_immutable;
index c8479cd..7c55b31 100644 (file)
@@ -46,22 +46,10 @@ sub index : Chained('base') PathPart('') Args(0) {
   $c->detach($c->req->param('a'))
     if $c->req->param('a');
 
-  my @list = @{ $c->model()->repositories };
-  die 'No repositories found in '. $c->model->repo_dir
-    unless @list;
-
   my $search = $c->req->param('s') || '';
-  if($search) {
-    @list = grep {
-         index($_->name, $search) > -1
-      or ( $_->description !~ /^Unnamed repository/ and index($_->description, $search) > -1 )
-    } @list
-  }
 
   $c->stash(
     search_text => $search,
-    repositories    => \@list,
-    action      => 'index',
   );
 }
 
@@ -86,7 +74,6 @@ sub summary : Chained('base') Args(0) {
     )],
     refs      => $repository->references,
     heads     => [ @heads[0 .. ($#heads < $maxitems ? $#heads : $maxitems)] ],
-    action    => 'summary',
   );
 }
 
@@ -102,7 +89,6 @@ sub heads : Chained('base') Args(0) {
   $c->stash(
     commit => $self->_get_object($c),
     heads  => $repository->heads,
-    action => 'heads',
   );
 }
 
@@ -118,7 +104,6 @@ sub tags : Chained('base') Args(0) {
   $c->stash(
     commit => $self->_get_object($c),
     tags   => $repository->tags,
-    action => 'tags',
   );
 }
 
@@ -185,7 +170,6 @@ sub blob : Chained('base') Args(0) {
     filename => $filename,
     # XXX Hack hack hack, see View::SyntaxHighlight
     language => ($filename =~ /\.p[lm]$/i ? 'Perl' : ''),
-    action   => 'blob',
   );
 
   $c->forward('View::SyntaxHighlight')
@@ -246,7 +230,6 @@ sub blobdiff : Chained('base') Args(0) {
     # XXX Hack hack hack, see View::SyntaxHighlight
     blobs     => [$patch->[0]->{diff}],
     language  => 'Diff',
-    action    => 'blobdiff',
   );
 
   $c->forward('View::SyntaxHighlight')
@@ -267,7 +250,6 @@ sub commit : Chained('base') Args(0) {
       commit      => $commit,
       diff_tree   => ($repository->diff(commit => $commit))[0],
       refs      => $repository->references,
-      action      => 'commit',
   );
 }
 
@@ -292,7 +274,6 @@ sub commitdiff : Chained('base') Args(0) {
     # XXX Hack hack hack, see View::SyntaxHighlight
     blobs     => [map $_->{diff}, @$patch],
     language  => 'Diff',
-    action    => 'commitdiff',
   );
 
   $c->forward('View::SyntaxHighlight')
@@ -337,7 +318,6 @@ sub shortlog : Chained('base') Args(0) {
       refs      => $repository->references,
       page      => $page,
       filename  => $filename,
-      action    => 'shortlog',
   );
 }
 
@@ -349,7 +329,6 @@ Calls shortlog internally. Perhaps that should be reversed ...
 
 sub log : Chained('base') Args(0) {
     $_[0]->shortlog($_[1]);
-    $_[1]->stash->{action} = 'log';
 }
 
 # For legacy support.
@@ -363,7 +342,7 @@ sub history : Chained('base') Args(0) {
             $c->stash->{filename}
         )
     );
-     $c->stash( action => 'history',
+     $c->stash(
                filetype => $file->type,
            );
 }
@@ -388,7 +367,6 @@ sub tree : Chained('base') Args(0) {
       tree      => $tree,
       tree_list => [$repository->list_tree($tree->sha1)],
       path      => $c->req->param('f') || '',
-      action    => 'tree',
   );
 }
 
@@ -406,7 +384,6 @@ sub reflog : Chained('base') Args(0) {
 
   $c->stash(
       log    => \@log,
-      action => 'reflog',
   );
 }
 
@@ -435,7 +412,6 @@ sub search : Chained('base') Args(0) {
   $c->stash(
       commit  => $commit,
       results => [$repository->list_revs(%logargs)],
-      action  => 'search',
          # This could be added - page      => $page,
   );
 }
@@ -605,19 +581,10 @@ sub snapshot : Chained('base') Args(0) {
 sub base : Chained('/root') PathPart('') CaptureArgs(0) {
   my($self, $c) = @_;
 
-  my $repository = $c->req->param('p');
-  if (defined $repository) {
-    eval {
-      $c->stash(Repository => $c->model()->get_repository($repository));
-    };
-    if ($@) {
-      $c->detach('/error_404');
-    }
-  }
-
-  my $a_repository = $c->stash->{Repository} || $c->model()->repositories->[0];
+  my $git_version = `git --version`;
+  chomp($git_version);
   $c->stash(
-    git_version => $a_repository->run_cmd('--version'),
+    git_version => $git_version,
     version     => $Gitalist::VERSION,
 
     # XXX Move these to a plugin!
diff --git a/root/fragment/collectionofrepositories.tt2 b/root/fragment/collectionofrepositories.tt2
new file mode 100644 (file)
index 0000000..4dae472
--- /dev/null
@@ -0,0 +1,15 @@
+<tbody class='listing'>
+  [% FOR p IN repositories %]
+  [%- repos_link = c.uri_for_action('/repository/summary', [p.name]) -%]
+<tr>
+    <td><a class="list" href="[% repos_link %]">[% p.name %]</a></td>
+    <td><a class="list" title="[% p.description %]" href="[% repos_link %]">[% abridged_description(p.description)  %]</a></td>
+    <td>[% p.owner %]</td>
+    <td class="time-since">[% time_since(p.last_change) %]</td>
+    <td class="link"><a href="[% repos_link %]">summary</a>
+       | <a href="[% c.uri_for_action('/repository/shortlog', [p.name]) %]">shortlog</a>
+       | <a href="[% c.uri_for_action('/repository/log', [p.name]) %]">log</a>
+       | <a href="[% c.uri_for_action('/commit/tree', [p.name, 'HEAD']) %]">tree</a></td>
+</tr>
+  [% END %]
+</tbody>
index 9d1544d..5ab87e7 100644 (file)
@@ -1,3 +1,13 @@
+[% BLOCK repos_table_headfoot %]
+<tr>
+    <th>Repository</th>
+    <!-- XXX These do nothing presently -->
+    <th><a class="header" href="/?o=descr">Description</a></th>
+    <th><a class="header" href="/?o=owner">Owner</a></th>
+    <th><a class="header" href="/?o=age">Last Change</a></th>
+    <th></th>
+</tr>
+[% END %]
 <div class='content'>
   <form method="get" action="/" enctype="application/x-www-form-urlencoded">
    <p class="projsearch">Search:
 
   <table class="repository_list">
     <thead>
-       <tr>
-           <th>Repository</th>
-           <!-- XXX These do nothing presently -->
-           <th><a class="header" href="/?o=descr">Description</a></th>
-           <th><a class="header" href="/?o=owner">Owner</a></th>
-           <th><a class="header" href="/?o=age">Last Change</a></th>
-           <th></th>
-       </tr>
+               [% INCLUDE repos_table_headfoot %]
     </thead>
     <tfoot>
-       <tr>
-           <td>Repository</td>
-           <!-- XXX These do nothing presently -->
-           <td><a href="/?o=descr">Description</a></td>
-           <td><a href="/?o=owner">Owner</a></td>
-           <td><a href="/?o=age">Last Change</a></td>
-           <td></td>
-       </tr>
+               [% INCLUDE repos_table_headfoot %]
     </tfoot>
 
-    <tbody class='listing'>
-      [% FOR p IN repositories %]
-       <tr>
-           <td><a class="list" href="[% c.uri_for('/summary', {p=p.name}) %]">[% p.name %]</a></td>
-           <td><a class="list" title="[% p.description %]" href="[% c.uri_for('/summary', {p=p.name} ) %]">[% abridged_description(p.description)  %]</a></td>
-           <td>[% p.owner %]</td>
-           <td class="time-since">[% time_since(p.last_change) %]</td>
-           <td class="link"><a href="[% c.uri_for("summary", {p=p.name}) %]">summary</a>
-               | <a href="[% c.uri_for("shortlog", {p=p.name}) %]">shortlog</a>
-               | <a href="[% c.uri_for("log", {p=p.name}) %]">log</a>
-               | <a href="[% c.uri_for("tree", {p=p.name}) %]">tree</a></td>
-       </tr>
-      [% END %]
-    </tbody>
+       [% subinclude('/fragment/collectionofrepositories') %]
   </table>
 </div>