summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-01-30 20:46:45 +0800
committerGitHub <noreply@github.com>2017-01-30 20:46:45 +0800
commitf94869d2d19afd7110a0b996a7e6da339fb4e161 (patch)
tree8fe91beb0dcfce8e78515ebd525ee1decb633e68 /routers
parentd078aa30d6e6f40978ea68e9ae6eee53dc028ada (diff)
downloadgitea-f94869d2d19afd7110a0b996a7e6da339fb4e161.tar.gz
gitea-f94869d2d19afd7110a0b996a7e6da339fb4e161.zip
Track labels changed on issue view & resolved #542 (#788)
* track labels changed on issue view & resolved #542 * add missing head comment & sort & fix refresh
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/issue_label.go4
-rw-r--r--routers/repo/issue.go161
-rw-r--r--routers/repo/issue_label.go170
3 files changed, 177 insertions, 158 deletions
diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go
index e91b8e9daf..20de41b758 100644
--- a/routers/api/v1/repo/issue_label.go
+++ b/routers/api/v1/repo/issue_label.go
@@ -98,7 +98,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
return
}
- if err := models.DeleteIssueLabel(issue, label); err != nil {
+ if err := models.DeleteIssueLabel(issue, ctx.User, label); err != nil {
ctx.Error(500, "DeleteIssueLabel", err)
return
}
@@ -129,7 +129,7 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
return
}
- if err := issue.ReplaceLabels(labels); err != nil {
+ if err := issue.ReplaceLabels(labels, ctx.User); err != nil {
ctx.Error(500, "ReplaceLabels", err)
return
}
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 7ae6140388..b2490e242a 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -34,8 +34,6 @@ const (
tplIssueNew base.TplName = "repo/issue/new"
tplIssueView base.TplName = "repo/issue/view"
- tplLabels base.TplName = "repo/issue/labels"
-
tplMilestone base.TplName = "repo/issue/milestones"
tplMilestoneNew base.TplName = "repo/issue/milestone_new"
tplMilestoneEdit base.TplName = "repo/issue/milestone_edit"
@@ -86,21 +84,6 @@ func MustAllowPulls(ctx *context.Context) {
}
}
-// RetrieveLabels find all the labels of a repository
-func RetrieveLabels(ctx *context.Context) {
- labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"))
- if err != nil {
- ctx.Handle(500, "RetrieveLabels.GetLabels", err)
- return
- }
- for _, l := range labels {
- l.CalOpenIssues()
- }
- ctx.Data["Labels"] = labels
- ctx.Data["NumLabels"] = len(labels)
- ctx.Data["SortType"] = ctx.Query("sort")
-}
-
// Issues render issues page
func Issues(ctx *context.Context) {
isPullList := ctx.Params(":type") == "pulls"
@@ -629,6 +612,11 @@ func ViewIssue(ctx *context.Context) {
if !isAdded && !issue.IsPoster(comment.Poster.ID) {
participants = append(participants, comment.Poster)
}
+ } else if comment.Type == models.CommentTypeLabel {
+ if err = comment.LoadLabel(); err != nil {
+ ctx.Handle(500, "LoadLabel", err)
+ return
+ }
}
}
@@ -723,48 +711,6 @@ func UpdateIssueContent(ctx *context.Context) {
})
}
-// UpdateIssueLabel change issue's labels
-func UpdateIssueLabel(ctx *context.Context) {
- issue := getActionIssue(ctx)
- if ctx.Written() {
- return
- }
-
- if ctx.Query("action") == "clear" {
- if err := issue.ClearLabels(ctx.User); err != nil {
- ctx.Handle(500, "ClearLabels", err)
- return
- }
- } else {
- isAttach := ctx.Query("action") == "attach"
- label, err := models.GetLabelByID(ctx.QueryInt64("id"))
- if err != nil {
- if models.IsErrLabelNotExist(err) {
- ctx.Error(404, "GetLabelByID")
- } else {
- ctx.Handle(500, "GetLabelByID", err)
- }
- return
- }
-
- if isAttach && !issue.HasLabel(label.ID) {
- if err = issue.AddLabel(ctx.User, label); err != nil {
- ctx.Handle(500, "AddLabel", err)
- return
- }
- } else if !isAttach && issue.HasLabel(label.ID) {
- if err = issue.RemoveLabel(ctx.User, label); err != nil {
- ctx.Handle(500, "RemoveLabel", err)
- return
- }
- }
- }
-
- ctx.JSON(200, map[string]interface{}{
- "ok": true,
- })
-}
-
// UpdateIssueMilestone change issue's milestone
func UpdateIssueMilestone(ctx *context.Context) {
issue := getActionIssue(ctx)
@@ -966,103 +912,6 @@ func DeleteComment(ctx *context.Context) {
ctx.Status(200)
}
-// Labels render issue's labels page
-func Labels(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Tr("repo.labels")
- ctx.Data["PageIsIssueList"] = true
- ctx.Data["PageIsLabels"] = true
- ctx.Data["RequireMinicolors"] = true
- ctx.Data["LabelTemplates"] = models.LabelTemplates
- ctx.HTML(200, tplLabels)
-}
-
-// InitializeLabels init labels for a repository
-func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) {
- if ctx.HasError() {
- ctx.Redirect(ctx.Repo.RepoLink + "/labels")
- return
- }
- list, err := models.GetLabelTemplateFile(form.TemplateName)
- if err != nil {
- ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, err))
- ctx.Redirect(ctx.Repo.RepoLink + "/labels")
- return
- }
-
- labels := make([]*models.Label, len(list))
- for i := 0; i < len(list); i++ {
- labels[i] = &models.Label{
- RepoID: ctx.Repo.Repository.ID,
- Name: list[i][0],
- Color: list[i][1],
- }
- }
- if err := models.NewLabels(labels...); err != nil {
- ctx.Handle(500, "NewLabels", err)
- return
- }
- ctx.Redirect(ctx.Repo.RepoLink + "/labels")
-}
-
-// NewLabel create new label for repository
-func NewLabel(ctx *context.Context, form auth.CreateLabelForm) {
- ctx.Data["Title"] = ctx.Tr("repo.labels")
- ctx.Data["PageIsLabels"] = true
-
- if ctx.HasError() {
- ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
- ctx.Redirect(ctx.Repo.RepoLink + "/labels")
- return
- }
-
- l := &models.Label{
- RepoID: ctx.Repo.Repository.ID,
- Name: form.Title,
- Color: form.Color,
- }
- if err := models.NewLabels(l); err != nil {
- ctx.Handle(500, "NewLabel", err)
- return
- }
- ctx.Redirect(ctx.Repo.RepoLink + "/labels")
-}
-
-// UpdateLabel update a label's name and color
-func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) {
- l, err := models.GetLabelByID(form.ID)
- if err != nil {
- switch {
- case models.IsErrLabelNotExist(err):
- ctx.Error(404)
- default:
- ctx.Handle(500, "UpdateLabel", err)
- }
- return
- }
-
- l.Name = form.Title
- l.Color = form.Color
- if err := models.UpdateLabel(l); err != nil {
- ctx.Handle(500, "UpdateLabel", err)
- return
- }
- ctx.Redirect(ctx.Repo.RepoLink + "/labels")
-}
-
-// DeleteLabel delete a label
-func DeleteLabel(ctx *context.Context) {
- if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
- ctx.Flash.Error("DeleteLabel: " + err.Error())
- } else {
- ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
- }
-
- ctx.JSON(200, map[string]interface{}{
- "redirect": ctx.Repo.RepoLink + "/labels",
- })
- return
-}
-
// Milestones render milestones page
func Milestones(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.milestones")
diff --git a/routers/repo/issue_label.go b/routers/repo/issue_label.go
new file mode 100644
index 0000000000..6792947669
--- /dev/null
+++ b/routers/repo/issue_label.go
@@ -0,0 +1,170 @@
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package repo
+
+import (
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/auth"
+ "code.gitea.io/gitea/modules/base"
+ "code.gitea.io/gitea/modules/context"
+)
+
+const (
+ tplLabels base.TplName = "repo/issue/labels"
+)
+
+// Labels render issue's labels page
+func Labels(ctx *context.Context) {
+ ctx.Data["Title"] = ctx.Tr("repo.labels")
+ ctx.Data["PageIsIssueList"] = true
+ ctx.Data["PageIsLabels"] = true
+ ctx.Data["RequireMinicolors"] = true
+ ctx.Data["LabelTemplates"] = models.LabelTemplates
+ ctx.HTML(200, tplLabels)
+}
+
+// InitializeLabels init labels for a repository
+func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) {
+ if ctx.HasError() {
+ ctx.Redirect(ctx.Repo.RepoLink + "/labels")
+ return
+ }
+ list, err := models.GetLabelTemplateFile(form.TemplateName)
+ if err != nil {
+ ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, err))
+ ctx.Redirect(ctx.Repo.RepoLink + "/labels")
+ return
+ }
+
+ labels := make([]*models.Label, len(list))
+ for i := 0; i < len(list); i++ {
+ labels[i] = &models.Label{
+ RepoID: ctx.Repo.Repository.ID,
+ Name: list[i][0],
+ Color: list[i][1],
+ }
+ }
+ if err := models.NewLabels(labels...); err != nil {
+ ctx.Handle(500, "NewLabels", err)
+ return
+ }
+ ctx.Redirect(ctx.Repo.RepoLink + "/labels")
+}
+
+// RetrieveLabels find all the labels of a repository
+func RetrieveLabels(ctx *context.Context) {
+ labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"))
+ if err != nil {
+ ctx.Handle(500, "RetrieveLabels.GetLabels", err)
+ return
+ }
+ for _, l := range labels {
+ l.CalOpenIssues()
+ }
+ ctx.Data["Labels"] = labels
+ ctx.Data["NumLabels"] = len(labels)
+ ctx.Data["SortType"] = ctx.Query("sort")
+}
+
+// NewLabel create new label for repository
+func NewLabel(ctx *context.Context, form auth.CreateLabelForm) {
+ ctx.Data["Title"] = ctx.Tr("repo.labels")
+ ctx.Data["PageIsLabels"] = true
+
+ if ctx.HasError() {
+ ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
+ ctx.Redirect(ctx.Repo.RepoLink + "/labels")
+ return
+ }
+
+ l := &models.Label{
+ RepoID: ctx.Repo.Repository.ID,
+ Name: form.Title,
+ Color: form.Color,
+ }
+ if err := models.NewLabels(l); err != nil {
+ ctx.Handle(500, "NewLabel", err)
+ return
+ }
+ ctx.Redirect(ctx.Repo.RepoLink + "/labels")
+}
+
+// UpdateLabel update a label's name and color
+func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) {
+ l, err := models.GetLabelByID(form.ID)
+ if err != nil {
+ switch {
+ case models.IsErrLabelNotExist(err):
+ ctx.Error(404)
+ default:
+ ctx.Handle(500, "UpdateLabel", err)
+ }
+ return
+ }
+
+ l.Name = form.Title
+ l.Color = form.Color
+ if err := models.UpdateLabel(l); err != nil {
+ ctx.Handle(500, "UpdateLabel", err)
+ return
+ }
+ ctx.Redirect(ctx.Repo.RepoLink + "/labels")
+}
+
+// DeleteLabel delete a label
+func DeleteLabel(ctx *context.Context) {
+ if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
+ ctx.Flash.Error("DeleteLabel: " + err.Error())
+ } else {
+ ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
+ }
+
+ ctx.JSON(200, map[string]interface{}{
+ "redirect": ctx.Repo.RepoLink + "/labels",
+ })
+ return
+}
+
+// UpdateIssueLabel change issue's labels
+func UpdateIssueLabel(ctx *context.Context) {
+ issue := getActionIssue(ctx)
+ if ctx.Written() {
+ return
+ }
+
+ if ctx.Query("action") == "clear" {
+ if err := issue.ClearLabels(ctx.User); err != nil {
+ ctx.Handle(500, "ClearLabels", err)
+ return
+ }
+ } else {
+ isAttach := ctx.Query("action") == "attach"
+ label, err := models.GetLabelByID(ctx.QueryInt64("id"))
+ if err != nil {
+ if models.IsErrLabelNotExist(err) {
+ ctx.Error(404, "GetLabelByID")
+ } else {
+ ctx.Handle(500, "GetLabelByID", err)
+ }
+ return
+ }
+
+ if isAttach && !issue.HasLabel(label.ID) {
+ if err = issue.AddLabel(ctx.User, label); err != nil {
+ ctx.Handle(500, "AddLabel", err)
+ return
+ }
+ } else if !isAttach && issue.HasLabel(label.ID) {
+ if err = issue.RemoveLabel(ctx.User, label); err != nil {
+ ctx.Handle(500, "RemoveLabel", err)
+ return
+ }
+ }
+ }
+
+ ctx.JSON(200, map[string]interface{}{
+ "ok": true,
+ })
+}