mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 03:26:06 +01:00
Implemented the registration of the issue.
This commit is contained in:
@@ -1,11 +1,22 @@
|
||||
package app
|
||||
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
import service._
|
||||
import util.UsersOnlyAuthenticator
|
||||
|
||||
class IssuesController extends IssuesControllerBase
|
||||
with RepositoryService with AccountService
|
||||
with IssuesService with RepositoryService with AccountService with UsersOnlyAuthenticator
|
||||
|
||||
trait IssuesControllerBase extends ControllerBase { self: RepositoryService =>
|
||||
trait IssuesControllerBase extends ControllerBase {
|
||||
self: IssuesService with RepositoryService with UsersOnlyAuthenticator =>
|
||||
|
||||
case class IssueForm(title: String, content: Option[String])
|
||||
|
||||
val form = mapping(
|
||||
"title" -> trim(label("Title", text(required))),
|
||||
"content" -> trim(optional(text()))
|
||||
)(IssueForm.apply)
|
||||
|
||||
get("/:owner/:repository/issues"){
|
||||
issues.html.issues(getRepository(params("owner"), params("repository"), baseUrl).get)
|
||||
@@ -15,12 +26,16 @@ trait IssuesControllerBase extends ControllerBase { self: RepositoryService =>
|
||||
issues.html.issue(getRepository(params("owner"), params("repository"), baseUrl).get)
|
||||
}
|
||||
|
||||
get("/:owner/:repository/issues/new"){
|
||||
get("/:owner/:repository/issues/new")( usersOnly {
|
||||
issues.html.issueedit(getRepository(params("owner"), params("repository"), baseUrl).get)
|
||||
}
|
||||
})
|
||||
|
||||
post("/:owner/:repository/issues"){
|
||||
redirect("%s/%s/issues".format(params("owner"), params("repository")))
|
||||
}
|
||||
post("/:owner/:repository/issues", form)( usersOnly { form =>
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
|
||||
redirect("/%s/%s/issues/%d".format(owner, repository,
|
||||
saveIssue(owner, repository, context.loginAccount.get.userName, form.title, form.content)))
|
||||
})
|
||||
|
||||
}
|
||||
@@ -9,26 +9,26 @@ import model._
|
||||
|
||||
trait IssuesService {
|
||||
def saveIssue(owner: String, repository: String, loginUser: String,
|
||||
title: String, content: String) = {
|
||||
title: String, content: Option[String]) =
|
||||
// next id number
|
||||
val id = sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int].first
|
||||
sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int]
|
||||
.firstOption.filter { id =>
|
||||
Issues insert Issue(
|
||||
owner,
|
||||
repository,
|
||||
id,
|
||||
loginUser,
|
||||
None,
|
||||
None,
|
||||
title,
|
||||
content,
|
||||
new java.sql.Date(System.currentTimeMillis), // TODO
|
||||
new java.sql.Date(System.currentTimeMillis))
|
||||
|
||||
Issues insert Issue(
|
||||
owner,
|
||||
repository,
|
||||
id,
|
||||
loginUser,
|
||||
None,
|
||||
None,
|
||||
title,
|
||||
content,
|
||||
new java.sql.Date(System.currentTimeMillis), // TODO
|
||||
new java.sql.Date(System.currentTimeMillis))
|
||||
|
||||
// increment id
|
||||
IssueId filter { t =>
|
||||
(t.userName is owner.bind) && (t.repositoryName is repository.bind)
|
||||
} map (_.issueId) update(id)
|
||||
}
|
||||
// increment issue id
|
||||
IssueId.filter { t =>
|
||||
(t.userName is owner.bind) && (t.repositoryName is repository.bind)
|
||||
}.map(_.issueId).update(id) > 0
|
||||
} get
|
||||
|
||||
}
|
||||
@@ -6,9 +6,10 @@
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span9">
|
||||
<form action="@path/@repository.owner/@repository.name/issues" method="POST">
|
||||
<form action="@path/@repository.owner/@repository.name/issues" method="POST" validate="true">
|
||||
<div class="box">
|
||||
<div class="box-content">
|
||||
<span id="error-title" class="error"></span>
|
||||
<input type="text" name="title" value="" placeholder="Title" style="width: 650px;"/>
|
||||
@*
|
||||
<ul class="nav nav-tabs">
|
||||
|
||||
Reference in New Issue
Block a user