diff --git a/src/main/scala/app/IssuesController.scala b/src/main/scala/app/IssuesController.scala index 8408671..24f4b69 100644 --- a/src/main/scala/app/IssuesController.scala +++ b/src/main/scala/app/IssuesController.scala @@ -91,6 +91,8 @@ issues.html.issues(searchIssue(owner, repository, condition, filter, userName), getLabels(owner, repository), getMilestones(owner, repository).filter(_.closedDate.isEmpty), + countIssue(owner, repository, condition.copy(state = "open"), filter, userName), + countIssue(owner, repository, condition.copy(state = "closed"), filter, userName), condition, filter, repositoryInfo, isWritable(owner, repository, context.loginAccount)) } getOrElse NotFound diff --git a/src/main/scala/service/IssuesService.scala b/src/main/scala/service/IssuesService.scala index 8eb07c6..1bec5d7 100644 --- a/src/main/scala/service/IssuesService.scala +++ b/src/main/scala/service/IssuesService.scala @@ -28,16 +28,31 @@ (t.issueId is issueId.bind) } list + /** + * Returns the count of the search result against issues. + * + * @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 count of the search result + */ + 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 search result against issues. + * + * @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 count of the search result + */ def searchIssue(owner: String, repository: String, condition: IssueSearchCondition, filter: String, userName: Option[String]) = - Query(Issues) filter { t => - (t.userName is owner.bind) && - (t.repositoryName is repository.bind) && - (t.closed is (condition.state == "closed").bind) && - (t.milestoneId is condition.milestoneId.get.bind, condition.milestoneId.isDefined) && - //if(condition.labels.nonEmpty) Some(Query(Issue)) else None, - (t.assignedUserName is userName.get.bind, filter == "assigned") && - (t.openedUserName is userName.get.bind, filter == "created_by") - } sortBy { t => + searchIssueQuery(owner, repository, condition, filter, userName).sortBy { t => (condition.sort match { case "created" => t.registeredDate case "comments" => t.updatedDate @@ -50,6 +65,20 @@ } } list + /** + * Assembles query for conditional issue searching. + */ + private def searchIssueQuery(owner: String, repository: String, condition: IssueSearchCondition, filter: String, userName: Option[String]) = + Query(Issues) filter { t => + (t.userName is owner.bind) && + (t.repositoryName is repository.bind) && + (t.closed is (condition.state == "closed").bind) && + (t.milestoneId is condition.milestoneId.get.bind, condition.milestoneId.isDefined) && + //if(condition.labels.nonEmpty) Some(Query(Issue)) else None, + (t.assignedUserName is userName.get.bind, filter == "assigned") && + (t.openedUserName is userName.get.bind, filter == "created_by") + } + def saveIssue(owner: String, repository: String, loginUser: String, title: String, content: Option[String]) = // next id number diff --git a/src/main/twirl/issues/issues.scala.html b/src/main/twirl/issues/issues.scala.html index f130e6c..398d6f6 100644 --- a/src/main/twirl/issues/issues.scala.html +++ b/src/main/twirl/issues/issues.scala.html @@ -1,4 +1,5 @@ @(issues: List[model.Issue], labels: List[model.Label], milestones: List[model.Milestone], + openCount: Int, closedCount: Int, condition: service.IssuesService.IssueSearchCondition, filter: String, repository: service.RepositoryService.RepositoryInfo, isWritable: Boolean)(implicit context: app.Context) @import context._ @@ -91,8 +92,8 @@