From dce17c86ac26f2110e6067e8f85340122fe5d1e0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 24 May 2014 03:05:41 -0400 Subject: [PATCH] Almost done issue label #200 --- gogs.go | 2 +- models/issue.go | 7 +++++++ routers/repo/issue.go | 29 ++++++++++++++++++++++++++++- templates/issue/list.tmpl | 13 +++++++------ 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/gogs.go b/gogs.go index 45aa9f593..bdec2a71a 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/base" ) -const APP_VER = "0.3.5.0523 Alpha" +const APP_VER = "0.3.5.0524 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/issue.go b/models/issue.go index 3651c4611..d0a65298b 100644 --- a/models/issue.go +++ b/models/issue.go @@ -183,6 +183,13 @@ func GetIssues(uid, rid, pid, mid int64, page int, isClosed bool, labelIds, sort return issues, err } +type IssueStatus int + +const ( + IS_OPEN = iota + 1 + IS_CLOSE +) + // GetIssuesByLabel returns a list of issues by given label and repository. func GetIssuesByLabel(repoId int64, label string) ([]*Issue, error) { issues := make([]*Issue, 0, 10) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 0c0b7348f..23f2480dd 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -445,7 +445,7 @@ func UpdateIssueLabel(ctx *middleware.Context, params martini.Params) { issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, idx) if err != nil { if err == models.ErrIssueNotExist { - ctx.Handle(404, "issue.UpdateIssueLabel", err) + ctx.Handle(404, "issue.UpdateIssueLabel(GetIssueByIndex)", err) } else { ctx.Handle(500, "issue.UpdateIssueLabel(GetIssueByIndex)", err) } @@ -454,6 +454,17 @@ func UpdateIssueLabel(ctx *middleware.Context, params martini.Params) { isAttach := ctx.Query("action") == "attach" labelStrId := ctx.Query("id") + labelId, _ := base.StrTo(labelStrId).Int64() + label, err := models.GetLabelById(labelId) + if err != nil { + if err == models.ErrLabelNotExist { + ctx.Handle(404, "issue.UpdateIssueLabel(GetLabelById)", err) + } else { + ctx.Handle(500, "issue.UpdateIssueLabel(GetLabelById)", err) + } + return + } + isHad := strings.Contains(issue.LabelIds, "$"+labelStrId+"|") isNeedUpdate := false if isAttach { @@ -473,6 +484,22 @@ func UpdateIssueLabel(ctx *middleware.Context, params martini.Params) { ctx.Handle(500, "issue.UpdateIssueLabel(UpdateIssue)", err) return } + + if isAttach { + label.NumIssues++ + if issue.IsClosed { + label.NumClosedIssues++ + } + } else { + label.NumIssues-- + if issue.IsClosed { + label.NumClosedIssues-- + } + } + if err = models.UpdateLabel(label); err != nil { + ctx.Handle(500, "issue.UpdateIssueLabel(UpdateLabel)", err) + return + } } ctx.JSON(200, map[string]interface{}{ "ok": true, diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl index 285331239..d4fe1044f 100644 --- a/templates/issue/list.tmpl +++ b/templates/issue/list.tmpl @@ -17,12 +17,13 @@

Label