mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
Issue time estimate, meaningful time tracking (#23113)
Redesign the time tracker side bar, and add "time estimate" support (in "1d 2m" format) Closes #23112 --------- Co-authored-by: stuzer05 <stuzer05@gmail.com> Co-authored-by: Yarden Shoham <hrsi88@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ package repo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
)
|
||||
|
||||
// AddTimeManually tracks time manually
|
||||
@@ -26,19 +28,16 @@ func AddTimeManually(c *context.Context) {
|
||||
c.NotFound("CanUseTimetracker", nil)
|
||||
return
|
||||
}
|
||||
url := issue.Link()
|
||||
|
||||
if c.HasError() {
|
||||
c.Flash.Error(c.GetErrMsg())
|
||||
c.Redirect(url)
|
||||
c.JSONError(c.GetErrMsg())
|
||||
return
|
||||
}
|
||||
|
||||
total := time.Duration(form.Hours)*time.Hour + time.Duration(form.Minutes)*time.Minute
|
||||
|
||||
if total <= 0 {
|
||||
c.Flash.Error(c.Tr("repo.issues.add_time_sum_to_small"))
|
||||
c.Redirect(url, http.StatusSeeOther)
|
||||
c.JSONError(c.Tr("repo.issues.add_time_sum_to_small"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -47,7 +46,7 @@ func AddTimeManually(c *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.Redirect(url, http.StatusSeeOther)
|
||||
c.JSONRedirect("")
|
||||
}
|
||||
|
||||
// DeleteTime deletes tracked time
|
||||
@@ -83,5 +82,38 @@ func DeleteTime(c *context.Context) {
|
||||
}
|
||||
|
||||
c.Flash.Success(c.Tr("repo.issues.del_time_history", util.SecToTime(t.Time)))
|
||||
c.Redirect(issue.Link())
|
||||
c.JSONRedirect("")
|
||||
}
|
||||
|
||||
func UpdateIssueTimeEstimate(ctx *context.Context) {
|
||||
issue := GetActionIssue(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.IsSigned || (!issue.IsPoster(ctx.Doer.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
timeStr := strings.TrimSpace(ctx.FormString("time_estimate"))
|
||||
|
||||
total, err := util.TimeEstimateParse(timeStr)
|
||||
if err != nil {
|
||||
ctx.JSONError(ctx.Tr("repo.issues.time_estimate_invalid"))
|
||||
return
|
||||
}
|
||||
|
||||
// No time changed
|
||||
if issue.TimeEstimate == total {
|
||||
ctx.JSONRedirect("")
|
||||
return
|
||||
}
|
||||
|
||||
if err := issue_service.ChangeTimeEstimate(ctx, issue, ctx.Doer, total); err != nil {
|
||||
ctx.ServerError("ChangeTimeEstimate", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSONRedirect("")
|
||||
}
|
||||
|
Reference in New Issue
Block a user