diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-07 16:51:14 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-07 16:51:14 -0400 |
commit | 33d32585b1b7232c764e8cb8629a33076902c882 (patch) | |
tree | 4450575c9a0a71c8a7d51e9b4eafee321226d8c2 /routers/user | |
parent | 6fb7229beaadb53f59cb85d80976f99708a7434d (diff) | |
download | gitea-33d32585b1b7232c764e8cb8629a33076902c882.tar.gz gitea-33d32585b1b7232c764e8cb8629a33076902c882.zip |
Add mention, read/unread support of issue tracker
Diffstat (limited to 'routers/user')
-rw-r--r-- | routers/user/home.go | 123 |
1 files changed, 58 insertions, 65 deletions
diff --git a/routers/user/home.go b/routers/user/home.go index 588cb8e3b0..11ac1a8126 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -13,6 +13,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" ) @@ -127,102 +128,94 @@ func Issues(ctx *middleware.Context) { } _, _ = assigneeId, posterId - // page, _ := base.StrTo(ctx.Query("page")).Int() - // repoId, _ := base.StrTo(ctx.Query("repoid")).Int64() - - // ctx.Data["RepoId"] = repoId - - // var posterId int64 = 0 - // if ctx.Query("type") == "created_by" { - // posterId = ctx.User.Id - // ctx.Data["ViewType"] = "created_by" - // } - rid, _ := base.StrTo(ctx.Query("repoid")).Int64() issueStats := models.GetUserIssueStats(ctx.User.Id, filterMode) // Get all repositories. repos, err := models.GetRepositories(ctx.User, true) if err != nil { - ctx.Handle(500, "user.Issues(get repositories)", err) + ctx.Handle(500, "user.Issues(GetRepositories)", err) return } + rids := make([]int64, 0, len(repos)) showRepos := make([]*models.Repository, 0, len(repos)) - - // Get all issues. - // allIssues := make([]models.Issue, 0, 5*len(repos)) for _, repo := range repos { if repo.NumIssues == 0 { continue } + rids = append(rids, repo.Id) repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues issueStats.AllCount += int64(repo.NumOpenIssues) - // switch filterMode{ - // case models.FM_ASSIGN: - - // } - if isShowClosed { if repo.NumClosedIssues > 0 { + if filterMode == models.FM_CREATE { + repo.NumClosedIssues = int(models.GetIssueCountByPoster(ctx.User.Id, repo.Id, isShowClosed)) + } showRepos = append(showRepos, repo) } } else { if repo.NumOpenIssues > 0 { + if filterMode == models.FM_CREATE { + repo.NumOpenIssues = int(models.GetIssueCountByPoster(ctx.User.Id, repo.Id, isShowClosed)) + } showRepos = append(showRepos, repo) } } + } - // issues, err := models.GetIssues(0, repo.Id, posterId, 0, page, isShowClosed, "", "") - // if err != nil { - // ctx.Handle(200, "user.Issues(get issues)", err) - // return - // } - } - - // allIssueCount += repo.NumIssues - // closedIssueCount += repo.NumClosedIssues - - // // Set repository information to issues. - // for j := range issues { - // issues[j].Repo = &repos[i] - // } - // allIssues = append(allIssues, issues...) - - // repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues - // if repos[i].NumOpenIssues > 0 { - // showRepos = append(showRepos, repos[i]) - // } - // } - - // showIssues := make([]models.Issue, 0, len(allIssues)) - // 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 repoId > 0 && repoId != allIssues[i].Repo.Id { - // continue - // } - - // if isShowClosed == allIssues[i].IsClosed { - // showIssues = append(showIssues, allIssues[i]) - // } - // } + if rid > 0 { + rids = []int64{rid} + } + + page, _ := base.StrTo(ctx.Query("page")).Int() + + // Get all issues. + var ius []*models.IssueUser + switch viewType { + case "assigned": + fallthrough + case "created_by": + ius, err = models.GetIssueUserPairsByMode(ctx.User.Id, rid, isShowClosed, page, filterMode) + default: + ius, err = models.GetIssueUserPairsByRepoIds(rids, isShowClosed, page) + } + if err != nil { + ctx.Handle(500, "user.Issues(GetAllIssueUserPairs)", err) + return + } + + issues := make([]*models.Issue, len(ius)) + for i := range ius { + issues[i], err = models.GetIssueById(ius[i].IssueId) + if err != nil { + if err == models.ErrIssueNotExist { + log.Error("user.Issues(#%d): issue not exist", ius[i].IssueId) + continue + } else { + ctx.Handle(500, "user.Issues(GetIssue)", err) + return + } + } + + issues[i].Repo, err = models.GetRepositoryById(issues[i].RepoId) + if err != nil { + ctx.Handle(500, "user.Issues(GetRepositoryById)", err) + return + } + + issues[i].Poster, err = models.GetUserById(issues[i].PosterId) + if err != nil { + ctx.Handle(500, "user.Issues(GetUserById)", err) + return + } + } ctx.Data["RepoId"] = rid ctx.Data["Repos"] = showRepos + ctx.Data["Issues"] = issues ctx.Data["ViewType"] = viewType ctx.Data["IssueStats"] = issueStats ctx.Data["IsShowClosed"] = isShowClosed |