Almost done issue label #200

This commit is contained in:
Unknown 2014-05-24 03:05:41 -04:00
parent b1bdbd7f94
commit dce17c86ac
4 changed files with 43 additions and 8 deletions

View file

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
) )
const APP_VER = "0.3.5.0523 Alpha" const APP_VER = "0.3.5.0524 Alpha"
func init() { func init() {
base.AppVer = APP_VER base.AppVer = APP_VER

View file

@ -183,6 +183,13 @@ func GetIssues(uid, rid, pid, mid int64, page int, isClosed bool, labelIds, sort
return issues, err return issues, err
} }
type IssueStatus int
const (
IS_OPEN = iota + 1
IS_CLOSE
)
// GetIssuesByLabel returns a list of issues by given label and repository. // GetIssuesByLabel returns a list of issues by given label and repository.
func GetIssuesByLabel(repoId int64, label string) ([]*Issue, error) { func GetIssuesByLabel(repoId int64, label string) ([]*Issue, error) {
issues := make([]*Issue, 0, 10) issues := make([]*Issue, 0, 10)

View file

@ -445,7 +445,7 @@ func UpdateIssueLabel(ctx *middleware.Context, params martini.Params) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, idx) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, idx)
if err != nil { if err != nil {
if err == models.ErrIssueNotExist { if err == models.ErrIssueNotExist {
ctx.Handle(404, "issue.UpdateIssueLabel", err) ctx.Handle(404, "issue.UpdateIssueLabel(GetIssueByIndex)", err)
} else { } else {
ctx.Handle(500, "issue.UpdateIssueLabel(GetIssueByIndex)", err) ctx.Handle(500, "issue.UpdateIssueLabel(GetIssueByIndex)", err)
} }
@ -454,6 +454,17 @@ func UpdateIssueLabel(ctx *middleware.Context, params martini.Params) {
isAttach := ctx.Query("action") == "attach" isAttach := ctx.Query("action") == "attach"
labelStrId := ctx.Query("id") 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+"|") isHad := strings.Contains(issue.LabelIds, "$"+labelStrId+"|")
isNeedUpdate := false isNeedUpdate := false
if isAttach { if isAttach {
@ -473,6 +484,22 @@ func UpdateIssueLabel(ctx *middleware.Context, params martini.Params) {
ctx.Handle(500, "issue.UpdateIssueLabel(UpdateIssue)", err) ctx.Handle(500, "issue.UpdateIssueLabel(UpdateIssue)", err)
return 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{}{ ctx.JSON(200, map[string]interface{}{
"ok": true, "ok": true,

View file

@ -17,12 +17,13 @@
<h4>Label</h4> <h4>Label</h4>
<ul class="list-unstyled" id="label-list" data-ajax="{{$.RepoLink}}/issues/labels/delete"> <ul class="list-unstyled" id="label-list" data-ajax="{{$.RepoLink}}/issues/labels/delete">
{{range .Labels}} {{range .Labels}}
<li class="label-item" id="label-{{.Id}}" data-id="{{.Id}}"><a href="#"> <li class="label-item" id="label-{{.Id}}" data-id="{{.Id}}">
<span class="pull-right count">{{if $.IsShowClosed}}{{.NumClosedIssues}}{{else}}{{.NumOpenIssues}}{{end}}</span> <a href="#">
<span class="color" style="background-color: {{.Color}}" data-color="{{.Color}}"></span> <span class="pull-right count">{{if $.IsShowClosed}}{{.NumClosedIssues}}{{else}}{{.NumOpenIssues}}{{end}}</span>
<span class="name">{{.Name}}</span> <span class="color" style="background-color: {{.Color}}" data-color="{{.Color}}"></span>
</a> <span class="name">{{.Name}}</span>
<a class="del pull-right" href="#" data-id="{{.Id}}"><i class="fa fa-times-circle-o"></i></a> </a>
<a class="del pull-right" href="#" data-id="{{.Id}}"><i class="fa fa-times-circle-o"></i></a>
</li> </li>
{{end}} {{end}}
<li class="label-change-li" style="display: none"> <li class="label-change-li" style="display: none">