Add issue count for each labels.

This commit is contained in:
takezoe
2013-06-26 10:28:14 +09:00
parent 8283302c18
commit cceda62ef7
3 changed files with 45 additions and 5 deletions

View File

@@ -94,8 +94,9 @@ trait IssuesControllerBase extends ControllerBase {
countIssue(owner, repository, condition.copy(state = "open"), filter, userName),
countIssue(owner, repository, condition.copy(state = "closed"), filter, userName),
countIssue(owner, repository, condition, "all", None),
context.loginAccount.map(x => countIssue(owner, repository, condition, "assigned", Some(x.userName))),
context.loginAccount.map(x => countIssue(owner, repository, condition, "created_by", Some(x.userName))),
context.loginAccount.map(x => countIssue(owner, repository, condition, "assigned", userName)),
context.loginAccount.map(x => countIssue(owner, repository, condition, "created_by", userName)),
countIssueGroupByLabels(owner, repository, condition, filter, userName),
condition, filter, repositoryInfo, isWritable(owner, repository, context.loginAccount))
} getOrElse NotFound

View File

@@ -2,7 +2,7 @@ package service
import scala.slick.driver.H2Driver.simple._
import Database.threadLocalSession
import scala.slick.jdbc.{StaticQuery => Q}
import scala.slick.jdbc.{StaticQuery => Q, GetResult}
import Q.interpolation
import model._
@@ -41,6 +41,45 @@ trait IssuesService {
def countIssue(owner: String, repository: String, condition: IssueSearchCondition, filter: String, userName: Option[String]): Int =
searchIssueQuery(owner, repository, condition, filter, userName) map (_.length) first
/**
* Returns the Map which contains issue count for each labels.
*
* @param owner the repository owner
* @param repository the repository name
* @param condition the search condition
* @param filter the filter type ("all", "assigned" or "created_by")
* @param userName the filter user name required for "assigned" and "created_by"
* @return the Map which contains issue count for each labels (key is label name, value is issue count),
*/
def countIssueGroupByLabels(owner: String, repository: String, condition: IssueSearchCondition,
filter: String, userName: Option[String]): Map[String, Int] = {
case class LabelCount(labelName: String, count: Int)
implicit val getLabelCount = GetResult(r => LabelCount(r.<<, r.<<))
Q.query[(String, String, Boolean), LabelCount](
"""SELECT
T3.LABEL_NAME, COUNT(T1.ISSUE_ID)
FROM ISSUE T1
INNER JOIN ISSUE_LABEL T2 ON T1.ISSUE_ID = T2.ISSUE_ID
INNER JOIN LABEL T3 ON T2.LABEL_ID = T3.LABEL_ID
WHERE
T1.USER_NAME = ?
AND T1.REPOSITORY_NAME = ?
AND T1.CLOSED = ?
""" +
condition.milestoneId.map(" AND T1.MILESTONE_ID = " + milestoneId).getOrElse("") +
(filter match {
case "assigned" => " AND T1.ASSIGNED_USER_NAME = '%s'".format(userName.get)
case "created_by" => " AND T1.OPENED_USER_NAME = '%s'".format(userName.get)
case _ => ""
}) +
" GROUP BY T3.LABEL_NAME")
.list(owner, repository, condition.state == "closed")
.map(x => x.labelName -> x.count)
.toMap
}
/**
* Returns the search result against issues.
*

View File

@@ -1,5 +1,5 @@
@(issues: List[model.Issue], labels: List[model.Label], milestones: List[model.Milestone],
openCount: Int, closedCount: Int, allCount: Int, assignedCount: Option[Int], createdByCount: Option[Int],
openCount: Int, closedCount: Int, allCount: Int, assignedCount: Option[Int], createdByCount: Option[Int], labelCounts: Map[String, Int],
condition: service.IssuesService.IssueSearchCondition, filter: String,
repository: service.RepositoryService.RepositoryInfo, isWritable: Boolean)(implicit context: app.Context)
@import context._
@@ -57,7 +57,7 @@
<li>
<a href="@condition.copy(labels = (if(condition.labels.contains(label.labelName)) condition.labels - label.labelName else condition.labels + label.labelName)).toURL"
@if(condition.labels.contains(label.labelName)){style="background-color: #@label.color; color: #@label.fontColor;"}>
<span class="count-right">0</span>
<span class="count-right">@labelCounts.getOrElse(label.labelName, 0)</span>
<span style="background-color: #@label.color;" class="label-color">&nbsp;&nbsp;</span>
@label.labelName
</a>