Add mention, read/unread support of issue tracker

This commit is contained in:
Unknown 2014-05-07 16:51:14 -04:00
parent 6fb7229bea
commit 33d32585b1
11 changed files with 354 additions and 200 deletions

View file

@ -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
if rid > 0 {
rids = []int64{rid}
}
// // Set repository information to issues.
// for j := range issues {
// issues[j].Repo = &repos[i]
// }
// allIssues = append(allIssues, issues...)
page, _ := base.StrTo(ctx.Query("page")).Int()
// repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
// if repos[i].NumOpenIssues > 0 {
// showRepos = append(showRepos, repos[i])
// }
// }
// 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
}
// showIssues := make([]models.Issue, 0, len(allIssues))
// ctx.Data["IsShowClosed"] = isShowClosed
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
}
}
// // 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++
// }
issues[i].Repo, err = models.GetRepositoryById(issues[i].RepoId)
if err != nil {
ctx.Handle(500, "user.Issues(GetRepositoryById)", err)
return
}
// if repoId > 0 && repoId != allIssues[i].Repo.Id {
// continue
// }
// if isShowClosed == allIssues[i].IsClosed {
// showIssues = append(showIssues, allIssues[i])
// }
// }
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