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 37 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 @@ -136,6 +136,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 @@ -541,6 +543,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 @@ -692,6 +704,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 @@ -859,6 +872,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 @@ -100,6 +100,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
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ var migrations = []Migration{
NewMigration("Add Sorting to ProjectBoard table", addSortingColToProjectBoard),
// v172 -> v173
NewMigration("Add sessions table for go-chi/session", addSessionTable),
// v173 -> v174
NewMigration("Add time_id column to Comment", addTimeIDCommentColumn),
}

// GetCurrentDBVersion returns the current db version
Expand Down
22 changes: 22 additions & 0 deletions models/migrations/v173.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"fmt"

"xorm.io/xorm"
)

func addTimeIDCommentColumn(x *xorm.Engine) error {
type Comment struct {
TimeID int64
}

if err := x.Sync2(new(Comment)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return nil
}
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ issues.stop_tracking_history = `stopped working %s`
issues.cancel_tracking = Discard
issues.cancel_tracking_history = `cancelled time tracking %s`
issues.add_time = Manually Add Time
issues.del_time = Delete this time log
issues.add_time_short = Add Time
issues.add_time_cancel = Cancel
issues.add_time_history = `added spent time %s`
Expand Down
4 changes: 4 additions & 0 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,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
35 changes: 35 additions & 0 deletions routers/repo/issue_timetrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,38 @@ func AddTimeManually(c *context.Context) {

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
}

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(issue.HTMLURL(), http.StatusSeeOther)
6543 marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions routers/routes/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ func RegisterRoutes(m *web.Route) {
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 @@ -276,6 +276,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/comments_delete_time" Dict "ctx" $ "comment" . }}
<div class="detail">
{{svg "octicon-clock"}}
<span class="text grey">{{.Content}}</span>
Expand All @@ -291,6 +292,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/comments_delete_time" Dict "ctx" $ "comment" . }}
<div class="detail">
{{svg "octicon-clock"}}
<span class="text grey">{{.Content}}</span>
Expand Down
21 changes: 21 additions & 0 deletions templates/repo/issue/view_content/comments_delete_time.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{ if .comment.Time }} {{/* compatibility with time comments made before v1.14 */}}
{{ if (not .comment.Time.Deleted) }}
{{ if (or .ctx.IsAdmin (and .ctx.IsSigned (eq .ctx.SignedUserID .comment.PosterID))) }}
<span class="ui float right">
<div class="ui mini modal issue-delete-time-modal" data-id="{{.comment.Time.ID}}">
<form method="POST" class="delete-time-form" action="{{.ctx.RepoLink}}/issues/{{.ctx.Issue.Index}}/times/{{.comment.TimeID}}/delete">
{{.ctx.CsrfTokenHtml}}
</form>
<div class="header">{{.ctx.i18n.Tr "repo.issues.del_time"}}</div>
<div class="actions">
<div class="ui red approve button">{{.ctx.i18n.Tr "repo.issues.context.delete"}}</div>
<div class="ui cancel button">{{.ctx.i18n.Tr "repo.issues.add_time_cancel"}}</div>
</div>
</div>
<button class="ui icon button compact mini issue-delete-time poping up" data-id="{{.comment.Time.ID}}" data-content="{{.ctx.i18n.Tr "repo.issues.del_time"}}" data-position="top right" data-variation="tiny inverted">
{{svg "octicon-trashcan"}}
</button>
</span>
{{end}}
{{end}}
{{end}}
2 changes: 1 addition & 1 deletion templates/repo/issue/view_content/sidebar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
{{end}}
<div class="ui buttons two fluid">
<button class="ui button poping up issue-start-time" data-content='{{.i18n.Tr "repo.issues.start_tracking"}}' data-position="top center" data-variation="small inverted">{{.i18n.Tr "repo.issues.start_tracking_short"}}</button>
<div class="ui mini modal">
<div class="ui mini modal issue-start-time-modal">
<div class="header">{{.i18n.Tr "repo.issues.add_time"}}</div>
<div class="content">
<form method="POST" id="add_time_manual_form" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/times/add" class="ui action input fluid">
Expand Down
16 changes: 15 additions & 1 deletion web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3198,19 +3198,33 @@ function initVueApp() {

function initIssueTimetracking() {
$(document).on('click', '.issue-add-time', () => {
$('.mini.modal').modal({
$('.issue-start-time-modal').modal({
duration: 200,
onApprove() {
$('#add_time_manual_form').trigger('submit');
}
}).modal('show');
$('.issue-start-time-modal input').on('keydown', (e) => {
if ((e.keyCode || e.key) === 13) {
$('#add_time_manual_form').trigger('submit');
}
});
});
$(document).on('click', '.issue-start-time, .issue-stop-time', () => {
$('#toggle_stopwatch_form').trigger('submit');
});
$(document).on('click', '.issue-cancel-time', () => {
$('#cancel_stopwatch_form').trigger('submit');
});
$(document).on('click', 'button.issue-delete-time', function () {
const sel = `.issue-delete-time-modal[data-id="${$(this).data('id')}"]`;
$(sel).modal({
duration: 200,
onApprove() {
$(`${sel} form`).trigger('submit');
}
}).modal('show');
});
}

function initFilterBranchTagDropdown(selector) {
Expand Down