mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 03:26:06 +01:00
Start to implement WikiController.
Changed controllers from servlet to filter by mapping flexibility.
This commit is contained in:
@@ -4,8 +4,9 @@ import javax.servlet._
|
||||
|
||||
class ScalatraBootstrap extends LifeCycle {
|
||||
override def init(context: ServletContext) {
|
||||
context.mount(new CreateRepositoryServlet, "/new")
|
||||
context.mount(new RepositoryViewerServlet, "/*")
|
||||
context.mount(new CreateRepositoryController, "/new")
|
||||
context.mount(new WikiController, "/*")
|
||||
context.mount(new RepositoryViewerController, "/*")
|
||||
|
||||
context.addListener(new ServletContextListener(){
|
||||
def contextInitialized(e: ServletContextEvent): Unit = {
|
||||
|
||||
@@ -11,7 +11,7 @@ import jp.sf.amateras.scalatra.forms._
|
||||
/**
|
||||
* Creates new repository.
|
||||
*/
|
||||
class CreateRepositoryServlet extends ServletBase {
|
||||
class CreateRepositoryController extends ControllerBase {
|
||||
|
||||
case class RepositoryCreationForm(name: String, description: String)
|
||||
|
||||
@@ -64,7 +64,7 @@ case class ContentInfo(viewType: String, content: Option[String])
|
||||
/**
|
||||
* The repository viewer.
|
||||
*/
|
||||
class RepositoryViewerServlet extends ServletBase {
|
||||
class RepositoryViewerController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* Displays user information.
|
||||
@@ -9,7 +9,7 @@ import jp.sf.amateras.scalatra.forms._
|
||||
/**
|
||||
* Provides generic features for ScalatraServlet implementations.
|
||||
*/
|
||||
abstract class ServletBase extends ScalatraServlet with ClientSideValidationFormSupport with JacksonJsonSupport {
|
||||
abstract class ControllerBase extends ScalatraFilter with ClientSideValidationFormSupport with JacksonJsonSupport {
|
||||
|
||||
implicit val jsonFormats = DefaultFormats
|
||||
|
||||
|
||||
9
src/main/scala/app/UsersController.scala
Normal file
9
src/main/scala/app/UsersController.scala
Normal file
@@ -0,0 +1,9 @@
|
||||
package app
|
||||
|
||||
class UsersController extends ControllerBase {
|
||||
|
||||
get("/"){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package app
|
||||
|
||||
class UsersServlet extends ServletBase {
|
||||
|
||||
get("/"){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
14
src/main/scala/app/WikiController.scala
Normal file
14
src/main/scala/app/WikiController.scala
Normal file
@@ -0,0 +1,14 @@
|
||||
package app
|
||||
|
||||
import util.{WikiUtil, JGitUtil}
|
||||
|
||||
class WikiController extends ControllerBase {
|
||||
|
||||
get("/:owner/:repository/wiki"){
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
|
||||
html.wiki(WikiUtil.getPage(owner, repository, "Home"), JGitUtil.getRepositoryInfo(owner, repository, servletContext))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.io.File
|
||||
import java.util.Date
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.eclipse.jgit.lib.RepositoryBuilder
|
||||
|
||||
object WikiUtil {
|
||||
|
||||
@@ -37,17 +38,34 @@ object WikiUtil {
|
||||
def getWikiWorkDir(owner: String, repository: String): File =
|
||||
new File("%s/tmp/%s/%s-wiki".format(Directory.RepositoryHome, owner, repository))
|
||||
|
||||
// TODO synchronized?
|
||||
def createWikiRepository(owner: String, repository: String): Unit = {
|
||||
val dir = getWikiRepositoryDir(owner, repository)
|
||||
if(!dir.exists){
|
||||
val repo = new RepositoryBuilder().setGitDir(dir).setBare.build
|
||||
repo.create
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wiki page.
|
||||
*/
|
||||
def getPage(owner: String, repository: String, pageName: String): Option[WikiPageInfo] = {
|
||||
createWikiRepository(owner, repository)
|
||||
val git = Git.open(getWikiRepositoryDir(owner, repository))
|
||||
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName).map { file =>
|
||||
WikiPageInfo(file.name, new String(git.getRepository.open(file.id).getBytes, "UTF-8"))
|
||||
try {
|
||||
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName).map { file =>
|
||||
WikiPageInfo(file.name, new String(git.getRepository.open(file.id).getBytes, "UTF-8"))
|
||||
}
|
||||
} catch {
|
||||
// TODO no commit, but it should not judge by exception.
|
||||
case e: NullPointerException => None
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
// def getPageList(owner: String, repository: String): List[WikiPageHistoryInfo]
|
||||
|
||||
// TODO
|
||||
//def getPageHistory(owner: String, repository: String, pageName: String): List[WikiPageHistoryInfo]
|
||||
|
||||
@@ -56,6 +74,8 @@ object WikiUtil {
|
||||
* Save the wiki page.
|
||||
*/
|
||||
def savePage(owner: String, repository: String, pageName: String, content: String, committer: String, message: String): Unit = {
|
||||
createWikiRepository(owner, repository)
|
||||
|
||||
val workDir = getWikiWorkDir(owner, repository)
|
||||
|
||||
// clone
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
@import context._
|
||||
@import view.helpers
|
||||
@main(repository.owner+"/"+repository.name) {
|
||||
@header(branch, repository)
|
||||
@header("code", repository)
|
||||
@navtab(branch, repository, "files")
|
||||
<div class="head">
|
||||
<a href="@path/@repository.owner/@repository.name/tree/@branch">@repository.name</a> /
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
@import view.helpers
|
||||
@import org.eclipse.jgit.diff.DiffEntry.ChangeType
|
||||
@main(helpers.cut(commit.message, 20)){
|
||||
@header(branch, repository)
|
||||
@header("code", repository)
|
||||
@navtab(branch, repository, "commits")
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
@import context._
|
||||
@import view.helpers
|
||||
@main(repository.owner+"/"+repository.name) {
|
||||
@header(branch, repository)
|
||||
@header("code", repository)
|
||||
@navtab(branch, repository, "commits")
|
||||
<div class="head">
|
||||
<a href="@path/@repository.owner/@repository.name/tree/@branch">@repository.name</a> / Commit History
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
@import context._
|
||||
@import view.helpers
|
||||
@main(repository.owner+"/"+repository.name) {
|
||||
@header(branch, repository)
|
||||
@header("code", repository)
|
||||
@navtab(branch, repository, "files")
|
||||
<div class="head">
|
||||
<a href="@path/@repository.owner/@repository.name/tree/@branch">@repository.name</a> /
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@(branch: String, repository: app.RepositoryInfo)(implicit context: app.Context)
|
||||
@(active: String, repository: app.RepositoryInfo)(implicit context: app.Context)
|
||||
@import context._
|
||||
<div class="head">
|
||||
<a href="@path/@repository.owner">@repository.owner</a> / <a href="@path/@repository.owner/@repository.name">@repository.name</a>
|
||||
@@ -6,10 +6,10 @@
|
||||
<div class="navbar">
|
||||
<div class="navbar-inner">
|
||||
<ul class="nav">
|
||||
<li class="active"><a href="#">Code</a></li>
|
||||
<li><a href="#">Issue</a></li>
|
||||
<li><a href="#">Wiki</a></li>
|
||||
<li><a href="#">Settings</a></li>
|
||||
<li@if(active=="code"){ class="active"}><a href="@path/@repository.owner/@repository.name">Code</a></li>
|
||||
<li@if(active=="issue"){ class="active"}><a href="#">Issue</a></li>
|
||||
<li@if(active=="wiki"){ class="active"}><a href="@path/@repository.owner/@repository.name/wiki">Wiki</a></li>
|
||||
<li@if(active=="settings"){ class="active"}><a href="#">Settings</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
11
src/main/twirl/wiki.scala.html
Normal file
11
src/main/twirl/wiki.scala.html
Normal file
@@ -0,0 +1,11 @@
|
||||
@(page: Option[util.WikiUtil.WikiPageInfo], repository: app.RepositoryInfo)(implicit context: app.Context)
|
||||
@main("Wiki"){
|
||||
@header("wiki", repository)
|
||||
<ul class="nav nav-tabs">
|
||||
<li><a href="">Home</a></li>
|
||||
<li><a href="">Pages</a></li>
|
||||
<li><a href="">Wiki History</a></li>
|
||||
<li><a href="">Git Access</a></li>
|
||||
</ul>
|
||||
xxxx
|
||||
}
|
||||
Reference in New Issue
Block a user