Newer
Older
GitBucket / src / main / twirl / gitbucket / core / pulls / pullreq.scala.html
@Naoki Takezoe Naoki Takezoe on 22 Dec 2016 6 KB (refs #1386)Bump jQuery to 1.12.2
@(issue: gitbucket.core.model.Issue,
  pullreq: gitbucket.core.model.PullRequest,
  comments: List[gitbucket.core.model.Comment],
  issueLabels: List[gitbucket.core.model.Label],
  collaborators: List[String],
  milestones: List[(gitbucket.core.model.Milestone, Int, Int)],
  labels: List[gitbucket.core.model.Label],
  dayByDayCommits: Seq[Seq[gitbucket.core.util.JGitUtil.CommitInfo]],
  diffs: Seq[gitbucket.core.util.JGitUtil.DiffInfo],
  isEditable: Boolean,
  isManageable: Boolean,
  repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
  flash: Map[String, String])(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@import gitbucket.core.model.IssueComment
@import gitbucket.core.model.CommitComment
@gitbucket.core.html.main(s"${issue.title} - Pull request #${issue.issueId} - ${repository.owner}/${repository.name}", Some(repository)){
  @gitbucket.core.html.menu("pulls", repository){
    @defining(dayByDayCommits.flatten){ commits =>
      <div>
        <div class="show-title pull-right">
          @if(isManageable || context.loginAccount.map(_.userName == issue.openedUserName).getOrElse(false)){
            <a class="btn" href="#" id="edit">Edit</a>
          }
          @if(context.loginAccount.isDefined){
            <a class="btn btn-success" href="@helpers.url(repository)/compare">New pull request</a>
          }
        </div>
        <div class="edit-title pull-right" style="display: none;">
          <a class="btn btn-success" href="#" id="update">Save</a>  <a class="btn btn-default" href="#" id="cancel">Cancel</a>
        </div>
        <h1 class="body-title">
          <span class="show-title">
            <span id="show-title">@issue.title</span>
            <span class="muted">#@issue.issueId</span>
          </span>
          <span class="edit-title" style="display: none;">
            <span id="error-edit-title" class="error"></span>
            <input type="text" class="form-control" style="width: 700px;" id="edit-title" value="@issue.title"/>
          </span>
        </h1>
      </div>
      <div style="margin-bottom: 15px">
        @if(issue.closed) {
          @comments.flatMap @{
            case comment: IssueComment => Some(comment)
            case _ => None
          }.find(_.action == "merge").map{ comment =>
            <span class="label label-info issue-status">Merged</span>
            <span class="muted">
              @helpers.user(comment.commentedUserName, styleClass="username strong") merged @commits.size @helpers.plural(commits.size, "commit")
              into <code>@pullreq.userName:@pullreq.branch</code> from <code>@pullreq.requestUserName:@pullreq.requestBranch</code>
              @gitbucket.core.helper.html.datetimeago(comment.registeredDate)
            </span>
          }.getOrElse {
            <span class="label label-important issue-status">Closed</span>
            <span class="muted">
              @helpers.user(issue.openedUserName, styleClass="username strong") wants to merge @commits.size @helpers.plural(commits.size, "commit")
              into <code>@pullreq.userName:@pullreq.branch</code> from <code>@pullreq.requestUserName:@pullreq.requestBranch</code>
            </span>
          }
        } else {
          <span class="label label-success issue-status">Open</span>
          <span class="muted">
            @helpers.user(issue.openedUserName, styleClass="username strong") wants to merge @commits.size @helpers.plural(commits.size, "commit")
            into <code>@pullreq.userName:@pullreq.branch</code> from <code>@pullreq.requestUserName:@pullreq.requestBranch</code>
          </span>
        }
      </div>
      <ul class="nav nav-tabs fill-width" id="pullreq-tab">
        <li><a href="#conversation">Conversation <span class="badge">@comments.flatMap @{
          case comment: IssueComment => Some(comment)
          case _: CommitComment => None
        }.size</span></a></li>
        <li><a href="#commits">Commits <span class="badge">@commits.size</span></a></li>
        <li><a href="#files">Files Changed <span class="badge">@diffs.size</span></a></li>
      </ul>
      <div class="tab-content fill-width" style="padding-top: 20px;">
        <div class="tab-pane" id="conversation">
          @flash.get("error").map{ error =>
            <div class="alert alert-error">@error</div>
          }
          @flash.get("info").map{ info =>
            <div class="alert alert-info">@info</div>
          }
          @gitbucket.core.pulls.html.conversation(issue, pullreq, comments, issueLabels, collaborators, milestones, labels, isEditable, isManageable, repository)
        </div>
        <div class="tab-pane" id="commits">
          @gitbucket.core.pulls.html.commits(dayByDayCommits, Some(comments), repository)
        </div>
        <div class="tab-pane" id="files">
          @gitbucket.core.helper.html.diff(diffs, repository, Some(commits.head.id), Some(commits.last.id), true, Some(pullreq.issueId), isManageable, true)
        </div>
      </div>
    }
  }
}
<script>
$(function(){
  // Determine active tab from hash
  if(location.hash == '#commits'){
    $('li:has(a[href="#commits"])').addClass('active');
    $('div#commits').addClass('active');
  } else if(location.hash == '#files'){
    $('li:has(a[href="#files"])').addClass('active');
    $('div#files').addClass('active');
  } else {
    $('li:has(a[href="#conversation"])').addClass('active');
    $('div#conversation').addClass('active');
  }
  // Set hash when tab is clicked
  $('ul.nav-tabs li a').click(function(e){
    location.href = $(e.delegateTarget).attr("href");
  });

  $('#pullreq-tab a').click(function (e) {
    e.preventDefault();
    $(this).tab('show');
  });

  $('#edit').click(function(){
    $('.edit-title').show();
    $('.show-title').hide();
    return false;
  });

  $('#update').click(function(){
    $(this).attr('disabled', 'disabled');
    $.ajax({
      url: '@helpers.url(repository)/issues/edit_title/@issue.issueId',
      type: 'POST',
      data: {
        title   : $('#edit-title').val()
      }
    }).done(function(data){
      $('#show-title').empty().text(data.title);
      $('#cancel').click();
      $(this).removeAttr('disabled');
    }).fail(function(req){
      $(this).removeAttr('disabled');
      $('#error-edit-title').text($.parseJSON(req.responseText).title);
    });
    return false;
  });

  $('#cancel').click(function(){
    $('.edit-title').hide();
    $('.show-title').show();
    return false;
  });
});
</script>