Proof of concept for #56388: add last commit msg to tre views.
Dan Brook [Fri, 23 Apr 2010 22:41:20 +0000 (23:41 +0100)]
lib/Gitalist/Controller/Fragment/Ref.pm
lib/Gitalist/URIStructure/Ref.pm
root/fragment/ref/tree.tt2

index 9793dd7..a6690e6 100644 (file)
@@ -9,6 +9,7 @@ with qw/
 /;
 
 use File::Type::WebImages ();
+use JSON::XS qw(encode_json);
 
 sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
 
@@ -116,4 +117,24 @@ after history => sub {
     );
 };
 
+after file_commit_info => sub {
+    my ($self, $c) = @_;
+
+    my $repository  = $c->stash->{Repository};
+
+    my($commit) = $repository->list_revs(
+       sha1   => $c->stash->{Commit}->sha1,
+       count  => 1,
+       file   => $c->stash->{filename},
+    );
+
+    my $json_obj = $commit
+                 ? { sha1 => $commit->sha1, comment => $c->stash->{short_cmt}->($commit->comment) }
+                 : { };
+
+    $c->response->content_type('application/json');
+    # XXX Make use of the json branch
+    $c->response->body( encode_json $json_obj );
+};
+
 __PACKAGE__->meta->make_immutable;
index 20337fe..da71487 100644 (file)
@@ -55,6 +55,8 @@ sub diff_plain : Chained('diff') PathPart('plain') Args() {
 
 sub commit : Chained('find') PathPart('commit') Args(0) {}
 
+sub file_commit_info : Chained('find') Does('FilenameArgs') Args() {}
+
 sub tree : Chained('find') Does('FilenameArgs') Args() {}
 
 sub find_blob : Action {
index b043808..38ecf21 100755 (executable)
@@ -1,14 +1,28 @@
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+<script>
+// Wait for image requests to come back first - $(function() {
+$(window).load(function() {
+  $('#commit-tree .message').each(function() {
+    var cell     = $(this);
+    var filename = cell.parent().find('.file-name').text();
+    $.getJSON('/fragment/Gitalist/[% Commit.sha1 %]/file_commit_info/'+filename, {}, function(commitInfo) {
+      cell.empty();
+      cell.html('<a href="/Gitalist/"'+commitInfo.sha1+'">'+commitInfo.comment+'</a>');
+    });
+  });
+});
+</script>
+
 [% BLOCK tree_table_headfoot %]
 [% SET cell = type == 'head' ? 'th' : 'td' %]
   <tr>
    <[% cell %]>Mode</[% cell %]>
    <[% cell %]>Folder / File</[% cell %]>
    <[% cell %]>Actions</[% cell %]>
+   <[% cell %]>Message</[% cell %]>
   </tr>
 [% END %]
 
-
-
 [%-
        SET counter         = 1;
        
@@ -43,6 +57,7 @@
          [% END %]
            <a href="[% c.uri_for_action('/ref/history', c.req.captures, c.req.args.to_path(item.file)) %]" title="History (Short log)" class="button shortlog">Short log</a>
                </td>
+          <td class="message">Loading commit info ...</td>
        </tr>
                [% counter = counter + 1 %]
        [% END %]
@@ -51,7 +66,7 @@
 
 
 
-<table class="listing">
+<table class="listing" id="commit-tree">
 <thead>[% PROCESS tree_table_headfoot type = 'head' %]</thead>
 <tbody>
        [% INCLUDE output_tree tree_type => tree_folders %]