gitprep / templates / main / repository.html.ep /
Yuki Kimoto improved design
cd11b68 11 years ago
1 contributor
383 lines | 10.877kb
<%
  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;
      border-bottom:1px solid black;
    }
    .code_menu_left {
      width:700px;
      float:left;
    }
    .code_menu_current_ref {
      float:left;
      padding:5px 10px 5px 10px;
    }
    .code_menu_current_ref_button {
      border:1px solid black;
      /* padding:3px; */
    }
    .code_menu_files {
      float:left;
      padding:5px 10px;
      border:1px solid black;
      border-bottom:none;
      z-index:5;
      background-color:#F5F5F5;
    }
    .code_menu_commits {
      float:left;
      padding:5px 10px;
    }
    .code_menu_branches {
      padding:5px;
      float:left;
    }
    .code_menu_right {
      text-align:right;
    }
    .code_menu_tags {
      float:right;
      padding:5px 10px;
    }
    .code_menu_downloads {
      float:right;
      padding:5px 10px;
    }

    /* 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">
      <div class="code_menu_left">
        <div class="code_menu_current_ref">
          <div class="code_menu_current_ref_button">
            branch <b>master</b>
          </div>
        </div>
        <a href="<%= url_for %>"><div class="code_menu_files">Files</div></a>
        <a href="<%= url_for("/$user/$repository/commits/master") %>"><div class="code_menu_commits">Commits</div></a>
        <a href="<%= url_for("/$user/$repository/branches") %>"><div class="code_menu_branches">Branches</div></a>
      </div>
      <div class="code_menu_right">
        <a href="<%= url_for("/$user/$repository/downloads") %>"><div class="code_menu_downloads"><s>Downloads</s></div></a>
        <a href="<%= url_for("/$user/$repository/tags") %>"><div class="code_menu_tags">Tags</div></a>
      </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/$rep/commit/$commit->{id}") %>">
            latest commit <%= substr($commit->{id}, 0, 10) %>
          </a>
        </div>
      </div>
      <table class="tree_body">
        % 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="list">
              % if ($type eq 'blob') {
                <a class="list" href="<%= url_for('blob', project => $rep_ns, id_file => "$id/$file") %>">
                  <%= $name %>
                </a>
              % } elsif ($tree) {
                <a href="<%= url_for('tree', project => $rep_ns, id_dir => "$id/$child_dir") %>">
                  <%= $name %>
                </a>
              % }
            </td>
            <td>
              <%= $tree->{author_date} %>
            </td>
            <td>
              <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>