summaryrefslogtreecommitdiffstats
path: root/models/issue_list.go
diff options
context:
space:
mode:
authorJonas Franz <info@jonasfranz.software>2018-04-29 07:58:47 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2018-04-29 13:58:47 +0800
commit8d5f58d8347196fca04fdf3a22d021d09d15e37f (patch)
tree4db9aabfec9a274b945dc3835d261c3267440ee3 /models/issue_list.go
parente3028d124f864b0ed2563cd0fea8b24612eb64bb (diff)
downloadgitea-8d5f58d8347196fca04fdf3a22d021d09d15e37f.tar.gz
gitea-8d5f58d8347196fca04fdf3a22d021d09d15e37f.zip
Shows total tracked time in issue and milestone list (#3341)
* Show total tracked time in issue and milestone list Show total tracked time at issue page Signed-off-by: Jonas Franz <info@jonasfranz.software> * Optimizing TotalTimes by using SumInt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixing wrong total times for milestones caused by a missing JOIN Adding unit tests for total times Signed-off-by: Jonas Franz <info@jonasfranz.software> * Logging error instead of ignoring it Signed-off-by: Jonas Franz <info@jonasfranz.software> * Correcting spelling mistakes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change error message to a short version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add error handling to TotalTimes Add variable for totalTimes Signed-off-by: Jonas Franz <info@jonasfranz.de> * Introduce TotalTrackedTimes as variable of issue Load TotalTrackedTimes by loading attributes of IssueList Load TotalTrackedTimes by loading attributes of single issue Add Sec2Time as helper to use it in templates Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixed test + gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Load TotalTrackedTimes via MilestoneList instead of single requests Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change comment from SQL query to description Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if timetracker is enabled Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by enabling timetracking Signed-off-by: Jonas Franz <info@jonasfranz.de>
Diffstat (limited to 'models/issue_list.go')
-rw-r--r--models/issue_list.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/models/issue_list.go b/models/issue_list.go
index 4910915cd0..01a1a15f44 100644
--- a/models/issue_list.go
+++ b/models/issue_list.go
@@ -290,6 +290,50 @@ func (issues IssueList) loadComments(e Engine) (err error) {
return nil
}
+func (issues IssueList) loadTotalTrackedTimes(e Engine) (err error) {
+ type totalTimesByIssue struct {
+ IssueID int64
+ Time int64
+ }
+ if len(issues) == 0 {
+ return nil
+ }
+ var trackedTimes = make(map[int64]int64, len(issues))
+
+ var ids = make([]int64, 0, len(issues))
+ for _, issue := range issues {
+ if issue.Repo.IsTimetrackerEnabled() {
+ ids = append(ids, issue.ID)
+ }
+ }
+
+ // select issue_id, sum(time) from tracked_time where issue_id in (<issue ids in current page>) group by issue_id
+ rows, err := e.Table("tracked_time").
+ Select("issue_id, sum(time) as time").
+ In("issue_id", ids).
+ GroupBy("issue_id").
+ Rows(new(totalTimesByIssue))
+ if err != nil {
+ return err
+ }
+
+ defer rows.Close()
+
+ for rows.Next() {
+ var totalTime totalTimesByIssue
+ err = rows.Scan(&totalTime)
+ if err != nil {
+ return err
+ }
+ trackedTimes[totalTime.IssueID] = totalTime.Time
+ }
+
+ for _, issue := range issues {
+ issue.TotalTrackedTime = trackedTimes[issue.ID]
+ }
+ return nil
+}
+
// loadAttributes loads all attributes, expect for attachments and comments
func (issues IssueList) loadAttributes(e Engine) (err error) {
if _, err = issues.loadRepositories(e); err != nil {
@@ -316,6 +360,10 @@ func (issues IssueList) loadAttributes(e Engine) (err error) {
return
}
+ if err = issues.loadTotalTrackedTimes(e); err != nil {
+ return
+ }
+
return nil
}