gitprep / templates / project.html.ep /
e7b9307 10 years ago
3 contributor
203 lines | 6.097kb
<%
  use Text::Markdown::Hoedown;

  my $state;

  # API
  my $api = gitprep_api;

  # Git
  my $git = app->git;
  
  # Parameters
  my $user = param('user');
  my $project = param('project');
  my $rev = app->manager->default_branch($user, $project);
  
  unless (app->manager->exists_project($user, $project)) {
    $self->render_not_found;
    return;
  }

  # Repository description
  my $desc = $git->description($user, $project);
  
  # Check exsitence
  my $commits_number;
  if ($git->exists_branch($user, $project)) {
    # Commit
    my $commit = $git->get_commit($user, $project, $rev);
    
    # Tree
    my $trees = $git->trees($user, $project, $rev);
    
    # Commits number
    $commits_number = $git->commits_number($user, $project, $rev);
    
    # Variable for included template
    stash(
      commit => $commit,
      trees => $trees,
      rev => $rev,
      title => "$user/$project",
    );
    
    $state = 'display';
  }
  else { $state = 'init' }

  my $url = url_for->to_abs;
  $url->base(undef);
  my $ssh_port = config->{basic}{ssh_port};
  my $rep_home = app->git->rep_home;
  my $execute_user = getpwuid($>);
  my $ssh_rep_url = "ssh://$execute_user\@" . $url->host
    . ($ssh_port ? ":$ssh_port" : '') . "$rep_home/$user/$project.git";
%>

% layout 'common', title => "$user/$project";

  % my $logined = $api->logined;

  %= javascript begin
    $(document).ready(function () {
      var http_rep_url = '<%= url_for("$user/$project.git")->to_abs %>';
      % my $rep = $git->rep($user, $project);
      % my $ssh_port = config->{basic}{ssh_port} || '';
      
      var logined = <%= $logined ? 'true' : 'false' %>;
      var ssh_rep_url = '';
      if (logined) {
        ssh_rep_url = '<%= $ssh_rep_url %>';
      }
      
      // Click HTTP button
      $('#btn_http').on('click', function () {
        $('#rep_url').val(http_rep_url);
        $('#access').text('Read-write');
      });
      
      // Click SSH button
      $('#btn_ssh').on('click', function () {
        $('#rep_url').val(ssh_rep_url);
        $('#access').text('Read-write');
      });

      // Initialize
      $('#btn_http').trigger('click');
      
      // URL is automatically selected
      var url_selected_count = 0;
      $('#rep_url').on('mouseup', function () {
        if (url_selected_count == 0) {
          $(this).select();
        }
        url_selected_count += 1;
      });
      $('#rep_url').on('blur', function () {
        url_selected_count = 0;
      });
    });
  % end
  
  %= include '/include/header';
  
  <div class="container">
    %= include '/include/message', message => flash('message');
    %= include '/include/project_header';
    
    <h3 style="margin:20px 0px 20px 0;font-size:16px;line-height:0">
      <%= $desc %>
    </h3>
    % if ($state eq 'display') {
      <div class="border-gray radius" style="padding:0 3px;margin-bottom:10px;">
        <a class="btn" style="padding:3px 6px;margin-left:10px" href="<%= url_for("/$user/$project/archive/$rev.zip") %>">
          <i class="icon-arrow-down"></i>ZIP
        </a>
        <div class="input-append" style="margin-top:10px">
          <div class="btn-group" data-toggle="buttons-radio">
            <button class="btn" id="btn_http" style="margin-left:5px;padding:3px 6px;border-top-right-radius:0px; border-bottom-right-radius:0px"><%= $self->req->is_secure ? 'HTTPS' : 'HTTP' %></button>
            % if ($logined) {
              <button class="btn" id="btn_ssh" style="padding:3px 7px;border-radius:0">SSH</button>
            % }
          </div>
          <input id="rep_url" type="text" style="width:635px;border-radius:0;padding:3px 7px;border-top-right-radius:3px;border-bottom-right-radius:3px">
        </div>
        <span style="color:#666;font-size:12px"><b><span id="access"></span></b> access</span>
      </div>
      
      %= include '/include/code_menu', display => 'files';
      
      <div class="row" style="font-size:18px;margin-bottom:10px">
        <div class="span6">
          <a href="<%= url_for %>"><%= $project %></a>
        </div>
        <div class="text-right">
          <a href="<%= url_for("/$user/$project/commits/$rev") %>">
            <%= $commits_number %> commits
          </a>
        </div>
      </div>
      
      <div style="margin-bottom:30px">
        %= include '/include/tree';
      </div>
      
      %= include '/include/readme';
      
    % } elsif ($state eq 'init' && $api->logined($user)) {
      
      <h4>SSH</h4>
      
      <div class="text-center" style="margin-bottom:10px">
        <b>Create a new repository on the command line via ssh</b>
      </div>
      
      <pre style="margin-bottom:30px">
touch README
git init
git add README
git commit -m "first commit"
git remote add origin <%= $ssh_rep_url %>
git push -u origin master</pre>
      
      <div class="text-center" style="margin-bottom:10px">
        <b>Push an existing repository from the command line via ssh</b>
      </div>
      
      <pre style="margin-bottom:30px">
git remote add origin <%= $ssh_rep_url %>
git push -u origin master</pre>

      <hr>
      % my $http_rep_url = url_for("$user/$project.git")->to_abs;

      <h4><%= uc url_for->to_abs->scheme %></h4>

      <div class="text-center" style="margin-bottom:10px">
        <b>Create a new repository on the command line via <%= url_for->to_abs->scheme %></b>
      </div>
      
      <pre style="margin-bottom:30px">
touch README
git init
git add README
git commit -m "first commit"
git remote add origin <%= $http_rep_url %>
git push -u origin master</pre>
      
      <div class="text-center" style="margin-bottom:10px">
        <b>Push an existing repository from the command line via <%= url_for->to_abs->scheme %></b>
      </div>
      
      <pre style="margin-bottom:30px">
git remote add origin <%= $http_rep_url %>
git push -u origin master</pre>
    % } else {
      <div class="well text-center muted" style="background:white;margin-bottom:30px">
        <b>Repository is not yet created.</b>
      </div>
    % }
  </div>
  
  %= include '/include/footer';