mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-10-31 18:46:28 +01:00
(refs #13)Implementing file editing on the repository viewer
This commit is contained in:
@@ -93,13 +93,6 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
treeWalk.setRecursive(true)
|
||||
getPathObjectId(path, treeWalk)
|
||||
} map { objectId =>
|
||||
// if(raw){
|
||||
// // Download
|
||||
// defining(JGitUtil.getContentFromId(git, objectId, false).get){ bytes =>
|
||||
// contentType = FileUtil.getContentType(path, bytes)
|
||||
// bytes
|
||||
// }
|
||||
// } else {
|
||||
// Viewer
|
||||
val large = FileUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize)
|
||||
val viewer = if(FileUtil.isImage(path)) "image" else if(large) "large" else "other"
|
||||
@@ -119,7 +112,6 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
}
|
||||
|
||||
repo.html.editor(id, repository, path.split("/").toList, content, new JGitUtil.CommitInfo(revCommit))
|
||||
// }
|
||||
} getOrElse NotFound
|
||||
}
|
||||
})
|
||||
|
||||
@@ -163,6 +163,45 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
||||
*/
|
||||
def isPast(date: Date): Boolean = System.currentTimeMillis > date.getTime
|
||||
|
||||
/**
|
||||
* Returns file type for AceEditor.
|
||||
*/
|
||||
def editorType(fileName: String): String = {
|
||||
fileName.toLowerCase match {
|
||||
case x if(x.endsWith(".bat")) => "batchfile"
|
||||
case x if(x.endsWith(".java")) => "java"
|
||||
case x if(x.endsWith(".scala")) => "scala"
|
||||
case x if(x.endsWith(".js")) => "javascript"
|
||||
case x if(x.endsWith(".css")) => "css"
|
||||
case x if(x.endsWith(".md")) => "markdown"
|
||||
case x if(x.endsWith(".html")) => "html"
|
||||
case x if(x.endsWith(".xml")) => "xml"
|
||||
case x if(x.endsWith(".c")) => "c_cpp"
|
||||
case x if(x.endsWith(".cpp")) => "c_cpp"
|
||||
case x if(x.endsWith(".coffee")) => "coffee"
|
||||
case x if(x.endsWith(".ejs")) => "ejs"
|
||||
case x if(x.endsWith(".hs")) => "haskell"
|
||||
case x if(x.endsWith(".json")) => "json"
|
||||
case x if(x.endsWith(".jsp")) => "jsp"
|
||||
case x if(x.endsWith(".jsx")) => "jsx"
|
||||
case x if(x.endsWith(".cl")) => "lisp"
|
||||
case x if(x.endsWith(".clojure")) => "lisp"
|
||||
case x if(x.endsWith(".lua")) => "lua"
|
||||
case x if(x.endsWith(".php")) => "php"
|
||||
case x if(x.endsWith(".py")) => "python"
|
||||
case x if(x.endsWith(".rdoc")) => "rdoc"
|
||||
case x if(x.endsWith(".rhtml")) => "rhtml"
|
||||
case x if(x.endsWith(".ruby")) => "ruby"
|
||||
case x if(x.endsWith(".sh")) => "sh"
|
||||
case x if(x.endsWith(".sql")) => "sql"
|
||||
case x if(x.endsWith(".tcl")) => "tcl"
|
||||
case x if(x.endsWith(".vbs")) => "vbscript"
|
||||
case x if(x.endsWith(".tcl")) => "tcl"
|
||||
case x if(x.endsWith(".yml")) => "yaml"
|
||||
case _ => "plain_text"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implicit conversion to add mkHtml() to Seq[Html].
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
<a href="@url(repository)/commit/@latestCommit.id" class="commit-message">@link(latestCommit.summary, repository)</a>
|
||||
</div>
|
||||
<div class="btn-group pull-right">
|
||||
<a class="btn btn-mini" href="@url(repository)/edit/@encodeRefName(branch)/@pathList.mkString("/")">Edit</a>
|
||||
<a class="btn btn-mini" href="?raw=true">Raw</a>
|
||||
<a class="btn btn-mini" href="@url(repository)/commits/@encodeRefName(branch)/@pathList.mkString("/")">History</a>
|
||||
</div>
|
||||
|
||||
@@ -20,18 +20,13 @@
|
||||
</div>
|
||||
<style type="text/css" media="screen">
|
||||
#editor {
|
||||
@*
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
*@
|
||||
width: 100%;
|
||||
height: 800px;
|
||||
height: 600px;
|
||||
}
|
||||
</style>
|
||||
<form method="POST" action="@url(repository)/edit/@encodeRefName(branch)/@pathList.mkString("/")">
|
||||
<table class="table table-bordered">
|
||||
@*
|
||||
<tr>
|
||||
<th style="font-weight: normal;">
|
||||
<div class="pull-left">
|
||||
@@ -46,17 +41,33 @@
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
*@
|
||||
<tr>
|
||||
<td>
|
||||
<div id="editor">@content.content.get</div>
|
||||
</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%;" placeholder="Update @pathList.last"/>
|
||||
</div>
|
||||
<div style="text-align: right;">
|
||||
<a href="@url(repository)/blob/@encodeRefName(branch)/@pathList.mkString("/")" class="btn btn-danger">Cancel</a>
|
||||
<input type="submit" class="btn btn-success" value="Commit changes"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
<script src="@assets/ace/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script>
|
||||
var editor = ace.edit("editor");
|
||||
editor.setTheme("ace/theme/monokai");
|
||||
//editor.getSession().setMode("ace/mode/javascript");
|
||||
editor.getSession().setMode("ace/mode/scala");
|
||||
editor.getSession().setMode("ace/mode/@editorType(pathList.last)");
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user