diff --git a/gogs.go b/gogs.go index 45aa9f5931..bdec2a71ac 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 3651c46116..d0a65298b2 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 0c0b7348f4..23f2480dda 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 2853312394..d4fe1044f1 100644 --- a/templates/issue/list.tmpl +++ b/templates/issue/list.tmpl @@ -17,12 +17,13 @@

Label