Skip to content
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

Add UI to delete tracked times #14100

Merged
merged 40 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
99d977f
add DeleteTime issue action
noerw Dec 21, 2020
864651a
store time ID for CommentTypeAddTimeManual & StopTracking
noerw Dec 21, 2020
083bb1e
add template to render delete time button on comments
noerw Dec 21, 2020
a322b60
code review
noerw Dec 22, 2020
0ee2dce
make linter happy
noerw Dec 22, 2020
0bfc614
Update routers/repo/issue_timetrack.go
noerw Dec 22, 2020
3cab4a8
Update routers/repo/issue_timetrack.go
noerw Dec 22, 2020
ba50f18
Merge branch 'master' into delete-times-ui
6543 Dec 22, 2020
7470f8a
add confirmation dialog
noerw Dec 22, 2020
78f4b2c
revert vscode shenanigans
noerw Dec 22, 2020
dd0a7d7
make linter happy
noerw Dec 22, 2020
6a37c2f
(╯°□°)╯︵ ┻━┻
noerw Dec 22, 2020
3548da4
Merge branch 'master' into delete-times-ui
6543 Dec 22, 2020
7d2f0d3
Add migration
6543 Dec 22, 2020
c8e6271
Merge branch 'master' into delete-times-ui
noerw Dec 24, 2020
d360901
rename to comments_delete_time template
noerw Dec 24, 2020
e0a11f4
rectangular button
noerw Dec 24, 2020
c97d667
submit add time on enter
noerw Dec 24, 2020
0bd16c9
revert -> Revert Time Log
noerw Dec 24, 2020
acf5a84
Merge branch 'master' into delete-times-ui
6543 Dec 27, 2020
209304e
revert -> delete, trashcan icon
noerw Jan 10, 2021
b655885
move migration for curr master
noerw Jan 10, 2021
1f6f28a
Merge remote-tracking branch 'origin/master' into delete-times-ui
noerw Jan 10, 2021
432127b
Merge remote-tracking branch 'noerw/delete-times-ui' into delete-time…
noerw Jan 10, 2021
12ba398
Merge remote-tracking branch 'origin/master' into delete-times-ui
noerw Jan 12, 2021
c0396e5
fixup! Merge remote-tracking branch 'origin/master' into delete-times-ui
noerw Jan 12, 2021
d35eb22
fixup! Merge remote-tracking branch 'origin/master' into delete-times-ui
noerw Jan 12, 2021
a1260a3
Merge remote-tracking branch 'origin/master' into delete-times-ui
noerw Jan 13, 2021
f2c8542
Merge branch 'master' into delete-times-ui
noerw Jan 16, 2021
498f15f
Merge branch 'master' into delete-times-ui
6543 Jan 19, 2021
18d62ef
Merge branch 'master' into delete-times-ui
6543 Jan 23, 2021
a2b0b66
Merge branch 'master' into delete-times-ui
6543 Feb 4, 2021
2041c93
migrate to chi
6543 Feb 4, 2021
0955919
Merge branch 'master' into delete-times-ui
6543 Feb 9, 2021
fbf4a1d
add
6543 Feb 12, 2021
4543349
Merge branch 'master' into delete-times-ui
6543 Feb 12, 2021
040cea4
Merge branch 'master' into delete-times-ui
6543 Feb 15, 2021
bc0fc82
Merge branch 'master' into delete-times-ui
6543 Feb 19, 2021
2a2dd93
Flash Success
6543 Feb 19, 2021
574fad2
imports
6543 Feb 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ type Comment struct {
MilestoneID int64
OldMilestone *Milestone `xorm:"-"`
Milestone *Milestone `xorm:"-"`
TimeID int64
Time *TrackedTime `xorm:"-"`
AssigneeID int64
RemovedAssignee bool
Assignee *User `xorm:"-"`
Expand Down Expand Up @@ -540,6 +542,16 @@ func (c *Comment) LoadDepIssueDetails() (err error) {
return err
}

// LoadTime loads the associated time for a CommentTypeAddTimeManual
func (c *Comment) LoadTime() error {
if c.Time != nil || c.TimeID == 0 {
return nil
}
var err error
c.Time, err = GetTrackedTimeByID(c.TimeID)
return err
}

func (c *Comment) loadReactions(e Engine, repo *Repository) (err error) {
if c.Reactions != nil {
return nil
Expand Down Expand Up @@ -691,6 +703,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
MilestoneID: opts.MilestoneID,
OldProjectID: opts.OldProjectID,
ProjectID: opts.ProjectID,
TimeID: opts.TimeID,
RemovedAssignee: opts.RemovedAssignee,
AssigneeID: opts.AssigneeID,
AssigneeTeamID: opts.AssigneeTeamID,
Expand Down Expand Up @@ -858,6 +871,7 @@ type CreateCommentOptions struct {
MilestoneID int64
OldProjectID int64
ProjectID int64
TimeID int64
AssigneeID int64
AssigneeTeamID int64
RemovedAssignee bool
Expand Down
1 change: 1 addition & 0 deletions models/issue_stopwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error {
Repo: issue.Repo,
Content: SecToTime(timediff),
Type: CommentTypeStopTracking,
TimeID: tt.ID,
}); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions models/issue_tracked_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func AddTime(user *User, issue *Issue, amount int64, created time.Time) (*Tracke
Doer: user,
Content: SecToTime(amount),
Type: CommentTypeAddTimeManual,
TimeID: t.ID,
}); err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,10 @@ func ViewIssue(ctx *context.Context) {
ctx.ServerError("LoadPushCommits", err)
return
}
} else if comment.Type == models.CommentTypeAddTimeManual ||
comment.Type == models.CommentTypeStopTracking {
// drop error since times could be pruned from DB..
_ = comment.LoadTime()
}
}

Expand Down
42 changes: 42 additions & 0 deletions routers/repo/issue_timetrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,45 @@ func AddTimeManually(c *context.Context, form auth.AddTimeManuallyForm) {

c.Redirect(url, http.StatusSeeOther)
}

// DeleteTime deletes tracked time
func DeleteTime(c *context.Context) {
issue := GetActionIssue(c)
if c.Written() {
return
}
if !c.Repo.CanUseTimetracker(issue, c.User) {
c.NotFound("CanUseTimetracker", nil)
return
}
url := issue.HTMLURL()

if c.HasError() {
c.Flash.Error(c.GetErrMsg())
c.Redirect(url)
return
}
noerw marked this conversation as resolved.
Show resolved Hide resolved

t, err := models.GetTrackedTimeByID(c.ParamsInt64(":timeid"))
if err != nil {
if models.IsErrNotExist(err) {
c.NotFound("time not found", err)
return
}
c.Error(http.StatusInternalServerError, "GetTrackedTimeByID", err.Error())
return
}

// only OP or admin may delete
if !c.IsSigned || (!c.IsUserSiteAdmin() && c.User.ID != t.UserID) {
c.Error(http.StatusForbidden, "not allowed")
return
}

if err = models.DeleteTime(t); err != nil {
c.ServerError("DeleteTime", err)
return
}

c.Redirect(url, http.StatusSeeOther)
noerw marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions routers/routes/macaron.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ func RegisterMacaronRoutes(m *macaron.Macaron) {
m.Combo("/comments").Post(repo.MustAllowUserComment, bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
m.Group("/times", func() {
m.Post("/add", bindIgnErr(auth.AddTimeManuallyForm{}), repo.AddTimeManually)
m.Post("/:timeid/delete", repo.DeleteTime)
m.Group("/stopwatch", func() {
m.Post("/toggle", repo.IssueStopwatch)
m.Post("/cancel", repo.CancelStopwatch)
Expand Down
2 changes: 2 additions & 0 deletions templates/repo/issue/view_content/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
<a class="author" href="{{.Poster.HomeLink}}">{{.Poster.GetDisplayName}}</a>
{{$.i18n.Tr "repo.issues.stop_tracking_history" $createdStr | Safe}}
</span>
{{ template "repo/issue/view_content/delete_time" Dict "ctx" $ "comment" . }}
<div class="detail">
{{svg "octicon-clock"}}
<span class="text grey">{{.Content}}</span>
Expand All @@ -290,6 +291,7 @@
<a class="author" href="{{.Poster.HomeLink}}">{{.Poster.GetDisplayName}}</a>
{{$.i18n.Tr "repo.issues.add_time_history" $createdStr | Safe}}
</span>
{{ template "repo/issue/view_content/delete_time" Dict "ctx" $ "comment" . }}
<div class="detail">
{{svg "octicon-clock"}}
<span class="text grey">{{.Content}}</span>
Expand Down
14 changes: 14 additions & 0 deletions templates/repo/issue/view_content/delete_time.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ if .comment.Time }} <!-- compatibility with pre v1.14 -->
6543 marked this conversation as resolved.
Show resolved Hide resolved
{{ if (not .comment.Time.Deleted) }}
{{ if (or .ctx.IsAdmin (and .ctx.IsSigned (eq .ctx.SignedUserID .comment.PosterID))) }}
<span class="ui float right">
<form method="POST" action="{{.ctx.RepoLink}}/issues/{{.ctx.Issue.Index}}/times/{{.comment.TimeID}}/delete">
{{.ctx.CsrfTokenHtml}}
<button type="submit" class="ui icon button circular small">
<i class="icon delete"></i>
</button>
</form>
</span>
{{end}}
{{end}}
{{end}}