diff --git a/models/issue.go b/models/issue.go index b05667c3a..b30676e94 100644 --- a/models/issue.go +++ b/models/issue.go @@ -136,6 +136,12 @@ func GetIssues(userId, repoId, posterId, milestoneId int64, page int, isClosed, return issues, err } +// GetUserIssueCount returns the number of issues that were created by given user in repository. +func GetUserIssueCount(userId, repoId int64) int64 { + count, _ := orm.Where("poster_id=?", userId).And("repo_id=?", repoId).Count(new(Issue)) + return count +} + // UpdateIssue updates information of issue. func UpdateIssue(issue *Issue) error { _, err := orm.Id(issue.Id).AllCols().Update(issue) diff --git a/models/repo.go b/models/repo.go index e6d4639b0..43d4aa739 100644 --- a/models/repo.go +++ b/models/repo.go @@ -84,6 +84,7 @@ type Repository struct { NumForks int NumIssues int NumClosedIssues int + NumOpenIssues int `xorm:"-"` IsPrivate bool IsBare bool Created time.Time `xorm:"created"` diff --git a/routers/repo/issue.go b/routers/repo/issue.go index effb1fab3..23571e759 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -21,13 +21,21 @@ func Issues(ctx *middleware.Context) { ctx.Data["Title"] = "Issues" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true + ctx.Data["ViewType"] = "all" milestoneId, _ := base.StrTo(ctx.Query("milestone")).Int() page, _ := base.StrTo(ctx.Query("page")).Int() + var posterId int64 = 0 + if ctx.Query("type") == "created_by" { + posterId = ctx.User.Id + ctx.Data["ViewType"] = "created_by" + } + ctx.Data["IssueCreatedCount"] = models.GetUserIssueCount(ctx.User.Id, ctx.Repo.Repository.Id) + // Get issues. - issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, 0, - int64(milestoneId), page, ctx.Query("state") == "closed", false, ctx.Query("labels"), ctx.Query("sortType")) + issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, posterId, int64(milestoneId), page, + ctx.Query("state") == "closed", false, ctx.Query("labels"), ctx.Query("sortType")) if err != nil { ctx.Handle(200, "issue.Issues: %v", err) return diff --git a/routers/user/user.go b/routers/user/user.go index d3ef96211..052a27749 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -286,6 +286,66 @@ func Feeds(ctx *middleware.Context, form auth.FeedsForm) { func Issues(ctx *middleware.Context) { ctx.Data["Title"] = "Your Issues" + ctx.Data["ViewType"] = "all" + + page, _ := base.StrTo(ctx.Query("page")).Int() + + var posterId int64 = 0 + if ctx.Query("type") == "created_by" { + posterId = ctx.User.Id + ctx.Data["ViewType"] = "created_by" + } + + // Get all repositories. + repos, err := models.GetRepositories(ctx.User) + if err != nil { + ctx.Handle(200, "user.Issues(get repository)", err) + return + } + + var closedIssueCount, createdByCount int + + // Get all issues. + allIssues := make([]models.Issue, 0, 5*len(repos)) + for i, repo := range repos { + issues, err := models.GetIssues(0, repo.Id, posterId, 0, page, false, false, "", "") + if err != nil { + ctx.Handle(200, "user.Issues(get issues)", err) + return + } + + closedIssueCount += repo.NumClosedIssues + repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues + allIssues = append(allIssues, issues...) + } + + showIssues := make([]models.Issue, 0, len(allIssues)) + isShowClosed := ctx.Query("state") == "closed" + ctx.Data["IsShowClosed"] = isShowClosed + + // Get posters and filter issues. + for i := range allIssues { + u, err := models.GetUserById(allIssues[i].PosterId) + if err != nil { + ctx.Handle(200, "user.Issues(get poster): %v", err) + return + } + allIssues[i].Poster = u + if u.Id == ctx.User.Id { + createdByCount++ + } + + if isShowClosed == allIssues[i].IsClosed { + showIssues = append(showIssues, allIssues[i]) + } + } + + ctx.Data["Repos"] = repos + ctx.Data["Issues"] = showIssues + ctx.Data["AllIssueCount"] = len(allIssues) + ctx.Data["ClosedIssueCount"] = closedIssueCount + ctx.Data["OpenIssueCount"] = len(allIssues) - closedIssueCount + ctx.Data["CreatedByCount"] = createdByCount ctx.HTML(200, "issue/user") } diff --git a/templates/install.tmpl b/templates/install.tmpl index b2ae3bac2..4fbef3cba 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -2,13 +2,12 @@
General settings for GoGits
+General Settings of Gogs
The user has access to visit and run GoGits.
+The user has access to visit and run Gogs.
Notification Settings