diff --git a/models/issue.go b/models/issue.go index b05667c3a8..b30676e940 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 e6d4639b02..43d4aa739f 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 effb1fab37..23571e759b 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 d3ef96211e..052a277498 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 b2ae3bac21..4fbef3cba0 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -2,13 +2,12 @@
{{.CsrfTokenHtml}} -

Install Steps For First Running

+

Install Steps For First-time Run

{{.ErrorMsg}}
-

GoGits need MySQL or PostgreSQL server

+

Gogs requires MySQL or PostgreSQL based on your choice

-
+
- +
-

Recommend use INNODB engine with utf8_general_ci charset.

+
- +
- -

Use SSL protocol to connect PostgreSQL.

+
@@ -74,15 +77,15 @@ -
+
-

General settings for GoGits

+

General Settings of Gogs

@@ -98,8 +101,7 @@
- -

The user has access to visit and run GoGits.

+

The user has access to visit and run Gogs.

@@ -125,7 +127,7 @@
- + @@ -163,20 +165,28 @@

Notification Settings

- - -
- +
+
+ +
-
- -
- +
+
+
+ +
+ diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl index b8947d9fc5..39a4af5691 100644 --- a/templates/issue/list.tmpl +++ b/templates/issue/list.tmpl @@ -6,9 +6,9 @@
diff --git a/templates/issue/user.tmpl b/templates/issue/user.tmpl index cf5e365dcf..edffde4f43 100644 --- a/templates/issue/user.tmpl +++ b/templates/issue/user.tmpl @@ -16,21 +16,20 @@