Implemented the issue stub.

This commit is contained in:
shimamoto
2013-06-27 14:40:59 +09:00
parent 2c9ed60dbb
commit aa8b705748
3 changed files with 45 additions and 15 deletions

View File

@@ -62,17 +62,25 @@ trait IssuesControllerBase extends ControllerBase {
val repository = params("repository")
redirect("/%s/%s/issues/%d".format(owner, repository,
saveIssue(owner, repository, context.loginAccount.get.userName, form.title, form.content)))
createIssue(owner, repository, context.loginAccount.get.userName, form.title, form.content)))
})
// TODO Authenticator
// TODO Authenticator, Validation
post("/:owner/:repository/issues/:id"){
// TODO update issue
val owner = params("owner")
val repository = params("repository")
val issueId = params("id").toInt
val title = params("title")
val content = params.get("content")
updateIssue(owner, repository, issueId, title, content)
contentType = formats("json")
org.json4s.jackson.Serialization.write(Map(
"title" -> "test title 2",
"content" -> view.Markdown.toHtml("* hoge", getRepository("root", "test", baseUrl).get, false, true, true)))
org.json4s.jackson.Serialization.write(
Map("title" -> title,
"content" -> view.Markdown.toHtml(content getOrElse "No description given.",
getRepository(owner, repository, baseUrl).get, false, true, true)))
}
// TODO requires users only and readable repository checking
@@ -81,16 +89,21 @@ trait IssuesControllerBase extends ControllerBase {
val repository = params("repository")
redirect("/%s/%s/issues/%d#comment-%d".format(owner, repository, form.issueId,
saveComment(owner, repository, context.loginAccount.get.userName, form.issueId, form.content)))
createComment(owner, repository, context.loginAccount.get.userName, form.issueId, form.content)))
})
// TODO Authenticator
// TODO Authenticator, Validation
post("/:owner/:repository/issue_comments/:id"){
// TODO update issue memo
val commentId = params("id").toInt
val content = params("content")
updateComment(commentId, content)
contentType = formats("json")
org.json4s.jackson.Serialization.write(Map(
"content" -> view.Markdown.toHtml("* hoge memo", getRepository("root", "test", baseUrl).get, false, true, true)))
org.json4s.jackson.Serialization.write(
Map("content" -> view.Markdown.toHtml(content,
getRepository(params("owner"), params("repository"), baseUrl).get, false, true, true)))
}
// TODO Authenticator

View File

@@ -167,7 +167,7 @@ trait IssuesService {
} exists, condition.labels.nonEmpty)
}
def saveIssue(owner: String, repository: String, loginUser: String,
def createIssue(owner: String, repository: String, loginUser: String,
title: String, content: Option[String]) =
// next id number
sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int]
@@ -191,7 +191,7 @@ trait IssuesService {
}.map(_.issueId).update(id) > 0
} get
def saveComment(owner: String, repository: String, loginUser: String,
def createComment(owner: String, repository: String, loginUser: String,
issueId: Int, content: String) =
IssueComments.autoInc insert (
owner,
@@ -202,6 +202,23 @@ trait IssuesService {
currentDate,
currentDate)
def updateIssue(owner: String, repository: String, issueId: Int,
title: String, content: Option[String]) =
Issues filter { t =>
(t.userName is owner.bind) &&
(t.repositoryName is repository.bind) &&
(t.issueId is issueId.bind)
} map { t =>
t.title ~ t.content.? ~ t.updatedDate
} update (title, content, currentDate)
def updateComment(commentId: Int, content: String) =
IssueComments filter {
_.commentId is commentId.bind
} map { t =>
t.content ~ t.updatedDate
} update (content, currentDate)
}
object IssuesService {

View File

@@ -4,7 +4,7 @@
@if(!isComment){
<input type="text" style="width: 730px;" id="edit-title" value="@title.get"/>
}
<textarea style="width: 730px; height: 100px;" id="edit-content@if(isComment){"-" + key}">@content</textarea>
<textarea style="width: 730px; height: 100px;" id="edit-content@if(isComment){-@key}">@content</textarea>
<input type="button" class="btn btn-small" value="Update @{if(isComment) "Comment" else "Issue"}"/>
<span class="pull-right"><a class="btn btn-small btn-danger" href="#">Cancel</a></span>
<script>
@@ -22,7 +22,7 @@ $(function(){
var url = '@path/@owner/@repository/issues/@key';
var param = {
title : $('#edit-title').val(),
content : $('#edit-content-@key').val()
content : $('#edit-content').val()
};
var func = function(data){
$('#issueTitle').empty().text(data.title);