Milestone completed.

This commit is contained in:
takezoe
2013-06-23 14:51:07 +09:00
parent f93dc890c8
commit 83ff171782
4 changed files with 98 additions and 52 deletions

View File

@@ -71,7 +71,8 @@ trait IssuesControllerBase extends ControllerBase {
getRepository(owner, repository, baseUrl) match {
case None => NotFound()
case Some(r) => issues.html.milestones(state, getMilestones(owner, repository), r, isWritable(owner, repository, context.loginAccount))
case Some(r) => issues.html.milestones(state, getMilestones(owner, repository),
getMilestoneIssueCounts(owner, repository), r, isWritable(owner, repository, context.loginAccount))
}
})

View File

@@ -82,6 +82,24 @@ trait IssuesService {
.sortBy(_.milestoneId desc)
.firstOption
def getMilestoneIssueCounts(owner: String, repository: String): Map[(Int, Boolean), Int] = {
import scala.slick.jdbc.{GetResult, StaticQuery}
import StaticQuery.interpolation
case class IssueCount(userName: String, repositoryName: String, milestoneId: Int, closed: Boolean, count: Int)
implicit val getIssueCount = GetResult(r => IssueCount(r.<<, r.<<, r.<<, r.<<, r.<<))
sql"""
select USER_NAME, REPOSITORY_NAME, MILESTONE_ID, CLOSED, COUNT(ISSUE_ID)
from ISSUE
where USER_NAME = $owner AND REPOSITORY_NAME = $repository AND MILESTONE_ID IS NOT NULL
group by USER_NAME, REPOSITORY_NAME, MILESTONE_ID, CLOSED"""
.as[IssueCount]
.list
.map { x => (x.milestoneId, x.closed) -> x.count }
.toMap
}
def getMilestones(owner: String, repository: String): List[Milestone] =
Query(Milestones)
.filter(m => (m.userName is owner.bind) && (m.repositoryName is repository.bind))