Newer
Older
GitBucket / src / main / twirl / gitbucket / core / repo / files.scala.html
@Yuusuke KOUNOIKE Yuusuke KOUNOIKE on 6 Jan 2019 11 KB Embedding filename to file icon tag (#2239)
@(branch: String,
  repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
  pathList: List[String],
  latestCommit: gitbucket.core.util.JGitUtil.CommitInfo,
  commitCount: Int,
  files: List[gitbucket.core.util.JGitUtil.FileInfo],
  readme: Option[(List[String], String)],
  hasWritePermission: Boolean,
  branchPullRequest: Option[(gitbucket.core.model.PullRequest, gitbucket.core.model.Issue)],
  info: Option[Any] = None,
  error: Option[Any] = None)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@import gitbucket.core.service.RepositoryService
@gitbucket.core.html.main(
  if(pathList.isEmpty){
    if(branch == repository.repository.defaultBranch){
      s"${repository.owner}/${repository.name}"
    } else {
      s"${repository.owner}/${repository.name} at ${branch}"
    }
  } else {
    s"${(repository.name :: pathList).mkString("/")} at ${branch} - ${repository.owner}/${repository.name}"
  }, Some(repository)) {
  @gitbucket.core.html.menu("files", repository, Some(branch), info, error){
    @if(pathList.isEmpty) {
      @repository.repository.description.map { description =>
        <p class="pc" style="margin-bottom: 10px;">
          <span class="normal muted">@Html(helpers.decorateHtml(helpers.urlLink(description), repository))</span>
        </p>
      }
    }
    <div id="pull-request-area"></div>
    <div class="head" style="height: 24px;">
      <div class="pull-right">
        <div class="btn-group">
          <a href="@{helpers.url(repository)}/archive@if(pathList.length > 0){/@pathList.map(helpers.urlEncode).mkString("/")}/@{helpers.urlEncode(branch)}.zip" class="btn btn-sm btn-default pc"><i class="octicon octicon-cloud-download"></i> Download ZIP</a>
          <a href="@helpers.url(repository)/find/@helpers.encodeRefName(branch)" class="btn btn-sm btn-default" data-hotkey="t"><i class="octicon octicon-search"></i></a>
          <a href="@helpers.url(repository)/commits/@helpers.encodeRefName((branch :: pathList).mkString("/"))" class="btn btn-sm btn-default"><i class="octicon octicon-history"></i> @if(commitCount > 10000){10000+} else {@commitCount} @helpers.plural(commitCount, "commit")</a>
        </div>
        <a href="@helpers.url(repository)/tree/@helpers.encodeRefName((latestCommit.id :: pathList).mkString("/"))" data-hotkey="y" style="display: none;">Transfer to URL with SHA</a>
      </div>
      @if(pathList.isEmpty){
        <div class="pull-right pc" style="margin-right: 5px;">
          <div class="btn-group">
            @if(context.platform != "linux" && context.platform != null){
              <a href="@RepositoryService.openRepoUrl(repository.httpUrl)" id="repository-clone-url" class="btn btn-sm btn-default"><i class="octicon octicon-desktop-download"></i></a>
            }
          </div>
        </div>
        <div class="pull-right pc">
          <div style="width: 240px; margin-right: 5px; margin-left: 5px;">
            @gitbucket.core.helper.html.copy("repository-url", "repository-url-copy", repository.httpUrl){
              @if(repository.sshUrl.isDefined){
                <div class="btn-group input-group-btn">
                  <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <span id="repository-url-proto">HTTP</span> <span class="caret"></span>
                  </button>
                  <ul class="dropdown-menu">
                    <li>
                      <a href="javascript:void(0);" id="repository-url-http">
                        <strong>HTTP (recommended)</strong><br>
                        Clone with Git using the repository's web address.
                      </a>
                    </li>
                    <li>
                      <a href="javascript:void(0);" id="repository-url-ssh">
                        <strong>SSH</strong><br>
                        Clone with an SSH key and passphrase from your GitBucket settings.
                      </a>
                    </li>
                  </ul>
                </div>
              }
              <input type="text" value="@repository.httpUrl" id="repository-url" class="form-control input-sm" readonly>
            }
          </div>
        </div>
      }
      <div class="pull-left">
        @gitbucket.core.helper.html.branchcontrol(branch, repository, hasWritePermission){
          @repository.branchList.map { x =>
            <li><a href="@helpers.url(repository)/tree/@helpers.encodeRefName(x)">@gitbucket.core.helper.html.checkicon(x == branch) @x</a></li>
          }
        }
        @if(pathList.nonEmpty){
          <a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)">@repository.name</a> /
          @pathList.zipWithIndex.map { case (section, i) =>
            <a href="@helpers.url(repository)/tree/@helpers.encodeRefName((branch :: pathList.take(i + 1)).mkString("/"))">@section</a> /
          }
        }
      </div>
      @if(hasWritePermission){
        <div class="btn-group pull-left" style="margin-left: 4px;">
          <a href="@helpers.url(repository)/new/@helpers.encodeRefName((branch :: pathList).mkString("/"))" class="btn btn-sm btn-default pc" title="Create a new file"><i class="octicon octicon-plus"></i></a>
          <a href="@helpers.url(repository)/upload/@helpers.encodeRefName((branch :: pathList).mkString("/"))" class="btn btn-sm btn-default pc" title="Upload files"><i class="octicon octicon-cloud-upload"></i></a>
        </div>
      }
    </div>
    <table class="table table-hover">
      @*
      <tr>
        <th colspan="4" style="font-weight: normal; border: none;">
          <a href="@url(repository)/commit/@latestCommit.id" class="commit-message">@link(latestCommit.summary, repository)</a>
          @if(latestCommit.description.isDefined){
            <a href="javascript:void(0)" onclick="$('#description-@latestCommit.id').toggle();" class="omit">...</a>
            <pre id="description-@latestCommit.id" class="commit-description" style="display: none;">@link(latestCommit.description.get, repository)</pre>
          }
        </th>
      </tr>
      *@
      <tr>
        <th colspan="4" class="latest-commit">
          <div>
            <div class="pull-right align-right" style="line-height: 18px;">
              <a href="@helpers.url(repository)/commit/@latestCommit.id" class="commit-id"><span class="muted">latest commit</span> <span class="monospace">@latestCommit.id.substring(0, 10)</span></a>
            </div>
            <div class="author-info">
              <div class="author">
                @helpers.avatarLink(latestCommit, 20)
                <span>@helpers.user(latestCommit.authorName, latestCommit.authorEmailAddress, "username strong")</span>
                <span class="muted"> authored @gitbucket.core.helper.html.datetimeago(latestCommit.authorTime)</span>
              </div>
              @if(latestCommit.isDifferentFromAuthor) {
                <div class="committer">
                  <span class="octicon octicon-arrow-right"></span>
                  <span>@helpers.user(latestCommit.committerName, latestCommit.committerEmailAddress, "username strong")</span>
                  <span class="muted"> committed @gitbucket.core.helper.html.datetimeago(latestCommit.commitTime)</span>
                </div>
              }
            </div>
          </div>
        </th>
      </tr>
      @if(pathList.size > 0){
        <tr>
          <td width="16" class="file-icon"></td>
          <td><a href="@helpers.url(repository)@if(pathList.size > 1){/tree/@helpers.encodeRefName(branch)/@helpers.encodeRefName(pathList.init.mkString("/"))}">..</a></td>
          <td></td>
          <td></td>
        </tr>
      }
      @files.map { file =>
        <tr>
          <td width="16" class="file-icon">
            @if(file.isDirectory){
              @if(file.linkUrl.isDefined){
                <i class="octicon octicon-file-symlink-directory"></i>
              } else {
                <i class="octicon octicon-file-directory"></i>
              }
            } else {
              <i class="octicon octicon-file-text" data-filename="@helpers.urlEncode(file.name)"></i>
            }
          </td>
          <td class="ellipsis-cell" style="width: 20%; min-width: 160px;">
            @if(file.isDirectory){
              @{file.linkUrl match {
                case Some(linkUrl) if linkUrl.startsWith("http://") || linkUrl.startsWith("https://") => {
                  <a href={linkUrl}>
                    <span class="simplified-path">{file.name.split("/").toList.init match {
                      case Nil  => ""
                      case list => list.mkString("", "/", "/")
                    }}</span>
                    {file.name.split("/").toList.last}
                  </a>
                }
                case Some(_) => {
                  <span>
                    <span class="simplified-path">{file.name.split("/").toList.init match {
                      case Nil  => ""
                      case list => list.mkString("", "/", "/")
                    }}</span>
                    {file.name.split("/").toList.last}
                  </span>
                }
                case None => {
                  <a href={helpers.url(repository) + "/tree" + helpers.encodeRefName((branch :: pathList).mkString("/", "/", "/") + file.name)}>
                    <span class="simplified-path">{file.name.split("/").toList.init match {
                      case Nil  => ""
                      case list => list.mkString("", "/", "/")
                    }}</span>
                    {file.name.split("/").toList.last}
                  </a>
                }
              }}
            } else {
              <a href="@helpers.url(repository)/blob@{helpers.encodeRefName((branch :: pathList).mkString("/", "/", "/") + file.name)}">@file.name</a>
            }
          </td>
          <td class="ellipsis-cell" style="width: 70%;">
            <span>
              <a href="@helpers.url(repository)/commit/@file.commitId" class="commit-message" title="@file.message">@helpers.link(file.message, repository)</a>
            </span>
          </td>
          <td style="width: 10%; min-width: 125px; text-align: right;">@gitbucket.core.helper.html.datetimeago(file.time, false)</td>
        </tr>
      }
    </table>
    @readme.map { case (filePath, content) =>
      <div id="readme" class="box-header">
        <div class="strong" style="line-height: 28px;">
          <i class="octicon octicon-file"></i>
          @filePath.last
          @if(hasWritePermission){
            <div class="btn-group pull-right">
              <a class="btn btn-sm" style="padding-right: 4px;" href="@helpers.url(repository)/edit/@helpers.encodeRefName((branch :: filePath).mkString("/"))"><i class="octicon octicon-pencil"></i></a>
            </div>
          }
        </div>
      </div>
      <div class="box-content-bottom markdown-body" style="padding-left: 20px; padding-right: 20px;">@helpers.renderMarkup(filePath, content, branch, repository, false, false, true)</div>
    }
  }
}
<script>
$(function() {
  @repository.sshUrl.map { sshUrl =>
    $('#repository-url-http').click(function(){
      $('#repository-url-proto').text('HTTP');
      $('#repository-url').val('@repository.httpUrl');
      $('#repository-clone-url').attr('href', '@RepositoryService.openRepoUrl(repository.httpUrl)')
      $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
    });

    $('#repository-url-ssh').click(function(){
      $('#repository-url-proto').text('SSH');
      $('#repository-url').val('@sshUrl');
      $('#repository-clone-url').attr('href', '@RepositoryService.openRepoUrl(sshUrl)');
      $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
    });
  }

  @if(pathList.isEmpty && hasWritePermission){
    $.get('@{helpers.url(repository)}/pulls/proposals', function(res){
      if(res) {
        $('#pull-request-area').html(res);
      }
    });
  }
});
</script>