diff --git a/src/main/scala/app/IssuesController.scala b/src/main/scala/app/IssuesController.scala index bd4a900..95fd25b 100644 --- a/src/main/scala/app/IssuesController.scala +++ b/src/main/scala/app/IssuesController.scala @@ -21,7 +21,6 @@ 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) case class IssueStateForm(issueId: Int, content: Option[String]) @@ -36,10 +35,9 @@ val issueTitleEditForm = mapping( "title" -> trim(label("Title", text(required))) )(x => x) -// val issueEditForm = mapping( -// "title" -> trim(label("Title", text(required))), -// "content" -> trim(optional(text())) -// )(IssueEditForm.apply) + val issueEditForm = mapping( + "content" -> trim(optional(text())) + )(x => x) val commentForm = mapping( "issueId" -> label("Issue Id", number()), @@ -126,7 +124,7 @@ getIssue(owner, name, params("id")).map { issue => if(isEditable(owner, name, issue.openedUserName)){ // update issue - updateIssueTitle(owner, name, issue.issueId, title) + updateIssue(owner, name, issue.issueId, title, issue.content) // extract references and create refer comment // TODO Confirmation(about "issue" parameter) createReferComment(owner, name, issue, title) @@ -137,20 +135,20 @@ } }) -// ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (form, repository) => -// defining(repository.owner, repository.name){ case (owner, name) => -// getIssue(owner, name, params("id")).map { issue => -// if(isEditable(owner, name, issue.openedUserName)){ -// // update issue -// updateIssue(owner, name, issue.issueId, form.title, form.content) -// // extract references and create refer comment -// createReferComment(owner, name, issue, form.title + " " + form.content.getOrElse("")) -// -// redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}") -// } else Unauthorized -// } getOrElse NotFound -// } -// }) + ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) => + defining(repository.owner, repository.name){ case (owner, name) => + getIssue(owner, name, params("id")).map { issue => + if(isEditable(owner, name, issue.openedUserName)){ + // update issue + updateIssue(owner, name, issue.issueId, issue.title, content) + // extract references and create refer comment + createReferComment(owner, name, issue, content.getOrElse("")) + + redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}") + } else Unauthorized + } getOrElse NotFound + } + }) post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) => handleComment(form.issueId, Some(form.content), repository)() map { case (issue, id) => @@ -192,7 +190,7 @@ if(isEditable(x.userName, x.repositoryName, x.openedUserName)){ params.get("dataType") collect { case t if t == "html" => issues.html.editissue( - x.title, x.content, x.issueId, x.userName, x.repositoryName) + x.content, x.issueId, x.userName, x.repositoryName) } getOrElse { contentType = formats("json") org.json4s.jackson.Serialization.write( diff --git a/src/main/scala/service/IssuesService.scala b/src/main/scala/service/IssuesService.scala index 2e834df..9e7bfa6 100644 --- a/src/main/scala/service/IssuesService.scala +++ b/src/main/scala/service/IssuesService.scala @@ -225,22 +225,14 @@ registeredDate = currentDate, updatedDate = currentDate) - def updateIssueTitle(owner: String, repository: String, issueId: Int, title: String)(implicit s: Session) = + def updateIssue(owner: String, repository: String, issueId: Int, + title: String, content: Option[String])(implicit s: Session) = Issues .filter (_.byPrimaryKey(owner, repository, issueId)) .map { t => - (t.title, t.updatedDate) + (t.title, t.content.?, t.updatedDate) } - .update (title, currentDate) - -// def updateIssue(owner: String, repository: String, issueId: Int, -// title: String, content: Option[String])(implicit s: Session) = -// Issues -// .filter (_.byPrimaryKey(owner, repository, issueId)) -// .map { t => -// (t.title, t.content.?, t.updatedDate) -// } -// .update (title, content, currentDate) + .update (title, content, currentDate) def updateAssignedUserName(owner: String, repository: String, issueId: Int, assignedUserName: Option[String])(implicit s: Session) = diff --git a/src/main/twirl/issues/commentlist.scala.html b/src/main/twirl/issues/commentlist.scala.html index 7038e1d..979062f 100644 --- a/src/main/twirl/issues/commentlist.scala.html +++ b/src/main/twirl/issues/commentlist.scala.html @@ -11,11 +11,11 @@ @user(issue.openedUserName, styleClass="username strong") commented on @datetime(issue.registeredDate) @if(hasWritePermission || loginAccount.map(_.userName == issue.openedUserName).getOrElse(false)){ - + } -
+
@markdown(issue.content getOrElse "No description provided.", repository, false, true)
@@ -102,13 +102,22 @@ \ No newline at end of file