summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-01-03 01:08:04 +0800
committerGitHub <noreply@github.com>2021-01-02 18:08:04 +0100
commit7a0a133d7c8f286d9f7d24ff1ed59428fa738de1 (patch)
tree0ae5875aa9c3819c47af45e5a7e3908c01b56166
parent17022f8b62a7a72812b62cfabfef1d101dd3bab3 (diff)
downloadgitea-7a0a133d7c8f286d9f7d24ff1ed59428fa738de1.tar.gz
gitea-7a0a133d7c8f286d9f7d24ff1ed59428fa738de1.zip
Fix dashboard issues labels filter bug (#14210) (#14214)
-rw-r--r--models/issue.go34
-rw-r--r--routers/user/home.go4
2 files changed, 26 insertions, 12 deletions
diff --git a/models/issue.go b/models/issue.go
index ee75623f53..9f7b9787eb 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -1491,6 +1491,7 @@ type UserIssueStatsOptions struct {
IsPull bool
IsClosed bool
IssueIDs []int64
+ LabelIDs []int64
}
// GetUserIssueStats returns issue statistic information for dashboard by given conditions.
@@ -1507,29 +1508,38 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
cond = cond.And(builder.In("issue.id", opts.IssueIDs))
}
+ sess := func(cond builder.Cond) *xorm.Session {
+ s := x.Where(cond)
+ if len(opts.LabelIDs) > 0 {
+ s.Join("INNER", "issue_label", "issue_label.issue_id = issue.id").
+ In("issue_label.label_id", opts.LabelIDs)
+ }
+ return s
+ }
+
switch opts.FilterMode {
case FilterModeAll:
- stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
+ stats.OpenCount, err = sess(cond).And("issue.is_closed = ?", false).
And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue))
if err != nil {
return nil, err
}
- stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
+ stats.ClosedCount, err = sess(cond).And("issue.is_closed = ?", true).
And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue))
if err != nil {
return nil, err
}
case FilterModeAssign:
- stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
+ stats.OpenCount, err = sess(cond).And("issue.is_closed = ?", false).
Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
And("issue_assignees.assignee_id = ?", opts.UserID).
Count(new(Issue))
if err != nil {
return nil, err
}
- stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
+ stats.ClosedCount, err = sess(cond).And("issue.is_closed = ?", true).
Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
And("issue_assignees.assignee_id = ?", opts.UserID).
Count(new(Issue))
@@ -1537,27 +1547,27 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
return nil, err
}
case FilterModeCreate:
- stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
+ stats.OpenCount, err = sess(cond).And("issue.is_closed = ?", false).
And("issue.poster_id = ?", opts.UserID).
Count(new(Issue))
if err != nil {
return nil, err
}
- stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
+ stats.ClosedCount, err = sess(cond).And("issue.is_closed = ?", true).
And("issue.poster_id = ?", opts.UserID).
Count(new(Issue))
if err != nil {
return nil, err
}
case FilterModeMention:
- stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
+ stats.OpenCount, err = sess(cond).And("issue.is_closed = ?", false).
Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true).
And("issue_user.uid = ?", opts.UserID).
Count(new(Issue))
if err != nil {
return nil, err
}
- stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
+ stats.ClosedCount, err = sess(cond).And("issue.is_closed = ?", true).
Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true).
And("issue_user.uid = ?", opts.UserID).
Count(new(Issue))
@@ -1567,7 +1577,7 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
}
cond = cond.And(builder.Eq{"issue.is_closed": opts.IsClosed})
- stats.AssignCount, err = x.Where(cond).
+ stats.AssignCount, err = sess(cond).
Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
And("issue_assignees.assignee_id = ?", opts.UserID).
Count(new(Issue))
@@ -1575,14 +1585,14 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
return nil, err
}
- stats.CreateCount, err = x.Where(cond).
+ stats.CreateCount, err = sess(cond).
And("poster_id = ?", opts.UserID).
Count(new(Issue))
if err != nil {
return nil, err
}
- stats.MentionCount, err = x.Where(cond).
+ stats.MentionCount, err = sess(cond).
Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true).
And("issue_user.uid = ?", opts.UserID).
Count(new(Issue))
@@ -1590,7 +1600,7 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
return nil, err
}
- stats.YourRepositoriesCount, err = x.Where(cond).
+ stats.YourRepositoriesCount, err = sess(cond).
And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue))
if err != nil {
diff --git a/routers/user/home.go b/routers/user/home.go
index f7f1786b33..d6b4825adf 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -567,6 +567,7 @@ func Issues(ctx *context.Context) {
FilterMode: filterMode,
IsPull: isPullList,
IsClosed: isShowClosed,
+ LabelIDs: opts.LabelIDs,
}
if len(repoIDs) > 0 {
userIssueStatsOpts.UserRepoIDs = repoIDs
@@ -586,6 +587,7 @@ func Issues(ctx *context.Context) {
IsPull: isPullList,
IsClosed: isShowClosed,
IssueIDs: issueIDsFromSearch,
+ LabelIDs: opts.LabelIDs,
}
if len(repoIDs) > 0 {
statsOpts.RepoIDs = repoIDs
@@ -608,6 +610,7 @@ func Issues(ctx *context.Context) {
IsPull: isPullList,
IsClosed: isShowClosed,
IssueIDs: issueIDsFromSearch,
+ LabelIDs: opts.LabelIDs,
})
if err != nil {
ctx.ServerError("GetUserIssueStats All", err)
@@ -659,6 +662,7 @@ func Issues(ctx *context.Context) {
ctx.Data["RepoIDs"] = repoIDs
ctx.Data["IsShowClosed"] = isShowClosed
ctx.Data["TotalIssueCount"] = totalIssues
+ ctx.Data["SelectLabels"] = selectLabels
if isShowClosed {
ctx.Data["State"] = "closed"