Skip to content

Commit

Permalink
Fix dashboard issues labels filter bug (#14210) (#14214)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Jan 2, 2021
1 parent 17022f8 commit 7a0a133
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
34 changes: 22 additions & 12 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -1507,57 +1508,66 @@ 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))
if err != nil {
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))
Expand All @@ -1567,30 +1577,30 @@ 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))
if err != nil {
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))
if err != nil {
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 {
Expand Down
4 changes: 4 additions & 0 deletions routers/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 7a0a133

Please sign in to comment.