diff options
-rw-r--r-- | gogs.go | 2 | ||||
-rw-r--r-- | models/issue.go | 7 | ||||
-rw-r--r-- | routers/repo/issue.go | 29 | ||||
-rw-r--r-- | templates/issue/list.tmpl | 13 |
4 files changed, 43 insertions, 8 deletions
@@ -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 @@ <h4>Label</h4> <ul class="list-unstyled" id="label-list" data-ajax="{{$.RepoLink}}/issues/labels/delete"> {{range .Labels}} - <li class="label-item" id="label-{{.Id}}" data-id="{{.Id}}"><a href="#"> - <span class="pull-right count">{{if $.IsShowClosed}}{{.NumClosedIssues}}{{else}}{{.NumOpenIssues}}{{end}}</span> - <span class="color" style="background-color: {{.Color}}" data-color="{{.Color}}"></span> - <span class="name">{{.Name}}</span> - </a> - <a class="del pull-right" href="#" data-id="{{.Id}}"><i class="fa fa-times-circle-o"></i></a> + <li class="label-item" id="label-{{.Id}}" data-id="{{.Id}}"> + <a href="#"> + <span class="pull-right count">{{if $.IsShowClosed}}{{.NumClosedIssues}}{{else}}{{.NumOpenIssues}}{{end}}</span> + <span class="color" style="background-color: {{.Color}}" data-color="{{.Color}}"></span> + <span class="name">{{.Name}}</span> + </a> + <a class="del pull-right" href="#" data-id="{{.Id}}"><i class="fa fa-times-circle-o"></i></a> </li> {{end}} <li class="label-change-li" style="display: none"> |