gitprep / templates / commits.html.ep /
20e7a22 10 years ago
1 contributor
153 lines | 4.968kb
<%
  # API
  my $api = gitprep_api;

  # Git
  my $git = $self->app->git;

  # Parameters
  my $user = param('user');
  my $project = param('project');
  my $rev_file = param('rev_file');
  
  my $return_atom = $rev_file =~ s/\.atom$// ? 1 : 0;
  
  my ($rev, $file) = $git->parse_rev_path($user, $project, $rev_file);
  my $page = param('page') || 0;
  
  # Commit
  my $commit = $git->get_commit($user, $project, $rev);

  # Not found
  unless ($commit) {
    $self->render_not_found;
    return;
  }
    
  # Commits
  my $page_count = 30;
  my $commits = $git->get_commits(
    $user,
    $project,
    $commit->{id},
    $page_count,
    $page_count * $page,
    $file
  );
  my $commits_count = @$commits;
  my $commits_date = {};
  for my $commit (@$commits) {
    my $date = $commit->{age_string_date_local};
    $commits_date->{$date} ||= [];
    push @{$commits_date->{$date}}, $commit;
  }
  
  # Global variable
  stash(user => $user, project => $project, rev => $rev);
  
  if ($return_atom) {
    my $url = url_with->to_abs;
    
    my $xml = <<"EOS";
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
  <id>tag:gitprep,2008:/$user/$project/commits/$rev_file</id>
  <link type="application/atom+xml" rel="self" href="$url"/>
  <title>Recent Commits to $project:$rev</title>
  <updated>2013-03-29T22:16:25+09:00</updated>
EOS

    $xml .= <<"EOS";
</feed>
EOS
    
    
    $self->res->headers->content_type('application/atom+xml');
    $self->render(text => $xml);
    return;
  }
%>

% layout 'common', title => "Commit History \x{30fb} $user/$project";
  
  %= include '/include/header';

  <div class="container">
    %= include '/include/project_header';
    %= include '/include/code_menu', display => 'commits';
        
    <div style="margin-top:20px;margin-bottom:15px">
      % if (defined $file && length $file) {
        %= include '/include/page_path', type => 'blob', Path => $file, operation => 'commits', prefix => 'History for';
      % } else {
        <div style="font-size:18px">
          <a class="ubar" href="<%= url_for("/$user/$project") %>">
            <%= $project %>
          </a>
          /
          <span class="muted">Commit History</span>
        </div>
      % }
    </div>
    
    % for my $date (reverse sort keys %$commits_date) {
      <div style="margin-bottom:20px">
        % my $commits = $commits_date->{$date};
        
        <div class="bk-blue-light border-blue radius-top" style="padding:5px 8px;color:#3a505b">
          <b><%= $date %></b>
        </div>
        % my $num = 0;
        % for my $commit (sort {$b->{author_epoch} <=> $a->{author_epoch}} @$commits) {
          <div class="border-gray" style="font-size:14px;padding-bottom:0;border-top:none;border-bottom:none;padding:5px 5px 1px 5px">
            <div class="row">
              <div class="span8">
                <a class="font-black" href="<%= url_for("/$user/$project/commit/$commit->{id}") %>">
                  <b><%= $commit->{title_short} %></b>
                </a>
              </div>
              <div class="text-right">
                <a class="btn" style="width:90px;padding:0px 10px;color:#3a505b;font-size:12px" href="<%= url_for("/$user/$project/commit/$commit->{id}") %>">
                  <%= substr($commit->{id}, 0, 10) %>
                  <i class="icon-circle-arrow-right"></i>
                </a>
              </div>
            </div>
          </div>
          <div class="border-blue <%= $num eq @$commits - 1 ? 'radius-bottom' : '' %>" style="font-size:12px;border-top:none; padding:1px 5px 5px 5px">
            <div class="row">
              <div class="span8">
                <span title="<%= $commit->{author_email} %>"><%= $commit->{author_name} %></span> <span class="muted" title="<%= $commit->{age_string_datetime_local} %>"><%= $commit->{age_string} %></span>
              </div>
              <div class="text-right">
                <a class="muted" style="padding-right:18px;font-weight:bold" href="<%= url_for("/$user/$project/commit/$commit->{id}") %>">                  Browse code
                </a>
              </div>
            </div>
          </div>
          % $num++;
        % }
      </div>
    % }

    <ul class="pager" style="text-align:left">
      % if ($page == 0) {
        <li class="disabled">&laquo; Newer</li>
      % } else {
        % my $newer_page = $page - 1;
        <li class="disable">
          <a href="<%= url_for("/$user/$project/commits/$rev?page=$newer_page") %>">&laquo; Newer</a>
        </li>
      % }
      % if ($commits_count < $page_count) {
        <li class="disabled">Older &raquo;</li>
      % } else {
        % my $older_page = $page + 1;
        <li>
          <a href="<%= url_for("/$user/$project/commits/$rev?page=$older_page") %>">Older &raquo;</a>
        </li>
      % }
    </ul>
  </div>
  
  %= include '/include/footer';