diff --git a/src/main/scala/app/DashboardController.scala b/src/main/scala/app/DashboardController.scala index 2728b5e..fcce6c0 100644 --- a/src/main/scala/app/DashboardController.scala +++ b/src/main/scala/app/DashboardController.scala @@ -4,11 +4,11 @@ import util.UsersAuthenticator class DashboardController extends DashboardControllerBase - with IssuesService with RepositoryService with AccountService + with IssuesService with PullRequestService with RepositoryService with AccountService with UsersAuthenticator trait DashboardControllerBase extends ControllerBase { - self: IssuesService with RepositoryService with UsersAuthenticator => + self: IssuesService with PullRequestService with RepositoryService with UsersAuthenticator => get("/dashboard/issues/repos")(usersOnly { searchIssues("all") @@ -22,6 +22,14 @@ searchIssues("created_by") }) + get("/dashboard/pulls")(usersOnly { + searchPullRequests("created_by") + }) + + get("/dashboard/pulls/public")(usersOnly { + searchPullRequests("all") + }) + private def searchIssues(filter: String) = { import IssuesService._ @@ -54,4 +62,36 @@ } + private def searchPullRequests(filter: String) = { + import IssuesService._ + import PullRequestService._ + + // condition + val sessionKey = "dashboard/pulls" + val condition = if(request.getQueryString == null) + session.get(sessionKey).getOrElse(IssueSearchCondition()).asInstanceOf[IssueSearchCondition] + else IssueSearchCondition(request) + + session.put(sessionKey, condition) + + val userName = context.loginAccount.get.userName + val repositories = getUserRepositories(userName, baseUrl).map(repo => repo.owner -> repo.name) + val filterUser = Map(filter -> userName) + val page = IssueSearchCondition.page(request) + + dashboard.html.pulls( + pulls.html.listparts( + searchIssue(condition, filterUser, true, (page - 1) * PullRequestLimit, PullRequestLimit, repositories: _*), + page, + countIssue(condition.copy(state = "open"), filterUser, false, repositories: _*), + countIssue(condition.copy(state = "closed"), filterUser, false, repositories: _*), + condition), + countIssue(condition, Map.empty, true, repositories: _*), + getPullRequestCount(condition.state == "closed", userName, None), + condition, + filter) + + } + + } diff --git a/src/main/scala/app/PullRequestsController.scala b/src/main/scala/app/PullRequestsController.scala index d361d44..efc3213 100644 --- a/src/main/scala/app/PullRequestsController.scala +++ b/src/main/scala/app/PullRequestsController.scala @@ -386,7 +386,7 @@ pulls.html.list( searchIssue(condition, filterUser, true, (page - 1) * PullRequestLimit, PullRequestLimit, owner -> repoName), - getPullRequestCount(condition.state == "closed", Some(owner, repoName)), + getPullRequestCount(condition.state == "closed", owner, Some(repoName)), userName, page, countIssue(condition.copy(state = "open"), filterUser, true, owner -> repoName), diff --git a/src/main/scala/service/PullRequestService.scala b/src/main/scala/service/PullRequestService.scala index ab28675..bc2cf52 100644 --- a/src/main/scala/service/PullRequestService.scala +++ b/src/main/scala/service/PullRequestService.scala @@ -18,13 +18,13 @@ } else None } - def getPullRequestCount(closed: Boolean, repository: Option[(String, String)]): List[PullRequestCount] = + def getPullRequestCount(closed: Boolean, owner: String, repository: Option[String]): List[PullRequestCount] = Query(PullRequests) .innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) } .filter { case (t1, t2) => (t2.closed is closed.bind) && - (t1.userName is repository.get._1, repository.isDefined) && - (t1.repositoryName is repository.get._2, repository.isDefined) + (t1.userName is owner.bind) && + (t1.repositoryName is repository.get.bind, repository.isDefined) } .groupBy { case (t1, t2) => t2.openedUserName } .map { case (userName, t) => userName ~ t.length } diff --git a/src/main/twirl/dashboard/pulls.scala.html b/src/main/twirl/dashboard/pulls.scala.html new file mode 100644 index 0000000..a2139c2 --- /dev/null +++ b/src/main/twirl/dashboard/pulls.scala.html @@ -0,0 +1,42 @@ +@(listparts: twirl.api.Html, + allCount: Int, + counts: List[service.PullRequestService.PullRequestCount], + condition: service.IssuesService.IssueSearchCondition, + filter: String)(implicit context: app.Context) +@import context._ +@import view.helpers._ +@html.main("Your Issues"){ +@dashboard.html.tab("pulls") +
+
+ +
+ +
+ @listparts +
+} diff --git a/src/main/twirl/dashboard/tab.scala.html b/src/main/twirl/dashboard/tab.scala.html index c2e42a5..21e4d06 100644 --- a/src/main/twirl/dashboard/tab.scala.html +++ b/src/main/twirl/dashboard/tab.scala.html @@ -3,6 +3,7 @@ diff --git a/src/main/twirl/pulls/list.scala.html b/src/main/twirl/pulls/list.scala.html index 079ad20..27ec623 100644 --- a/src/main/twirl/pulls/list.scala.html +++ b/src/main/twirl/pulls/list.scala.html @@ -44,98 +44,7 @@ } -
- @if(hasWritePermission){ -
- @helper.html.paginator(page, (if(condition.state == "open") openCount else closedCount), service.PullRequestService.PullRequestLimit, 7, condition.toURL) - New pull request -
- } -
- @openCount Open - @closedCount Closed -
-
- - -
- - @if(issues.isEmpty){ - - - - } - @issues.map { case (issue, labels, commentCount) => - - - - } -
- No pull requests to show. -
- - @issue.title - #@issue.issueId -
- @issue.content.map { content => - @cut(content, 90) - }.getOrElse { - No description available - } -
-
- @avatar(issue.openedUserName, 20) by @issue.openedUserName @datetime(issue.registeredDate)  - @if(commentCount > 0){ - @commentCount @plural(commentCount, "comment") - } -
-
-
- @helper.html.paginator(page, (if(condition.state == "open") openCount else closedCount), service.PullRequestService.PullRequestLimit, 10, condition.toURL) -
-
+ @listparts(issues, page, openCount, closedCount, condition) } diff --git a/src/main/twirl/pulls/listparts.scala.html b/src/main/twirl/pulls/listparts.scala.html new file mode 100644 index 0000000..e3dfac4 --- /dev/null +++ b/src/main/twirl/pulls/listparts.scala.html @@ -0,0 +1,101 @@ +@(issues: List[(model.Issue, List[model.Label], Int)], + page: Int, + openCount: Int, + closedCount: Int, + condition: service.IssuesService.IssueSearchCondition)(implicit context: app.Context) +@import context._ +@import view.helpers._ +
+ @* + @if(hasWritePermission){ +
+ @helper.html.paginator(page, (if(condition.state == "open") openCount else closedCount), service.PullRequestService.PullRequestLimit, 7, condition.toURL) + New pull request +
+ } + *@ +
+ @openCount Open + @closedCount Closed +
+
+ + +
+ + @if(issues.isEmpty){ + + + + } + @issues.map { case (issue, labels, commentCount) => + + + + } +
+ No pull requests to show. +
+ + @issue.title + #@issue.issueId +
+ @issue.content.map { content => + @cut(content, 90) + }.getOrElse { + No description available + } +
+
+ @avatar(issue.openedUserName, 20) by @issue.openedUserName @datetime(issue.registeredDate)  + @if(commentCount > 0){ + @commentCount @plural(commentCount, "comment") + } +
+
+
+ @helper.html.paginator(page, (if(condition.state == "open") openCount else closedCount), service.PullRequestService.PullRequestLimit, 10, condition.toURL) +
+
\ No newline at end of file