-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shows total tracked time in issue and milestone list #3341
Changes from 25 commits
72c4296
1c0201f
1875038
b849f54
fda4dd4
983c1e1
707f3db
26a1e02
67be8bd
f1cfe62
770fea4
3c8507a
c5c812c
e92cc12
8481f2d
4cac53e
79dc9d8
421cbfb
1077882
9bb7714
0143b50
2f6a6fd
2d13376
a87698b
ec0d41c
856087e
02dc1cf
9508985
0ba269b
70e9bbd
221a327
90658cc
ca5243c
d623780
6a97bf7
62f9962
2835f08
526f7db
e9562ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ type Milestone struct { | |
DeadlineString string `xorm:"-"` | ||
DeadlineUnix util.TimeStamp | ||
ClosedDateUnix util.TimeStamp | ||
|
||
TotalTrackedTime int64 `xorm:"-"` | ||
} | ||
|
||
// BeforeInsert is invoked from XORM before inserting an object of this type. | ||
|
@@ -123,14 +125,70 @@ func GetMilestoneByRepoID(repoID, id int64) (*Milestone, error) { | |
return getMilestoneByRepoID(x, repoID, id) | ||
} | ||
|
||
type MilestoneList []*Milestone | ||
|
||
func (milestones MilestoneList) loadTotalTrackedTimes(e Engine) error { | ||
type totalTimesByMilestone struct { | ||
MilestoneID int64 | ||
Time int64 | ||
} | ||
if len(milestones) == 0 { | ||
return nil | ||
} | ||
var trackedTimes = make(map[int64]int64, len(milestones)) | ||
|
||
// SELECT milestone_id, sum(time) as time FROM `issue` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should be removed |
||
// INNER JOIN `milestone` ON issue.milestone_id = milestone.id | ||
// LEFT JOIN `tracked_time` ON tracked_time.issue_id = issue.id | ||
// WHERE `milestone_id` IN (?) GROUP BY milestone_id | ||
rows, err := e.Table("issue"). | ||
Join("INNER", "milestone", "issue.milestone_id = milestone.id"). | ||
Join("LEFT", "tracked_time", "tracked_time.issue_id = issue.id"). | ||
Select("milestone_id, sum(time) as time"). | ||
In("milestone_id", milestones.getMilestoneIDs()). | ||
GroupBy("milestone_id"). | ||
Rows(new(totalTimesByMilestone)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer rows.Close() | ||
|
||
for rows.Next() { | ||
var totalTime totalTimesByMilestone | ||
err = rows.Scan(&totalTime) | ||
if err != nil { | ||
return err | ||
} | ||
trackedTimes[totalTime.MilestoneID] = totalTime.Time | ||
} | ||
|
||
for _, milestone := range milestones { | ||
milestone.TotalTrackedTime = trackedTimes[milestone.ID] | ||
} | ||
return nil | ||
} | ||
|
||
func (milestones MilestoneList) LoadTotalTrackedTimes() error { | ||
return milestones.loadTotalTrackedTimes(x) | ||
} | ||
|
||
func (milestones MilestoneList) getMilestoneIDs() []int64 { | ||
var ids = make([]int64, 0, len(milestones)) | ||
for _, ms := range milestones { | ||
ids = append(ids, ms.ID) | ||
} | ||
return ids | ||
} | ||
|
||
// GetMilestonesByRepoID returns all milestones of a repository. | ||
func GetMilestonesByRepoID(repoID int64) ([]*Milestone, error) { | ||
func GetMilestonesByRepoID(repoID int64) (MilestoneList, error) { | ||
miles := make([]*Milestone, 0, 10) | ||
return miles, x.Where("repo_id = ?", repoID).Find(&miles) | ||
} | ||
|
||
// GetMilestones returns a list of milestones of given repository and status. | ||
func GetMilestones(repoID int64, page int, isClosed bool, sortType string) ([]*Milestone, error) { | ||
func GetMilestones(repoID int64, page int, isClosed bool, sortType string) (MilestoneList, error) { | ||
miles := make([]*Milestone, 0, setting.UI.IssuePagingNum) | ||
sess := x.Where("repo_id = ? AND is_closed = ?", repoID, isClosed) | ||
if page > 0 { | ||
|
@@ -151,7 +209,6 @@ func GetMilestones(repoID int64, page int, isClosed bool, sortType string) ([]*M | |
default: | ||
sess.Asc("deadline_unix") | ||
} | ||
|
||
return miles, sess.Find(&miles) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ | |
<span class="issue-stats"> | ||
<i class="octicon octicon-issue-opened"></i> {{$.i18n.Tr "repo.issues.open_tab" .NumOpenIssues}} | ||
<i class="octicon octicon-issue-closed"></i> {{$.i18n.Tr "repo.issues.close_tab" .NumClosedIssues}} | ||
{{if .TotalTrackedTime}}<i class="octicon octicon-clock"></i> {{.TotalTrackedTime|Sec2Time}}{{end}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably also change to same as in issues.tmpl: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Than probably there also needs to be such check added so that it would behave same in both places: https://github.com/JonasFranzDEV/gitea/blob/d6237809c472de482cc31fb954af1a8fd6ef54b4/models/issue.go#L248 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lafriks Done |
||
</span> | ||
</div> | ||
{{if $.IsRepositoryWriter}} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If error is ignored than at least it should be logged