Fix dashboard issues labels filter bug (#14210)

Co-authored-by: zeripath <art27@cantab.net>
release/v1.15
Lunny Xiao 2021-01-02 01:49:42 +08:00 committed by GitHub
parent a07e67d9cc
commit 21adeaad70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 12 deletions

View File

@ -1500,6 +1500,7 @@ type UserIssueStatsOptions struct {
IsPull bool IsPull bool
IsClosed bool IsClosed bool
IssueIDs []int64 IssueIDs []int64
LabelIDs []int64
} }
// GetUserIssueStats returns issue statistic information for dashboard by given conditions. // GetUserIssueStats returns issue statistic information for dashboard by given conditions.
@ -1516,29 +1517,38 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
cond = cond.And(builder.In("issue.id", opts.IssueIDs)) 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 { switch opts.FilterMode {
case FilterModeAll: 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)). And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err 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)). And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
case FilterModeAssign: 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"). Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
And("issue_assignees.assignee_id = ?", opts.UserID). And("issue_assignees.assignee_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err 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"). Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
And("issue_assignees.assignee_id = ?", opts.UserID). And("issue_assignees.assignee_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
@ -1546,27 +1556,27 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
return nil, err return nil, err
} }
case FilterModeCreate: 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). And("issue.poster_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err 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). And("issue.poster_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err return nil, err
} }
case FilterModeMention: 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). Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true).
And("issue_user.uid = ?", opts.UserID). And("issue_user.uid = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err 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). Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true).
And("issue_user.uid = ?", opts.UserID). And("issue_user.uid = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
@ -1576,7 +1586,7 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
} }
cond = cond.And(builder.Eq{"issue.is_closed": opts.IsClosed}) 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"). Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
And("issue_assignees.assignee_id = ?", opts.UserID). And("issue_assignees.assignee_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
@ -1584,14 +1594,14 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
return nil, err return nil, err
} }
stats.CreateCount, err = x.Where(cond). stats.CreateCount, err = sess(cond).
And("poster_id = ?", opts.UserID). And("poster_id = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {
return nil, err 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). Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true).
And("issue_user.uid = ?", opts.UserID). And("issue_user.uid = ?", opts.UserID).
Count(new(Issue)) Count(new(Issue))
@ -1599,7 +1609,7 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
return nil, err return nil, err
} }
stats.YourRepositoriesCount, err = x.Where(cond). stats.YourRepositoriesCount, err = sess(cond).
And(builder.In("issue.repo_id", opts.UserRepoIDs)). And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue)) Count(new(Issue))
if err != nil { if err != nil {

View File

@ -580,6 +580,7 @@ func Issues(ctx *context.Context) {
FilterMode: filterMode, FilterMode: filterMode,
IsPull: isPullList, IsPull: isPullList,
IsClosed: isShowClosed, IsClosed: isShowClosed,
LabelIDs: opts.LabelIDs,
} }
if len(repoIDs) > 0 { if len(repoIDs) > 0 {
userIssueStatsOpts.UserRepoIDs = repoIDs userIssueStatsOpts.UserRepoIDs = repoIDs
@ -599,6 +600,7 @@ func Issues(ctx *context.Context) {
IsPull: isPullList, IsPull: isPullList,
IsClosed: isShowClosed, IsClosed: isShowClosed,
IssueIDs: issueIDsFromSearch, IssueIDs: issueIDsFromSearch,
LabelIDs: opts.LabelIDs,
} }
if len(repoIDs) > 0 { if len(repoIDs) > 0 {
statsOpts.RepoIDs = repoIDs statsOpts.RepoIDs = repoIDs
@ -621,6 +623,7 @@ func Issues(ctx *context.Context) {
IsPull: isPullList, IsPull: isPullList,
IsClosed: isShowClosed, IsClosed: isShowClosed,
IssueIDs: issueIDsFromSearch, IssueIDs: issueIDsFromSearch,
LabelIDs: opts.LabelIDs,
}) })
if err != nil { if err != nil {
ctx.ServerError("GetUserIssueStats All", err) ctx.ServerError("GetUserIssueStats All", err)
@ -672,6 +675,7 @@ func Issues(ctx *context.Context) {
ctx.Data["RepoIDs"] = repoIDs ctx.Data["RepoIDs"] = repoIDs
ctx.Data["IsShowClosed"] = isShowClosed ctx.Data["IsShowClosed"] = isShowClosed
ctx.Data["TotalIssueCount"] = totalIssues ctx.Data["TotalIssueCount"] = totalIssues
ctx.Data["SelectLabels"] = selectLabels
if isShowClosed { if isShowClosed {
ctx.Data["State"] = "closed" ctx.Data["State"] = "closed"