Skip to content

Commit b5c38a4

Browse files
committed
Merge pull request 'implemented date adding for tracked time. it is required to calculate monthly timesheets' (go-gitea#8) from feature/7-date-to-time into integra
Reviewed-on: http://gitea.corp.sarov-site.online/integra/gitea/pulls/8
2 parents 43494f6 + 328ca6e commit b5c38a4

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

models/issue_tracked_time.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type TrackedTime struct {
2020
UserID int64 `xorm:"INDEX"`
2121
User *User `xorm:"-"`
2222
Created time.Time `xorm:"-"`
23-
CreatedUnix int64 `xorm:"created"`
23+
CreatedUnix int64 `xorm:"created_unix"`
2424
Time int64 `xorm:"NOT NULL"`
2525
Deleted bool `xorm:"NOT NULL DEFAULT false"`
2626
}
@@ -175,10 +175,11 @@ func addTime(e Engine, user *User, issue *Issue, amount int64, created time.Time
175175
created = time.Now()
176176
}
177177
tt := &TrackedTime{
178-
IssueID: issue.ID,
179-
UserID: user.ID,
180-
Time: amount,
181-
Created: created,
178+
IssueID: issue.ID,
179+
UserID: user.ID,
180+
Time: amount,
181+
Created: created,
182+
CreatedUnix: created.Unix(),
182183
}
183184
if _, err := e.Insert(tt); err != nil {
184185
return nil, err

routers/web/repo/issue_timetrack.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func AddTimeManually(c *context.Context) {
2626
return
2727
}
2828
url := issue.HTMLURL()
29-
3029
if c.HasError() {
3130
c.Flash.Error(c.GetErrMsg())
3231
c.Redirect(url)
@@ -40,8 +39,11 @@ func AddTimeManually(c *context.Context) {
4039
c.Redirect(url, http.StatusSeeOther)
4140
return
4241
}
43-
44-
if _, err := models.AddTime(c.User, issue, int64(total.Seconds()), time.Now()); err != nil {
42+
created, err := time.Parse("2006-01-02", form.Created)
43+
if err != nil {
44+
created = time.Now()
45+
}
46+
if _, err := models.AddTime(c.User, issue, int64(total.Seconds()), created); err != nil {
4547
c.ServerError("AddTime", err)
4648
return
4749
}

services/forms/repo_form.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,9 @@ func (f *DeleteRepoFileForm) Validate(req *http.Request, errs binding.Errors) bi
804804

805805
// AddTimeManuallyForm form that adds spent time manually.
806806
type AddTimeManuallyForm struct {
807-
Hours int `binding:"Range(0,1000)"`
808-
Minutes int `binding:"Range(0,1000)"`
807+
Created string `form:"created" binding:"OmitEmpty;Size(10)"`
808+
Hours int `binding:"Range(0,1000)"`
809+
Minutes int `binding:"Range(0,1000)"`
809810
}
810811

811812
// Validate validates the fields

templates/repo/issue/view_content/sidebar.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,12 @@
354354
</div>
355355
{{end}}
356356
<button class="ui fluid 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>
357-
<div class="ui mini modal issue-start-time-modal">
357+
<div class="ui tiny modal issue-start-time-modal">
358358
<div class="header">{{.i18n.Tr "repo.issues.add_time"}}</div>
359359
<div class="content">
360360
<form method="POST" id="add_time_manual_form" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/times/add" class="ui action input fluid">
361361
{{$.CsrfTokenHtml}}
362+
<input type="date" name="created">
362363
<input placeholder='{{.i18n.Tr "repo.issues.add_time_hours"}}' type="number" name="hours">
363364
<input placeholder='{{.i18n.Tr "repo.issues.add_time_minutes"}}' type="number" name="minutes" class="ui compact">
364365
</form>

0 commit comments

Comments
 (0)