This commit is contained in:
takezoe
2013-06-20 21:06:28 +09:00
4 changed files with 45 additions and 29 deletions

View File

@@ -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)))
})
}

View File

@@ -20,7 +20,7 @@ object Issues extends Table[Issue]("ISSUE") {
def content = column[String]("CONTENT")
def registeredDate = column[java.sql.Date]("REGISTERED_DATE") // TODO convert java.util.Date later
def updatedDate = column[java.sql.Date]("UPDATED_DATE")
def * = userName ~ repositoryName ~ issueId ~ openedUserName ~ milestoneId.? ~ assignedUserName.? ~ title ~ content ~ registeredDate ~ updatedDate <> (Issue, Issue.unapply _)
def * = userName ~ repositoryName ~ issueId ~ openedUserName ~ milestoneId.? ~ assignedUserName.? ~ title ~ content.? ~ registeredDate ~ updatedDate <> (Issue, Issue.unapply _)
}
case class Issue(
@@ -31,6 +31,6 @@ case class Issue(
milestoneId: Option[Int],
assignedUserName: Option[String],
title: String,
content: String,
content: Option[String],
registeredDate: java.sql.Date,
updatedDate: java.sql.Date)

View File

@@ -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
}

View File

@@ -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">