Skip to content

Commit

Permalink
Merge pull request 'implemented date adding for tracked time. it is r…
Browse files Browse the repository at this point in the history
…equired 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
  • Loading branch information
vsysoev committed Aug 27, 2021
2 parents 43494f6 + 328ca6e commit b5c38a4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
11 changes: 6 additions & 5 deletions models/issue_tracked_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type TrackedTime struct {
UserID int64 `xorm:"INDEX"`
User *User `xorm:"-"`
Created time.Time `xorm:"-"`
CreatedUnix int64 `xorm:"created"`
CreatedUnix int64 `xorm:"created_unix"`
Time int64 `xorm:"NOT NULL"`
Deleted bool `xorm:"NOT NULL DEFAULT false"`
}
Expand Down Expand Up @@ -175,10 +175,11 @@ func addTime(e Engine, user *User, issue *Issue, amount int64, created time.Time
created = time.Now()
}
tt := &TrackedTime{
IssueID: issue.ID,
UserID: user.ID,
Time: amount,
Created: created,
IssueID: issue.ID,
UserID: user.ID,
Time: amount,
Created: created,
CreatedUnix: created.Unix(),
}
if _, err := e.Insert(tt); err != nil {
return nil, err
Expand Down
8 changes: 5 additions & 3 deletions routers/web/repo/issue_timetrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func AddTimeManually(c *context.Context) {
return
}
url := issue.HTMLURL()

if c.HasError() {
c.Flash.Error(c.GetErrMsg())
c.Redirect(url)
Expand All @@ -40,8 +39,11 @@ func AddTimeManually(c *context.Context) {
c.Redirect(url, http.StatusSeeOther)
return
}

if _, err := models.AddTime(c.User, issue, int64(total.Seconds()), time.Now()); err != nil {
created, err := time.Parse("2006-01-02", form.Created)
if err != nil {
created = time.Now()
}
if _, err := models.AddTime(c.User, issue, int64(total.Seconds()), created); err != nil {
c.ServerError("AddTime", err)
return
}
Expand Down
5 changes: 3 additions & 2 deletions services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,9 @@ func (f *DeleteRepoFileForm) Validate(req *http.Request, errs binding.Errors) bi

// AddTimeManuallyForm form that adds spent time manually.
type AddTimeManuallyForm struct {
Hours int `binding:"Range(0,1000)"`
Minutes int `binding:"Range(0,1000)"`
Created string `form:"created" binding:"OmitEmpty;Size(10)"`
Hours int `binding:"Range(0,1000)"`
Minutes int `binding:"Range(0,1000)"`
}

// Validate validates the fields
Expand Down
3 changes: 2 additions & 1 deletion templates/repo/issue/view_content/sidebar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,12 @@
</div>
{{end}}
<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>
<div class="ui mini modal issue-start-time-modal">
<div class="ui tiny 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">
{{$.CsrfTokenHtml}}
<input type="date" name="created">
<input placeholder='{{.i18n.Tr "repo.issues.add_time_hours"}}' type="number" name="hours">
<input placeholder='{{.i18n.Tr "repo.issues.add_time_minutes"}}' type="number" name="minutes" class="ui compact">
</form>
Expand Down

0 comments on commit b5c38a4

Please sign in to comment.