diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-14 22:15:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-14 22:15:18 +0800 |
commit | 7a9a5c8a69c2a3ba107a4dbc199f052d58262033 (patch) | |
tree | a6940099182c4427ff010fc2368aeabb67b57ff6 /models/issue.go | |
parent | 3a91ac51a93aa6e352896048ce37c01227b42055 (diff) | |
download | gitea-7a9a5c8a69c2a3ba107a4dbc199f052d58262033.tar.gz gitea-7a9a5c8a69c2a3ba107a4dbc199f052d58262033.zip |
Fix assigned issues dashboard (#920)
* Fix assigned/created issues in dashboard. (#3560)
* Fix assigned/created issues in dashboard.
* Use GetUserIssueStats for getting all Dashboard stats.
* Use gofmt to format the file properly.
* Replace &Issue{} with new(Issue).
* Check if user has access to given repository.
* Remove unnecessary filtering of issues.
* Return 404 error if invalid repository is given.
* Use correct number of issues in paginater.
* fix issues on dashboard
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 89 |
1 files changed, 61 insertions, 28 deletions
diff --git a/models/issue.go b/models/issue.go index 30a6cf8a4c..3ae34009bf 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1184,7 +1184,7 @@ func UpdateIssueMentions(e Engine, issueID int64, mentions []string) error { // IssueStats represents issue statistic information. type IssueStats struct { OpenCount, ClosedCount int64 - AllCount int64 + YourRepositoriesCount int64 AssignCount int64 CreateCount int64 MentionCount int64 @@ -1210,6 +1210,7 @@ func parseCountResult(results []map[string][]byte) int64 { // IssueStatsOptions contains parameters accepted by GetIssueStats. type IssueStatsOptions struct { + FilterMode int RepoID int64 Labels string MilestoneID int64 @@ -1265,19 +1266,41 @@ func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) { } var err error - stats.OpenCount, err = countSession(opts). - And("is_closed = ?", false). - Count(&Issue{}) - if err != nil { - return nil, err - } - stats.ClosedCount, err = countSession(opts). - And("is_closed = ?", true). - Count(&Issue{}) - if err != nil { - return nil, err + switch opts.FilterMode { + case FilterModeAll, FilterModeAssign: + stats.OpenCount, err = countSession(opts). + And("is_closed = ?", false). + Count(new(Issue)) + + stats.ClosedCount, err = countSession(opts). + And("is_closed = ?", true). + Count(new(Issue)) + case FilterModeCreate: + stats.OpenCount, err = countSession(opts). + And("poster_id = ?", opts.PosterID). + And("is_closed = ?", false). + Count(new(Issue)) + + stats.ClosedCount, err = countSession(opts). + And("poster_id = ?", opts.PosterID). + And("is_closed = ?", true). + Count(new(Issue)) + case FilterModeMention: + stats.OpenCount, err = countSession(opts). + Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). + And("issue_user.uid = ?", opts.PosterID). + And("issue_user.is_mentioned = ?", true). + And("issue.is_closed = ?", false). + Count(new(Issue)) + + stats.ClosedCount, err = countSession(opts). + Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). + And("issue_user.uid = ?", opts.PosterID). + And("issue_user.is_mentioned = ?", true). + And("issue.is_closed = ?", true). + Count(new(Issue)) } - return stats, nil + return stats, err } // GetUserIssueStats returns issue statistic information for dashboard by given conditions. @@ -1298,29 +1321,39 @@ func GetUserIssueStats(repoID, uid int64, repoIDs []int64, filterMode int, isPul return sess } - stats.AssignCount, _ = countSession(false, isPull, repoID, repoIDs). + stats.AssignCount, _ = countSession(false, isPull, repoID, nil). And("assignee_id = ?", uid). - Count(&Issue{}) + Count(new(Issue)) - stats.CreateCount, _ = countSession(false, isPull, repoID, repoIDs). + stats.CreateCount, _ = countSession(false, isPull, repoID, nil). And("poster_id = ?", uid). - Count(&Issue{}) + Count(new(Issue)) - openCountSession := countSession(false, isPull, repoID, repoIDs) - closedCountSession := countSession(true, isPull, repoID, repoIDs) + stats.YourRepositoriesCount, _ = countSession(false, isPull, repoID, repoIDs). + Count(new(Issue)) switch filterMode { + case FilterModeAll: + stats.OpenCount, _ = countSession(false, isPull, repoID, repoIDs). + Count(new(Issue)) + stats.ClosedCount, _ = countSession(true, isPull, repoID, repoIDs). + Count(new(Issue)) case FilterModeAssign: - openCountSession.And("assignee_id = ?", uid) - closedCountSession.And("assignee_id = ?", uid) + stats.OpenCount, _ = countSession(false, isPull, repoID, nil). + And("assignee_id = ?", uid). + Count(new(Issue)) + stats.ClosedCount, _ = countSession(true, isPull, repoID, nil). + And("assignee_id = ?", uid). + Count(new(Issue)) case FilterModeCreate: - openCountSession.And("poster_id = ?", uid) - closedCountSession.And("poster_id = ?", uid) + stats.OpenCount, _ = countSession(false, isPull, repoID, nil). + And("poster_id = ?", uid). + Count(new(Issue)) + stats.ClosedCount, _ = countSession(true, isPull, repoID, nil). + And("poster_id = ?", uid). + Count(new(Issue)) } - stats.OpenCount, _ = openCountSession.Count(&Issue{}) - stats.ClosedCount, _ = closedCountSession.Count(&Issue{}) - return stats } @@ -1347,8 +1380,8 @@ func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen closedCountSession.And("poster_id = ?", uid) } - openResult, _ := openCountSession.Count(&Issue{}) - closedResult, _ := closedCountSession.Count(&Issue{}) + openResult, _ := openCountSession.Count(new(Issue)) + closedResult, _ := closedCountSession.Count(new(Issue)) return openResult, closedResult } |