Add comment count sorting and displaying.

This commit is contained in:
takezoe
2013-06-27 03:42:17 +09:00
parent 333c4f08d4
commit 2c9ed60dbb
2 changed files with 54 additions and 14 deletions

View File

@@ -95,22 +95,53 @@ trait IssuesService {
* @param userName the filter user name required for "assigned" and "created_by" * @param userName the filter user name required for "assigned" and "created_by"
* @param offset the offset for pagination * @param offset the offset for pagination
* @param limit the limit for pagination * @param limit the limit for pagination
* @return the count of the search result * @return the search result (list of tuples which contain issue, labels and comment count)
*/ */
def searchIssue(owner: String, repository: String, condition: IssueSearchCondition, def searchIssue(owner: String, repository: String, condition: IssueSearchCondition,
filter: String, userName: Option[String], offset: Int, limit: Int): List[Issue] = filter: String, userName: Option[String], offset: Int, limit: Int): List[(Issue, List[Label], Int)] = {
searchIssueQuery(owner, repository, condition, filter, userName).sortBy { t =>
(condition.sort match { // get issues and comment count
case "created" => t.registeredDate val issues = searchIssueQuery(owner, repository, condition, filter, userName)
case "comments" => t.updatedDate .leftJoin(Query(IssueComments)
case "updated" => t.updatedDate .filter { t => (t.userName is owner.bind) && (t.repositoryName is repository.bind) }
}) match { .groupBy { _.issueId }
case sort => condition.direction match { .map { case (issueId, t) => issueId ~ t.length }).on((t1, t2) => t1.issueId is t2._1)
case "asc" => sort asc .sortBy { case (t1, t2) =>
case "desc" => sort desc (condition.sort match {
case "created" => t1.registeredDate
case "comments" => t2._2
case "updated" => t1.updatedDate
}) match {
case sort => condition.direction match {
case "asc" => sort asc
case "desc" => sort desc
}
} }
} }
} drop(offset) take(limit) list .map { case (t1, t2) => (t1, t2._2.ifNull(0)) }
.drop(offset).take(limit)
.list
// get labels
val labels = Query(IssueLabels)
.innerJoin(Labels).on { (t1, t2) =>
(t1.userName is t2.userName) &&
(t1.repositoryName is t2.repositoryName) &&
(t1.labelId is t2.labelId)
}
.filter { case (t1, t2) =>
(t1.userName is owner.bind) &&
(t1.repositoryName is repository.bind) &&
(t1.issueId inSetBind (issues.map(_._1.issueId)))
}
.sortBy { case (t1, t2) => t1.issueId ~ t2.labelName }
.map { case (t1, t2) => (t1.issueId, t2) }
.list
issues.map { case (issue, commentCount) =>
(issue, labels.collect { case (issueId, labels) if(issueId == issue.issueId) => labels }, commentCount)
}
}
/** /**
* Assembles query for conditional issue searching. * Assembles query for conditional issue searching.

View File

@@ -1,4 +1,4 @@
@(issues: List[model.Issue], page: Int, labels: List[model.Label], milestones: List[model.Milestone], @(issues: List[(model.Issue, List[model.Label], Int)], page: Int, labels: List[model.Label], milestones: List[model.Milestone],
openCount: Int, closedCount: Int, allCount: Int, assignedCount: Option[Int], createdByCount: Option[Int], labelCounts: Map[String, Int], openCount: Int, closedCount: Int, allCount: Int, assignedCount: Option[Int], createdByCount: Option[Int], labelCounts: Map[String, Int],
condition: service.IssuesService.IssueSearchCondition, filter: String, condition: service.IssuesService.IssueSearchCondition, filter: String,
repository: service.RepositoryService.RepositoryInfo, isWritable: Boolean)(implicit context: app.Context) repository: service.RepositoryService.RepositoryInfo, isWritable: Boolean)(implicit context: app.Context)
@@ -118,13 +118,22 @@
</ul> </ul>
</div> </div>
<table class="table table-bordered table-hover table-issues"> <table class="table table-bordered table-hover table-issues">
@issues.map { issue => @issues.map { case (issue, labels, commentCount) =>
<tr> <tr>
<td> <td>
<a href="@path/@repository.owner/@repository.name/issues/@issue.issueId" class="issue-title">@issue.title</a> <a href="@path/@repository.owner/@repository.name/issues/@issue.issueId" class="issue-title">@issue.title</a>
@labels.map { label =>
<span class="label-color" style="background-color: #@label.color; color: #@label.fontColor;">@label.labelName</span>
}
<span class="pull-right muted">#@issue.issueId</span> <span class="pull-right muted">#@issue.issueId</span>
<div class="small muted"> <div class="small muted">
Opened by <a href="@path/@repository.owner" class="username">@issue.openedUserName</a> @datetime(issue.registeredDate) Opened by <a href="@path/@repository.owner" class="username">@issue.openedUserName</a> @datetime(issue.registeredDate)
@if(commentCount == 1){
<i class="icon-comment"></i> 1 comment
}
@if(commentCount > 1){
<i class="icon-comment"></i> @commentCount comments
}
</div> </div>
</td> </td>
</tr> </tr>