diff --git a/src/main/scala/app/IssuesController.scala b/src/main/scala/app/IssuesController.scala index 8fddaa9..b63625d 100644 --- a/src/main/scala/app/IssuesController.scala +++ b/src/main/scala/app/IssuesController.scala @@ -61,7 +61,7 @@ issues.html.issue( _, getComments(owner, repository, issueId.toInt), - getIssueLabel(owner, repository, issueId.toInt), + getIssueLabels(owner, repository, issueId.toInt), (getCollaborators(owner, repository) :+ owner).sorted, getMilestones(owner, repository), getLabels(owner, repository), @@ -115,16 +115,6 @@ redirect("/%s/%s/issues/_data/%d".format(owner, repository, issueId)) } - // TODO Authenticator - ajaxPost("/:owner/:repository/issues/:id/label/:labelId/new"){ - "TODO Insert!" - } - - // TODO Authenticator - ajaxPost("/:owner/:repository/issues/:id/label/:labelId/delete"){ - "TODO Delete!" - } - // TODO requires users only and readable repository checking post("/:owner/:repository/issue_comments/new", commentForm)( usersOnly { form => val owner = params("owner") @@ -178,6 +168,28 @@ } getOrElse NotFound } + // TODO Authenticator + ajaxPost("/:owner/:repository/issues/:id/label/new"){ + val owner = params("owner") + val repository = params("repository") + val issueId = params("id").toInt + + registerIssueLabel(owner, repository, issueId, params("labelId").toInt) + + issues.html.labellist(getIssueLabels(owner, repository, issueId)) + } + + // TODO Authenticator + ajaxPost("/:owner/:repository/issues/:id/label/delete"){ + val owner = params("owner") + val repository = params("repository") + val issueId = params("id").toInt + + deleteIssueLabel(owner, repository, issueId, params("labelId").toInt) + + issues.html.labellist(getIssueLabels(owner, repository, issueId)) + } + ajaxPost("/:owner/:repository/issues/assign/:id"){ val owner = params("owner") val repository = params("repository") diff --git a/src/main/scala/service/IssuesService.scala b/src/main/scala/service/IssuesService.scala index 299b4c2..778f24e 100644 --- a/src/main/scala/service/IssuesService.scala +++ b/src/main/scala/service/IssuesService.scala @@ -25,7 +25,7 @@ Query(IssueComments) filter (_.byPrimaryKey(commentId.toInt)) firstOption else None - def getIssueLabel(owner: String, repository: String, issueId: Int) = + def getIssueLabels(owner: String, repository: String, issueId: Int) = IssueLabels .innerJoin(Labels).on { (t1, t2) => t1.byLabel(t2.userName, t2.repositoryName, t2.labelId) diff --git a/src/main/twirl/issues/issue.scala.html b/src/main/twirl/issues/issue.scala.html index b5d36cd..0074136 100644 --- a/src/main/twirl/issues/issue.scala.html +++ b/src/main/twirl/issues/issue.scala.html @@ -189,21 +189,22 @@ }); $('a.toggle-label').click(function(){ - var url = '@url(repository)/issues/@issue.issueId/label/' + $(this).data('label-id'); - var icon; + var path, icon; var i = $(this).children('i'); if(i.hasClass('icon-ok')){ - url += '/delete'; + path = 'delete'; icon = 'icon-white'; } else { - url += '/new'; + path = 'new'; icon = 'icon-ok'; } - $.post(url, + $.post('@url(repository)/issues/@issue.issueId/label/' + path, + { + labelId : $(this).data('label-id') + }, function(data){ i.removeClass().addClass(icon); - // TODO label sort - alert(data); + $('ul.label-list').empty().html(data); }); return false; });