gitprep / templates / main / repository.html.ep /
Yuki Kimoto improved design
0bf7685 11 years ago
1 contributor
380 lines | 10.85kb
<%
  use Gitprep::API;
  
  my $ref = 'master';
  
  # Parameters
  my $user = param('user');
  my $repository = param('repository');
  my $id_dir ||= param('id_dir') || 'master/';

  # API
  my $api = Gitprep::API->new($self);
  
  # Parameters
  my $root_ns = $api->root_ns(config->{root});
  
  my $rep_ns = "$root_ns/$user/$repository.git";
  my $rep = "/$rep_ns";
  my $home_ns = $api->dirname($rep_ns);
  my $home = "/$home_ns";

  # Id and directory
  my ($id, $dir) = $api->parse_id_path($rep, $id_dir);

  # Git
  my $git = app->git;
  
  # Tree id
  my $tid;
  my $commit = $git->parse_commit($rep, $id);
  unless (defined $tid) {
    if (defined $dir && $dir ne '') {
      $tid = $git->id_by_path($rep, $id, $dir, 'tree');
    }
    else { $tid = $commit->{tree} }
  }
  $self->render_not_found unless defined $tid;
  
  # Get tree (command "git ls-tree")
  my @entries = ();
  my $show_sizes = 0;
  open my $fh, '-|', $git->cmd($rep), 'ls-tree', '-z',
      ($show_sizes ? '-l' : ()), $tid
    or $api->croak('Open git-ls-tree failed');
  {
    local $/ = "\0";
    @entries = map { chomp; $git->dec($_) } <$fh>;
  }
  close $fh
    or $api->croak(404, "Reading tree failed");
    
  # Commit log
  my $latest_commit_log = $git->latest_commit_log($rep, $ref);
  
  # Parse tree
  my $trees;
  for my $line (@entries) {
    my $tree = $git->parse_ls_tree_line($line, -z => 1, -l => $show_sizes);
    $tree->{mode_str} = $git->_mode_str($tree->{mode});
    
    # Commit log
    my $commit_log = $git->latest_commit_log($rep, $ref, $tree->{name});
    $tree = {%$tree, %$commit_log};
    
    push @$trees, $tree;
  }
  
  # References
  my $refs = $git->references($rep);
  
  # Repository description
  my $desc = $git->repository_description($rep);
  
  # Commits number
  my $commits_number = $git->commits_number($rep, $ref);
%>

% layout 'new_common';
  %= include '/css/common';
  
  %= javascript begin 
    $(document).ready(function() {
      
      // Repository URL
      var rep_url_bak_color = "#F5F5F5";
      var http_rep_url = "<%= url_for("/$user/$repository.git")->to_abs %>";
      var ssh_rep_url
        = "<%= url_for("/$rep_ns")->to_abs->scheme('ssh')->userinfo($user)->port(config->{ssh_port}) %>";
      var git_rep_url = "<%= url_for("/$user/$repository.git")->to_abs->scheme('git')->port('') %>";
      $(".git_url_text").val(http_rep_url);
      $(".git_url_http").css("background-color", "darkgray");
      $(".git_url_http").on('click', function () {
        $(".git_url_http").css("background-color", "darkgray");
        $(".git_url_ssh").css("background-color", rep_url_bak_color);
        $(".git_url_git").css("background-color", rep_url_bak_color);
        
        $(".git_url_text").val(http_rep_url);
        $(".git_url_access").text("Read-only access");
      });
      $(".git_url_ssh").on('click', function () {
        $(".git_url_http").css("background-color", rep_url_bak_color);
        $(".git_url_ssh").css("background-color", "darkgray");
        $(".git_url_git").css("background-color", rep_url_bak_color);
        
        $(".git_url_text").val(ssh_rep_url);
        $(".git_url_access").text("Read-Write access");
      });
      $(".git_url_git").on('click', function () {
        $(".git_url_http").css("background-color", rep_url_bak_color);
        $(".git_url_ssh").css("background-color", rep_url_bak_color);
        $(".git_url_git").css("background-color", "darkgray");
        
        $(".git_url_text").val(git_rep_url);
        $(".git_url_access").text("Read-Only access");
      });
      
    });
  % end
  
  %= stylesheet begin
    
    /* User and repository name */
    .user_rep {
      font-size:140%;
      font-weight:bold;
      margin-top:15px;
      margin-bottom:15px;
    }
    
    /* Repository description */
    .description {
      padding:10px;
      border:1px solid gray;
      margin-top:-1px;
    }
    
    /* Git URL */
    .git_url {
      border: 1px solid gray;
      padding: 10px;
      margin-top:-1px;
      font-size:80%;
    }
    .git_url_zip {
      padding:5px;
      float:left;
      border:1px solid gray;
      margin-right:5px;
      background-color:#F5F5F5;
    }
    .git_url_http {
      padding:5px;
      float:left;
      border:1px solid gray;
      background-color:#F5F5F5;
    }
    .git_url_ssh {
      padding:5px;
      float:left;
      border:1px solid gray;
      border-left:none;
      background-color:#F5F5F5;
    }
    .git_url_git {
      padding:5px;
      float:left;
      border:1px solid gray;
      border-left:none;
      background-color:#F5F5F5;
    }
    .git_url_text {
      padding:3px;
      float:left;
      border:1px solid gray;
      width:300px;
      margin-right:10px;
      border-left:none;
      display:block;
    }
    .git_url_access {
      padding:5px;
    }
      
    /* Code menu */
    .code_menu {
      margin-top:7px;
      margin-bottom:15px;
      height:30px;
      overflow:hidden;
    }
    .code_menu_left {
      width:700px;
      float:left;
      overflow:hidden;
    }
    .code_menu_current_ref {
      float:left;
      padding:5px 10px 10px 10px;
    }
    .code_menu_current_ref_button {
      padding:1px;
      border:1px solid black;
    }
    .code_menu_left li {
      float:left;
      padding:5px 10px;
    }
    .code_menu_files {
      border:1px solid black;
      border-bottom:none;
      background-color:white;
      font-weight:bold;
    }
    .code_menu_right {
      text-align:right;
      overflow:hidden;
    }
    .code_menu_right li {
      float:right;
      padding:5px 10px;
    }
    .code_menu_under {
      border-top:1px solid black;
    }

    /* Commit number */
    .commit_number {
      font-size:120%;
    }
    .commit_number_left {
      width:700px;
      float:left;
    }
    .commit_number_right {
      text-align:right;
    }
    
    /* README */
    .readme {
      width:100%;
      margin: 5px auto;
      border:2px solid gray;
    }
    .readme_title {
      border-bottom:1px solid gray;
      font-size:130%;
      font-weight:bold;
      padding:10px;
    }
    .readme_body {
      min-height: 50px;
      font-size:120%;
      padding:10px;
    }
  % end

  %= include '/include/new_header';

  <div class="main_panel">
    <div class="user_rep">
      <a href="<%= url_for("/$user") %>"><%= $user %></a>
      /
      <a href="<%= url_for %>"><%= $repository %></a>
    </div>
    
    <ul class="main_menu">
      <li><a href="<%= url_for %>">Code</a></li>
      <li><a href="<%= url_for("/$user/$repository/network") %>"><s>Network</s></a></li>
      <li><a href="<%= url_for("/$user/$repository/pulls") %>"><s>Pull Requests 0</s></a></li>
      <li><a href="<%= url_for("/$user/$repository/issues") %>"><s>Issues 1</s></a></li>
      <li><a href="<%= url_for("/$user/$repository/wiki") %>"><s>Wiki</s></a></li>
      <li><a href="<%= url_for("/$user/$repository/graphs") %>"><s>Graphs</s></a></li>
      <li><a href="<%= url_for("/$user/$repository/admin") %>"><s>Admin</s></a></li>
    </ul>

    <div class="description"><%= $desc %></div>
    
    <div class="git_url">
      <div class="git_url_zip"><a href="<%= url_for('/archive/master.zip') %>"><s>ZIP</s></a></div>
      <div class="git_url_http">HTTP</div>
      <div class="git_url_ssh">SSH</div>
      <div class="git_url_git">Git Read-Only</div>
      <input type="text" class="git_url_text">
      <div class="git_url_access">Read-only access</div>
    </div>
    
    <div class="code_menu">
      <ul class="code_menu_left">
        <li class="code_menu_current_ref">
          <div class="code_menu_current_ref_button">
            branch <b>master</b>
          </div>
        </li>
        <li class="code_menu_files"><a href="<%= url_for %>">Files</a></li>
        <li class="code_menu_commits"><a href="<%= url_for("/$user/$repository/commits/master") %>">Commits</a></li>
        <li class="code_menu_branches"><a href="<%= url_for("/$user/$repository/branches") %>">Branches</a></li>
      </ul>
      <ul class="code_menu_right">
        <li class="code_menu_downloads"><a href="<%= url_for("/$user/$repository/downloads") %>"><s>Downloads</s></a></li>
        <li class="code_menu_tags"><a href="<%= url_for("/$user/$repository/tags") %>">Tags</a></li>
      </ul>
      <div class="code_menu_under"></div>
    </div>
    
    
    <div class="commit_number">
      <div class="commit_number_left">
        <a href="<%= url_for %>"><%= $repository %></a>
      </div>
      <div class="commit_number_right">
        <a href="<%= url_for("/$user/$repository/commits/master") %>">
          <%= $commits_number %> commits
        </a>
      </div>
    </div>
    
    <div class="tree">
      <div class="tree_header">
        <a href="<%= url_for('commit', project => $rep_ns, id => $id) %>">
          <%= $commit->{title} %>
        </a>
      </div>
      <div class="tree_header2">
        <div class="tree_header2_left">
          <b><%= $latest_commit_log->{author} %></b> <span class="tree_header2_left_right">authored <%= $latest_commit_log->{author_date} %></span>
        </div>
        <div class="tree_header2_right">
          <a href="<%= url_for("/$user/$repository/commit/$commit->{id}") %>">
            latest commit <%= substr($commit->{id}, 0, 10) %>
          </a>
        </div>
      </div>
      <table class="tree_body" cellpadding="0" cellspacing="0">
        % for (my $i = 0; $i <@$trees; $i++) {
          
          % my $tree = $trees->[$i];
          % my $type = $tree->{type};
          % my $name = $tree->{name};
          
          % my $child_dir = defined $dir && length $dir ? join('/', $dir, $name) : $name;
          <tr>
            % my $file = defined $dir ? "$dir/$name" : $name;
            % $file =~ s/^\///;
            
            <td class="tree_td_file">
              % if ($type eq 'blob') {
                <a href="<%= url_for("/$user/$repository/blob/$ref/$name") %>">
                  <%= $name %>
                </a>
              % } elsif ($tree) {
                <a href="<%= url_for("/$user/$repository/tree/$ref/$child_dir") %>">
                  <%= $name %>
                </a>
              % }
            </td>
            <td>
              <%= $tree->{author_date} %>
            </td>
            <td class="tree_td_commit">
              <a href="<%= url_for("/$user/$repository/commit/$tree->{commit}") %>">
                <%= $tree->{comment} %>
              </a>
              [<%= $tree->{author} %>]
            </td>
          </tr>
        % }
      </table>
    </div>
    
    <div class="readme">
      <div class="readme_title">README</div>
      <div class="readme_body">
        README body
      </div>
    </div>
  </div>
  
  <div class="footer">
    <a href="https://github.com/yuki-kimoto/gitprep">Gitprep</a>
  </div>