aboutsummaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/issue.go39
-rw-r--r--routers/repo/issue_stopwatch.go50
-rw-r--r--routers/repo/issue_timetrack.go50
-rw-r--r--routers/repo/setting.go5
4 files changed, 140 insertions, 4 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index d1c5e1fe71..0cd4edabb6 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -589,6 +589,38 @@ func ViewIssue(ctx *context.Context) {
comment *models.Comment
participants = make([]*models.User, 1, 10)
)
+ if ctx.Repo.Repository.IsTimetrackerEnabled() {
+ if ctx.IsSigned {
+ // Deal with the stopwatch
+ ctx.Data["IsStopwatchRunning"] = models.StopwatchExists(ctx.User.ID, issue.ID)
+ if !ctx.Data["IsStopwatchRunning"].(bool) {
+ var exists bool
+ var sw *models.Stopwatch
+ if exists, sw, err = models.HasUserStopwatch(ctx.User.ID); err != nil {
+ ctx.Handle(500, "HasUserStopwatch", err)
+ return
+ }
+ ctx.Data["HasUserStopwatch"] = exists
+ if exists {
+ // Add warning if the user has already a stopwatch
+ var otherIssue *models.Issue
+ if otherIssue, err = models.GetIssueByID(sw.IssueID); err != nil {
+ ctx.Handle(500, "GetIssueByID", err)
+ return
+ }
+ // Add link to the issue of the already running stopwatch
+ ctx.Data["OtherStopwatchURL"] = otherIssue.HTMLURL()
+ }
+ }
+ ctx.Data["CanUseTimetracker"] = ctx.Repo.CanUseTimetracker(issue, ctx.User)
+ } else {
+ ctx.Data["CanUseTimetracker"] = false
+ }
+ if ctx.Data["WorkingUsers"], err = models.TotalTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
+ ctx.Handle(500, "TotalTimes", err)
+ return
+ }
+ }
// Render comments and and fetch participants.
participants[0] = issue.Poster
@@ -683,7 +715,8 @@ func ViewIssue(ctx *context.Context) {
ctx.HTML(200, tplIssueView)
}
-func getActionIssue(ctx *context.Context) *models.Issue {
+// GetActionIssue will return the issue which is used in the context.
+func GetActionIssue(ctx *context.Context) *models.Issue {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
@@ -720,7 +753,7 @@ func getActionIssues(ctx *context.Context) []*models.Issue {
// UpdateIssueTitle change issue's title
func UpdateIssueTitle(ctx *context.Context) {
- issue := getActionIssue(ctx)
+ issue := GetActionIssue(ctx)
if ctx.Written() {
return
}
@@ -748,7 +781,7 @@ func UpdateIssueTitle(ctx *context.Context) {
// UpdateIssueContent change issue's content
func UpdateIssueContent(ctx *context.Context) {
- issue := getActionIssue(ctx)
+ issue := GetActionIssue(ctx)
if ctx.Written() {
return
}
diff --git a/routers/repo/issue_stopwatch.go b/routers/repo/issue_stopwatch.go
new file mode 100644
index 0000000000..7e3121da9f
--- /dev/null
+++ b/routers/repo/issue_stopwatch.go
@@ -0,0 +1,50 @@
+// Copyright 2017 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 repo
+
+import (
+ "net/http"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/context"
+)
+
+// IssueStopwatch creates or stops a stopwatch for the given issue.
+func IssueStopwatch(c *context.Context) {
+ issueIndex := c.ParamsInt64("index")
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, issueIndex)
+
+ if err != nil {
+ c.Handle(http.StatusInternalServerError, "GetIssueByIndex", err)
+ return
+ }
+
+ if err := models.CreateOrStopIssueStopwatch(c.User, issue); err != nil {
+ c.Handle(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
+ return
+ }
+
+ url := issue.HTMLURL()
+ c.Redirect(url, http.StatusSeeOther)
+}
+
+// CancelStopwatch cancel the stopwatch
+func CancelStopwatch(c *context.Context) {
+ issueIndex := c.ParamsInt64("index")
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, issueIndex)
+
+ if err != nil {
+ c.Handle(http.StatusInternalServerError, "GetIssueByIndex", err)
+ return
+ }
+
+ if err := models.CancelStopwatch(c.User, issue); err != nil {
+ c.Handle(http.StatusInternalServerError, "CancelStopwatch", err)
+ return
+ }
+
+ url := issue.HTMLURL()
+ c.Redirect(url, http.StatusSeeOther)
+}
diff --git a/routers/repo/issue_timetrack.go b/routers/repo/issue_timetrack.go
new file mode 100644
index 0000000000..e01cd48a66
--- /dev/null
+++ b/routers/repo/issue_timetrack.go
@@ -0,0 +1,50 @@
+// Copyright 2017 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 repo
+
+import (
+ "net/http"
+ "time"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/auth"
+ "code.gitea.io/gitea/modules/context"
+)
+
+// AddTimeManually tracks time manually
+func AddTimeManually(c *context.Context, form auth.AddTimeManuallyForm) {
+ issueIndex := c.ParamsInt64("index")
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, issueIndex)
+ if err != nil {
+ if models.IsErrIssueNotExist(err) {
+ c.Handle(http.StatusNotFound, "GetIssueByIndex", err)
+ return
+ }
+ c.Handle(http.StatusInternalServerError, "GetIssueByIndex", err)
+ return
+ }
+ url := issue.HTMLURL()
+
+ if c.HasError() {
+ c.Flash.Error(c.GetErrMsg())
+ c.Redirect(url)
+ return
+ }
+
+ total := time.Duration(form.Hours)*time.Hour + time.Duration(form.Minutes)*time.Minute
+
+ if total <= 0 {
+ c.Flash.Error(c.Tr("repo.issues.add_time_sum_to_small"))
+ c.Redirect(url, http.StatusSeeOther)
+ return
+ }
+
+ if _, err := models.AddTime(c.User, issue, int64(total)); err != nil {
+ c.Handle(http.StatusInternalServerError, "AddTime", err)
+ return
+ }
+
+ c.Redirect(url, http.StatusSeeOther)
+}
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index 8b38e80916..6e12c7ad6d 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -201,7 +201,10 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
RepoID: repo.ID,
Type: models.UnitTypeIssues,
Index: int(models.UnitTypeIssues),
- Config: new(models.UnitConfig),
+ Config: &models.IssuesConfig{
+ EnableTimetracker: form.EnableTimetracker,
+ AllowOnlyContributorsToTrackTime: form.AllowOnlyContributorsToTrackTime,
+ },
})
}
}