mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-01 02:56:08 +01:00
Added the index page which is used while in development.
This commit is contained in:
@@ -4,8 +4,9 @@ import javax.servlet._
|
|||||||
|
|
||||||
class ScalatraBootstrap extends LifeCycle {
|
class ScalatraBootstrap extends LifeCycle {
|
||||||
override def init(context: ServletContext) {
|
override def init(context: ServletContext) {
|
||||||
context.mount(new CreateRepositoryController, "/new")
|
context.mount(new IndexController, "/")
|
||||||
context.mount(new WikiController, "/*")
|
context.mount(new WikiController, "/*")
|
||||||
|
context.mount(new CreateRepositoryController, "/*")
|
||||||
context.mount(new RepositoryViewerController, "/*")
|
context.mount(new RepositoryViewerController, "/*")
|
||||||
|
|
||||||
context.addListener(new ServletContextListener(){
|
context.addListener(new ServletContextListener(){
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ abstract class ControllerBase extends ScalatraFilter with ClientSideValidationFo
|
|||||||
|
|
||||||
implicit val jsonFormats = DefaultFormats
|
implicit val jsonFormats = DefaultFormats
|
||||||
|
|
||||||
implicit def context: Context = Context(servletContext.getContextPath)
|
implicit def context: Context = Context(servletContext.getContextPath, LoginUser)
|
||||||
|
|
||||||
// TODO get from session
|
// TODO get from session
|
||||||
val LoginUser = System.getProperty("user.name")
|
private val LoginUser = System.getProperty("user.name")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Context(path: String)
|
case class Context(path: String, loginUser: String)
|
||||||
@@ -23,15 +23,15 @@ class CreateRepositoryController extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* Show the new repository form.
|
* Show the new repository form.
|
||||||
*/
|
*/
|
||||||
get("/") {
|
get("/new") {
|
||||||
html.newrepo()
|
html.newrepo()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new repository.
|
* Create new repository.
|
||||||
*/
|
*/
|
||||||
post("/", form) { form =>
|
post("/new", form) { form =>
|
||||||
val gitdir = getRepositoryDir(LoginUser, form.name)
|
val gitdir = getRepositoryDir(context.loginUser, form.name)
|
||||||
val repository = new RepositoryBuilder().setGitDir(gitdir).setBare.build
|
val repository = new RepositoryBuilder().setGitDir(gitdir).setBare.build
|
||||||
|
|
||||||
repository.create
|
repository.create
|
||||||
@@ -40,7 +40,7 @@ class CreateRepositoryController extends ControllerBase {
|
|||||||
config.setBoolean("http", null, "receivepack", true)
|
config.setBoolean("http", null, "receivepack", true)
|
||||||
config.save
|
config.save
|
||||||
|
|
||||||
val tmpdir = getInitRepositoryDir(LoginUser, form.name)
|
val tmpdir = getInitRepositoryDir(context.loginUser, form.name)
|
||||||
try {
|
try {
|
||||||
// Clone the repository
|
// Clone the repository
|
||||||
Git.cloneRepository.setURI(gitdir.toURI.toString).setDirectory(tmpdir).call
|
Git.cloneRepository.setURI(gitdir.toURI.toString).setDirectory(tmpdir).call
|
||||||
@@ -62,7 +62,7 @@ class CreateRepositoryController extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// redirect to the repository
|
// redirect to the repository
|
||||||
redirect("/%s/%s".format(LoginUser, form.name))
|
redirect("/%s/%s".format(context.loginUser, form.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,7 +72,7 @@ class CreateRepositoryController extends ControllerBase {
|
|||||||
def validate(name: String, value: String): Option[String] = {
|
def validate(name: String, value: String): Option[String] = {
|
||||||
if(!value.matches("^[a-z0-9\\-_]+$")){
|
if(!value.matches("^[a-z0-9\\-_]+$")){
|
||||||
Some("Repository name contains invalid character.")
|
Some("Repository name contains invalid character.")
|
||||||
} else if(getRepositories(LoginUser).contains(value)){
|
} else if(getRepositories(context.loginUser).contains(value)){
|
||||||
Some("Repository already exists.")
|
Some("Repository already exists.")
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|||||||
9
src/main/scala/app/IndexController.scala
Normal file
9
src/main/scala/app/IndexController.scala
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
class IndexController extends ControllerBase {
|
||||||
|
|
||||||
|
get("/"){
|
||||||
|
html.index()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -63,7 +63,7 @@ class WikiController extends ControllerBase {
|
|||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
|
|
||||||
WikiUtil.savePage(owner, repository, form.currentPageName, form.pageName,
|
WikiUtil.savePage(owner, repository, form.currentPageName, form.pageName,
|
||||||
form.content, LoginUser, form.message.getOrElse(""))
|
form.content, context.loginUser, form.message.getOrElse(""))
|
||||||
|
|
||||||
redirect("%s/%s/wiki/%s".format(owner, repository, form.pageName))
|
redirect("%s/%s/wiki/%s".format(owner, repository, form.pageName))
|
||||||
}
|
}
|
||||||
|
|||||||
9
src/main/twirl/index.scala.html
Normal file
9
src/main/twirl/index.scala.html
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
@()(implicit context: app.Context)
|
||||||
|
@import context._
|
||||||
|
@main("GitBucket"){
|
||||||
|
<h1>GitBucket</h1>
|
||||||
|
<ul>
|
||||||
|
<li><a href="@path/@context.loginUser">User page</a></li>
|
||||||
|
<li><a href="@path/new">Create new repository</a></li>
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
<div class="nav-collapse collapse">
|
<div class="nav-collapse collapse">
|
||||||
<ul class="nav pull-right">
|
<ul class="nav pull-right">
|
||||||
<li><a href="@path/new">New repo</a></li>
|
<li><a href="@path/new">New repo</a></li>
|
||||||
<li><a href="#about">Account</a></li>
|
<li><a href="@path/@context.loginUser">Account</a></li>
|
||||||
<li><a href="#users">Users</a></li>
|
<li><a href="#users">Users</a></li>
|
||||||
<li><a href="#contact">Sign out</a></li>
|
<li><a href="#contact">Sign out</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="container">
|
<div class="container body">
|
||||||
@body
|
@body
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ div.head a {
|
|||||||
|
|
||||||
div.container {
|
div.container {
|
||||||
width: 920px;
|
width: 920px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.body {
|
||||||
margin-bottom: 40px;
|
margin-bottom: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user