summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-14 10:55:36 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-14 10:55:36 -0400
commit46fc36c3a63b5501ca154df885ae5446ebb66220 (patch)
treebf430623b1a1eb664b96759bff068d2a2624b92e /routers
parent99f2400e3b4f141671bd8f31d23afcd0cf511c05 (diff)
downloadgitea-46fc36c3a63b5501ca154df885ae5446ebb66220.tar.gz
gitea-46fc36c3a63b5501ca154df885ae5446ebb66220.zip
Finish change issue’s milestone
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/issue.go86
1 files changed, 82 insertions, 4 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 3e19724c38..2346539d0c 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -53,11 +53,17 @@ func Issues(ctx *middleware.Context) {
filterMode = models.FM_MENTION
}
- mid, _ := base.StrTo(ctx.Query("milestone")).Int64()
+ midx, _ := base.StrTo(ctx.Query("milestone")).Int64()
+ mile, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, midx)
+ if err != nil {
+ ctx.Handle(500, "issue.Issues(GetMilestoneByIndex): %v", err)
+ return
+ }
+
page, _ := base.StrTo(ctx.Query("page")).Int()
// Get issues.
- issues, err := models.GetIssues(assigneeId, ctx.Repo.Repository.Id, posterId, mid, page,
+ issues, err := models.GetIssues(assigneeId, ctx.Repo.Repository.Id, posterId, mile.Id, page,
isShowClosed, ctx.Query("labels"), ctx.Query("sortType"))
if err != nil {
ctx.Handle(500, "issue.Issues(GetIssues): %v", err)
@@ -240,12 +246,37 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
return
}
- us, err := models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/"))
+ // Get assigned milestone.
+ if issue.MilestoneId > 0 {
+ ctx.Data["Milestone"], err = models.GetMilestoneById(issue.MilestoneId)
+ if err != nil {
+ if err == models.ErrMilestoneNotExist {
+ log.Warn("issue.ViewIssue(GetMilestoneById): %v", err)
+ } else {
+ ctx.Handle(500, "issue.ViewIssue(GetMilestoneById)", err)
+ return
+ }
+ }
+ }
+
+ // Get all milestones.
+ ctx.Data["OpenMilestones"], err = models.GetMilestones(ctx.Repo.Repository.Id, false)
+ if err != nil {
+ ctx.Handle(500, "issue.ViewIssue(GetMilestones.1): %v", err)
+ return
+ }
+ ctx.Data["ClosedMilestones"], err = models.GetMilestones(ctx.Repo.Repository.Id, true)
+ if err != nil {
+ ctx.Handle(500, "issue.ViewIssue(GetMilestones.2): %v", err)
+ return
+ }
+
+ // Get all collaborators.
+ ctx.Data["Collaborators"], err = models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/"))
if err != nil {
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err)
return
}
- ctx.Data["Collaborators"] = us
if ctx.IsSigned {
// Update issue-user.
@@ -331,6 +362,52 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
})
}
+func UpdateIssueMilestone(ctx *middleware.Context) {
+ if !ctx.Repo.IsOwner {
+ ctx.Error(403)
+ return
+ }
+
+ issueId, err := base.StrTo(ctx.Query("issue")).Int64()
+ if err != nil {
+ ctx.Error(404)
+ return
+ }
+
+ issue, err := models.GetIssueById(issueId)
+ if err != nil {
+ if err == models.ErrIssueNotExist {
+ ctx.Handle(404, "issue.UpdateIssueMilestone(GetIssueById)", err)
+ } else {
+ ctx.Handle(500, "issue.UpdateIssueMilestone(GetIssueById)", err)
+ }
+ return
+ }
+
+ oldMid := issue.MilestoneId
+ mid, _ := base.StrTo(ctx.Query("milestone")).Int64()
+ if oldMid == mid {
+ ctx.JSON(200, map[string]interface{}{
+ "ok": true,
+ })
+ return
+ }
+
+ // Not check for invalid milestone id and give responsibility to owners.
+ issue.MilestoneId = mid
+ if err = models.ChangeMilestoneAssign(oldMid, mid, issue.IsClosed); err != nil {
+ ctx.Handle(500, "issue.UpdateIssueMilestone(ChangeMilestoneAssign)", err)
+ return
+ } else if err = models.UpdateIssue(issue); err != nil {
+ ctx.Handle(500, "issue.UpdateIssueMilestone(UpdateIssue)", err)
+ return
+ }
+
+ ctx.JSON(200, map[string]interface{}{
+ "ok": true,
+ })
+}
+
func UpdateAssignee(ctx *middleware.Context) {
if !ctx.Repo.IsOwner {
ctx.Error(403)
@@ -580,6 +657,7 @@ func UpdateMilestone(ctx *middleware.Context, params martini.Params) {
}
case "close":
if !mile.IsClosed {
+ mile.ClosedDate = time.Now()
if err = models.ChangeMilestoneStatus(mile, true); err != nil {
ctx.Handle(500, "issue.UpdateMilestone(ChangeMilestoneStatus)", err)
return