From 373685b86d677bc6dcac9e334424fbe62a60ab75 Mon Sep 17 00:00:00 2001 From: takezoe Date: Tue, 2 Jul 2013 10:57:37 +0900 Subject: [PATCH 1/3] Assign, milestone and labels are available in Issue creation. --- src/main/scala/app/IssuesController.scala | 38 ++++++++++++++++++---- src/main/scala/service/IssuesService.scala | 11 ++++--- src/main/twirl/issues/create.scala.html | 5 ++- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/main/scala/app/IssuesController.scala b/src/main/scala/app/IssuesController.scala index ebeac25bd..31ae34646 100644 --- a/src/main/scala/app/IssuesController.scala +++ b/src/main/scala/app/IssuesController.scala @@ -14,13 +14,26 @@ trait IssuesControllerBase extends ControllerBase { self: IssuesService with RepositoryService with LabelsService with MilestonesService with UsersOnlyAuthenticator => - case class IssueForm(title: String, content: Option[String]) + case class IssueCreateForm(title: String, content: Option[String], + assignedUserName: Option[String], milestoneId: Option[Int], labelNames: Option[String]) + + case class IssueEditForm(title: String, content: Option[String]) + case class CommentForm(issueId: Int, content: String) - val form = mapping( + val issueCreateForm = mapping( + "title" -> trim(label("Title", text(required))), + "content" -> trim(optional(text())), + "assignedUserName" -> trim(optional(text())), + "milestoneId" -> trim(optional(number())), + "labelNames" -> trim(optional(text())) + )(IssueCreateForm.apply) + + val issueEditForm = mapping( "title" -> trim(label("Title", text(required))), "content" -> trim(optional(text())) - )(IssueForm.apply) + )(IssueEditForm.apply) + val commentForm = mapping( "issueId" -> label("Issue Id", number()), "content" -> trim(label("Comment", text(required))) @@ -63,16 +76,27 @@ trait IssuesControllerBase extends ControllerBase { }) // TODO requires users only and readable repository checking - post("/:owner/:repository/issues/new", form)( usersOnly { form => + post("/:owner/:repository/issues/new", issueCreateForm)( usersOnly { form => val owner = params("owner") val repository = params("repository") - redirect("/%s/%s/issues/%d".format(owner, repository, - createIssue(owner, repository, context.loginAccount.get.userName, form.title, form.content))) + val issueId = createIssue(owner, repository, context.loginAccount.get.userName, + form.title, form.content, form.assignedUserName, form.milestoneId) + + form.labelNames.map { value => + val labels = getLabels(owner, repository) + value.split(",").foreach { labelName => + labels.find(_.labelName == labelName).map { label => + registerIssueLabel(owner, repository, issueId, label.labelId) + } + } + } + + redirect("/%s/%s/issues/%d".format(owner, repository, issueId)) }) // TODO Authenticator - ajaxPost("/:owner/:repository/issues/edit/:id", form){ form => + ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm){ form => val owner = params("owner") val repository = params("repository") val issueId = params("id").toInt diff --git a/src/main/scala/service/IssuesService.scala b/src/main/scala/service/IssuesService.scala index 424afd41a..167fa4676 100644 --- a/src/main/scala/service/IssuesService.scala +++ b/src/main/scala/service/IssuesService.scala @@ -160,8 +160,8 @@ trait IssuesService { } exists, condition.labels.nonEmpty) } - def createIssue(owner: String, repository: String, loginUser: String, - title: String, content: Option[String]) = + def createIssue(owner: String, repository: String, loginUser: String, title: String, content: Option[String], + assignedUserName: Option[String], milestoneId: Option[Int]) = // next id number sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] .firstOption.filter { id => @@ -170,8 +170,8 @@ trait IssuesService { repository, id, loginUser, - None, - None, + milestoneId, + assignedUserName, title, content, false, @@ -184,6 +184,9 @@ trait IssuesService { }.map(_.issueId).update(id) > 0 } get + def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int): Unit = + IssueLabels.* insert (IssueLabel(owner, repository, issueId, labelId)) + def createComment(owner: String, repository: String, loginUser: String, issueId: Int, content: String, action: Option[String]) = IssueComments.autoInc insert ( diff --git a/src/main/twirl/issues/create.scala.html b/src/main/twirl/issues/create.scala.html index 2512f279b..123cde04f 100644 --- a/src/main/twirl/issues/create.scala.html +++ b/src/main/twirl/issues/create.scala.html @@ -4,10 +4,9 @@ @html.main("New Issue - " + repository.owner + "/" + repository.name){ @html.header("issues", repository) @tab("", repository) - +
-
@@ -51,7 +50,6 @@
-
Add Labels @@ -72,6 +70,7 @@
+ }