From 16bddd593a9c4cd075d5e4ad8ed69c049223aef1 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 14 May 2014 11:14:51 -0400 Subject: [PATCH] =?UTF-8?q?Finish=20change=20issue=E2=80=99s=20milestone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/issue.go | 26 +++++++++++++----------- routers/repo/issue.go | 40 ++++++++++++++++++++++++++++++++----- templates/issue/create.tmpl | 28 ++++++++++++++++---------- templates/issue/view.tmpl | 6 +++--- 4 files changed, 70 insertions(+), 30 deletions(-) diff --git a/models/issue.go b/models/issue.go index 26380b6033..3d3e433a42 100644 --- a/models/issue.go +++ b/models/issue.go @@ -543,18 +543,20 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) { } } - m, err := GetMilestoneById(mid) - if err != nil { - return err - } - m.NumIssues++ - if isIssueClosed { - m.NumClosedIssues++ - } - m.Completeness = m.NumClosedIssues * 100 / m.NumIssues - if _, err = sess.Id(m.Id).Update(m); err != nil { - sess.Rollback() - return err + if mid > 0 { + m, err := GetMilestoneById(mid) + if err != nil { + return err + } + m.NumIssues++ + if isIssueClosed { + m.NumClosedIssues++ + } + m.Completeness = m.NumClosedIssues * 100 / m.NumIssues + if _, err = sess.Id(m.Id).Update(m); err != nil { + sess.Rollback() + return err + } } return sess.Commit() } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 2346539d0c..7b8c912e69 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -53,17 +53,21 @@ func Issues(ctx *middleware.Context) { filterMode = models.FM_MENTION } + var mid 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 + if midx > 0 { + mile, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, midx) + if err != nil { + ctx.Handle(500, "issue.Issues(GetMilestoneByIndex): %v", err) + return + } + mid = mile.Id } page, _ := base.StrTo(ctx.Query("page")).Int() // Get issues. - issues, err := models.GetIssues(assigneeId, ctx.Repo.Repository.Id, posterId, mile.Id, page, + issues, err := models.GetIssues(assigneeId, ctx.Repo.Repository.Id, posterId, mid, page, isShowClosed, ctx.Query("labels"), ctx.Query("sortType")) if err != nil { ctx.Handle(500, "issue.Issues(GetIssues): %v", err) @@ -120,6 +124,19 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false + var err error + // 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 + } + us, err := models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/")) if err != nil { ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err) @@ -134,6 +151,19 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false + var err error + // 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 + } + us, err := models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/")) if err != nil { ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err) diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index 4b43116cca..34cecc78bd 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -48,25 +48,33 @@
+ {{if not .OpenMilestones}}

Nothing to show

+ {{else}}
    -
  • -

    Milestone name

    -

    due to 3 days later

    -
  • -
  • -

    Milestone name

    -

    due to 3 days later

    + {{range .OpenMilestones}} +
  • +

    {{.Name}}

    +
  • + {{end}}
+ {{end}}
+
+ {{if not .ClosedMilestones}} +

Nothing to show

+ {{else}}
    -
  • -

    Milestone name

    -

    closed 3 days ago

    + {{range .ClosedMilestones}} +
  • +

    {{.Name}}

    +

    Closed {{TimeSince .ClosedDate}}

  • + {{end}}
+ {{end}}
diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 5aeb9409e1..18ec5faf0e 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -100,7 +100,7 @@
-
+