mirror of https://github.com/go-gitea/gitea.git
Signed-off-by: workjs1124 <kongjs123@gmail.com>
fix(issue): Replace stopwatch toggle with explicit start/stop actions The stopwatch toggle mechanism caused state desynchronization issues when used across multiple browser tabs, leading to a "stop" action incorrectly starting the timer again. This commit replaces the single toggle endpoint with two explicit endpoints: `/start` and `/stop`. This ensures that the user's intent is always clear and prevents unexpected behavior, resolving the state inconsistency bug.
This commit is contained in:
parent
618e2d8106
commit
d3785804cc
|
|
@ -1726,6 +1726,7 @@ issues.remove_time_estimate_at = removed time estimate %s
|
|||
issues.time_estimate_invalid = Time estimate format is invalid
|
||||
issues.start_tracking_history = started working %s
|
||||
issues.tracker_auto_close = Timer will be stopped automatically when this issue gets closed
|
||||
issues.tracker_already_stopped = The Timer for this issue is already stopped
|
||||
issues.tracking_already_started = `You have already started time tracking on <a href="%s">another issue</a>!`
|
||||
issues.stop_tracking = Stop Timer
|
||||
issues.stop_tracking_history = worked for <b>%[1]s</b> %[2]s
|
||||
|
|
|
|||
|
|
@ -10,31 +10,49 @@ import (
|
|||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
// IssueStopwatch creates or stops a stopwatch for the given issue.
|
||||
func IssueStopwatch(c *context.Context) {
|
||||
// IssueStartStopwatch creates a stopwatch for the given issue.
|
||||
func IssueStartStopwatch(c *context.Context) {
|
||||
issue := GetActionIssue(c)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
var showSuccessMessage bool
|
||||
|
||||
if !issues_model.StopwatchExists(c, c.Doer.ID, issue.ID) {
|
||||
showSuccessMessage = true
|
||||
}
|
||||
|
||||
if !c.Repo.CanUseTimetracker(c, issue, c.Doer) {
|
||||
c.NotFound(nil)
|
||||
return
|
||||
}
|
||||
|
||||
if err := issues_model.CreateOrStopIssueStopwatch(c, c.Doer, issue); err != nil {
|
||||
c.ServerError("CreateOrStopIssueStopwatch", err)
|
||||
if err := issues_model.CreateIssueStopwatch(c, c.Doer, issue); err != nil {
|
||||
c.ServerError("CreateIssueStopwatch", err)
|
||||
return
|
||||
}
|
||||
|
||||
if showSuccessMessage {
|
||||
c.Flash.Success(c.Tr("repo.issues.tracker_auto_close"))
|
||||
c.Flash.Success(c.Tr("repo.issues.tracker_auto_close"))
|
||||
|
||||
c.JSONRedirect("")
|
||||
}
|
||||
|
||||
// IssueStopStopwatch stops a stopwatch for the given issue.
|
||||
func IssueStopStopwatch(c *context.Context) {
|
||||
issue := GetActionIssue(c)
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.Repo.CanUseTimetracker(c, issue, c.Doer) {
|
||||
c.NotFound(nil)
|
||||
return
|
||||
}
|
||||
|
||||
wasRunning := issues_model.StopwatchExists(c, c.Doer.ID, issue.ID)
|
||||
|
||||
if wasRunning {
|
||||
if err := issues_model.FinishIssueStopwatch(c, c.Doer, issue); err != nil {
|
||||
c.ServerError("FinishIssueStopwatch", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.Flash.Warning(c.Tr("repo.issues.tracker_already_stopped"))
|
||||
}
|
||||
|
||||
c.JSONRedirect("")
|
||||
|
|
|
|||
|
|
@ -1253,7 +1253,8 @@ func registerWebRoutes(m *web.Router) {
|
|||
m.Post("/add", web.Bind(forms.AddTimeManuallyForm{}), repo.AddTimeManually)
|
||||
m.Post("/{timeid}/delete", repo.DeleteTime)
|
||||
m.Group("/stopwatch", func() {
|
||||
m.Post("/toggle", repo.IssueStopwatch)
|
||||
m.Post("/start", repo.IssueStartStopwatch)
|
||||
m.Post("/stop", repo.IssueStopStopwatch)
|
||||
m.Post("/cancel", repo.CancelStopwatch)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@
|
|||
</a>
|
||||
<div class="divider"></div>
|
||||
{{if $.IsStopwatchRunning}}
|
||||
<a class="item issue-stop-time link-action" data-url="{{.Issue.Link}}/times/stopwatch/toggle">
|
||||
<a class="item issue-stop-time link-action" data-url="{{.Issue.Link}}/times/stopwatch/stop">
|
||||
{{svg "octicon-stopwatch"}} {{ctx.Locale.Tr "repo.issues.timetracker_timer_stop"}}
|
||||
</a>
|
||||
<a class="item issue-cancel-time link-action" data-url="{{.Issue.Link}}/times/stopwatch/cancel">
|
||||
{{svg "octicon-trash"}} {{ctx.Locale.Tr "repo.issues.timetracker_timer_discard"}}
|
||||
</a>
|
||||
{{else}}
|
||||
<a class="item issue-start-time link-action" data-url="{{.Issue.Link}}/times/stopwatch/toggle">
|
||||
<a class="item issue-start-time link-action" data-url="{{.Issue.Link}}/times/stopwatch/start">
|
||||
{{svg "octicon-stopwatch"}} {{ctx.Locale.Tr "repo.issues.timetracker_timer_start"}}
|
||||
</a>
|
||||
<a class="item issue-add-time show-modal" data-modal="#issue-time-manually-add-modal">
|
||||
|
|
|
|||
Loading…
Reference in New Issue