diff options
author | Gwyneth Morgan <gwymor@tilde.club> | 2024-01-15 07:07:22 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-15 15:07:22 +0000 |
commit | 2c3da59e275b69ebf984bb70954f42a7bcb0b49d (patch) | |
tree | 7c4f4eabdcee9cff60abace2e4c36a1484277ee0 /models | |
parent | 2d343f8987025015f5b61e328cc9e45082e6d3f2 (diff) | |
download | gitea-2c3da59e275b69ebf984bb70954f42a7bcb0b49d.tar.gz gitea-2c3da59e275b69ebf984bb70954f42a7bcb0b49d.zip |
Add ability to see open and closed issues at the same time (#28757)
By clicking the currently active "Open" or "Closed" filter button in the
issue list, the user can toggle that filter off in order to see all
issues regardless of state. The URL "state" parameter will be set to
"all" and the "Open"/"Closed" button will not show as active.
Diffstat (limited to 'models')
-rw-r--r-- | models/issues/tracked_time.go | 12 | ||||
-rw-r--r-- | models/issues/tracked_time_test.go | 9 |
2 files changed, 14 insertions, 7 deletions
diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go index 884a445d26..91c4832e49 100644 --- a/models/issues/tracked_time.go +++ b/models/issues/tracked_time.go @@ -340,7 +340,7 @@ func GetTrackedTimeByID(ctx context.Context, id int64) (*TrackedTime, error) { } // GetIssueTotalTrackedTime returns the total tracked time for issues by given conditions. -func GetIssueTotalTrackedTime(ctx context.Context, opts *IssuesOptions, isClosed bool) (int64, error) { +func GetIssueTotalTrackedTime(ctx context.Context, opts *IssuesOptions, isClosed util.OptionalBool) (int64, error) { if len(opts.IssueIDs) <= MaxQueryParameters { return getIssueTotalTrackedTimeChunk(ctx, opts, isClosed, opts.IssueIDs) } @@ -363,7 +363,7 @@ func GetIssueTotalTrackedTime(ctx context.Context, opts *IssuesOptions, isClosed return accum, nil } -func getIssueTotalTrackedTimeChunk(ctx context.Context, opts *IssuesOptions, isClosed bool, issueIDs []int64) (int64, error) { +func getIssueTotalTrackedTimeChunk(ctx context.Context, opts *IssuesOptions, isClosed util.OptionalBool, issueIDs []int64) (int64, error) { sumSession := func(opts *IssuesOptions, issueIDs []int64) *xorm.Session { sess := db.GetEngine(ctx). Table("tracked_time"). @@ -377,7 +377,9 @@ func getIssueTotalTrackedTimeChunk(ctx context.Context, opts *IssuesOptions, isC Time int64 } - return sumSession(opts, issueIDs). - And("issue.is_closed = ?", isClosed). - SumInt(new(trackedTime), "tracked_time.time") + session := sumSession(opts, issueIDs) + if !isClosed.IsNone() { + session = session.And("issue.is_closed = ?", isClosed.IsTrue()) + } + return session.SumInt(new(trackedTime), "tracked_time.time") } diff --git a/models/issues/tracked_time_test.go b/models/issues/tracked_time_test.go index 2774234e7b..9beb862ffb 100644 --- a/models/issues/tracked_time_test.go +++ b/models/issues/tracked_time_test.go @@ -11,6 +11,7 @@ import ( issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/util" "github.com/stretchr/testify/assert" ) @@ -119,11 +120,15 @@ func TestTotalTimesForEachUser(t *testing.T) { func TestGetIssueTotalTrackedTime(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - ttt, err := issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, false) + ttt, err := issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, util.OptionalBoolFalse) assert.NoError(t, err) assert.EqualValues(t, 3682, ttt) - ttt, err = issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, true) + ttt, err = issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, util.OptionalBoolTrue) assert.NoError(t, err) assert.EqualValues(t, 0, ttt) + + ttt, err = issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, util.OptionalBoolNone) + assert.NoError(t, err) + assert.EqualValues(t, 3682, ttt) } |