Newer
Older
gitbucket_jkp / src / main / twirl / repo / delete.scala.html
@(branch: String,
  repository: service.RepositoryService.RepositoryInfo,
  pathList: List[String],
  fileName: String,
  content: util.JGitUtil.ContentInfo)(implicit context: app.Context)
@import context._
@import view.helpers._
@html.main(s"Deleting ${path} at ${fileName} - ${repository.owner}/${repository.name}", Some(repository)) {
  @html.header("code", repository)
  @tab(branch, repository, "files")
  <form method="POST" action="@url(repository)/remove" validate="true">
    <div class="head">
      <a href="@url(repository)/tree/@encodeRefName(branch)">@repository.name</a> /
      @pathList.zipWithIndex.map { case (section, i) =>
        <a href="@url(repository)/tree/@encodeRefName(branch)/@pathList.take(i + 1).mkString("/")">@section</a> /
      }
      @fileName
      <input type="hidden" name="fileName" id="fileName" value="@fileName"/>
      <input type="hidden" name="branch" id="branch" value="@branch"/>
      <input type="hidden" name="path" id="path" value="@pathList.mkString("/")"/>
    </div>
    <table class="table table-bordered">
      <th style="font-weight: normal;" class="box-header">
        @fileName
        <div class="pull-right align-right">
          <a href="@url(repository)/blob/@branch/@{(pathList ::: List(fileName)).mkString("/")}" class="btn btn-small">View</a>
        </div>
      </th>
      <tr>
        <td>
          <div id="diffText"></div>
          <textarea id="newText" style="display: none;"></textarea>
          <textarea id="oldText" style="display: none;">@content.content</textarea>
        </td>
      </tr>
    </table>
    <div class="issue-avatar-image">@avatar(loginAccount.get.userName, 48)</div>
      <div class="box issue-comment-box">
      <div class="box-content">
        <div>
          <strong>Commit changes</strong>
        </div>
        <div>
          <input type="text" name="message" style="width: 98%;"/>
        </div>
        <div style="text-align: right;">
          <a href="@url(repository)/blob/@encodeRefName(branch)/@pathList.mkString("/")" class="btn btn-danger">Cancel</a>
          <input type="submit" id="commit" class="btn btn-success" value="Commit changes"/>
        </div>
      </div>
    </div>
  </form>
}
<script type="text/javascript" src="@assets/jsdifflib/difflib.js"></script>
<script type="text/javascript" src="@assets/jsdifflib/diffview.js"></script>
<link href="@assets/jsdifflib/diffview.css" type="text/css" rel="stylesheet" />
<style type="text/css">
table.inlinediff {
  width: 100%;
}

table.inlinediff thead {
  display: none;
}

td.insert, td.equal, td.delete {
  width: 100%;
}
</style>
<script>
function diffUsingJS(oldTextId, newTextId, outputId) {
  // get the baseText and newText values from the two textboxes, and split them into lines
  var oldText = document.getElementById(oldTextId).value;
  if(oldText == ''){
    var oldLines = [];
  } else {
    var oldLines = difflib.stringAsLines(oldText);
  }

  var newText = document.getElementById(newTextId).value
  if(newText == ''){
    var newLines = [];
  } else {
    var newLines = difflib.stringAsLines(newText);
  }

  // create a SequenceMatcher instance that diffs the two sets of lines
  var sm = new difflib.SequenceMatcher(oldLines, newLines);

  // get the opcodes from the SequenceMatcher instance
  // opcodes is a list of 3-tuples describing what changes should be made to the base text
  // in order to yield the new text
  var opcodes = sm.get_opcodes();
  var diffoutputdiv = document.getElementById(outputId);
  while (diffoutputdiv.firstChild) diffoutputdiv.removeChild(diffoutputdiv.firstChild);

  // build the diff view and add it to the current DOM
  diffoutputdiv.appendChild(diffview.buildView({
    baseTextLines: oldLines,
    newTextLines: newLines,
    opcodes: opcodes,
    contextSize: 4,
    viewType: 1
  }));
}

$(function(){
  diffUsingJS('oldText', 'newText', 'diffText');
});
</script>