diff options
author | Lauris BH <lauris@nix.lv> | 2019-01-23 06:10:38 +0200 |
---|---|---|
committer | techknowlogick <matti@mdranta.net> | 2019-01-22 23:10:38 -0500 |
commit | 075649572d4472b588a8484ce3d7c37df7621f85 (patch) | |
tree | 5658dfda46b32c0686895615bceffbdac01ef4a3 /routers | |
parent | 6a949af8ca3aaa30f917c8ed792ae88bbaafdd75 (diff) | |
download | gitea-075649572d4472b588a8484ce3d7c37df7621f85.tar.gz gitea-075649572d4472b588a8484ce3d7c37df7621f85.zip |
Add the ability to use multiple labels as filters(#5786)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/issue.go | 15 | ||||
-rw-r--r-- | routers/routes/routes.go | 2 | ||||
-rw-r--r-- | routers/user/home.go | 12 |
3 files changed, 25 insertions, 4 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 8e0b22eb62..588e727ca4 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -112,8 +112,15 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB } repo := ctx.Repo.Repository + var labelIDs []int64 selectLabels := ctx.Query("labels") - + if len(selectLabels) > 0 && selectLabels != "0" { + labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ",")) + if err != nil { + ctx.ServerError("StringsToInt64s", err) + return + } + } isShowClosed := ctx.Query("state") == "closed" keyword := strings.Trim(ctx.Query("q"), " ") @@ -176,7 +183,7 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB PageSize: setting.UI.IssuePagingNum, IsClosed: util.OptionalBoolOf(isShowClosed), IsPull: isPullOption, - Labels: selectLabels, + LabelIDs: labelIDs, SortType: sortType, IssueIDs: issueIDs, }) @@ -210,7 +217,11 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB ctx.ServerError("GetLabelsByRepoID", err) return } + for _, l := range labels { + l.LoadSelectedLabelsAfterClick(labelIDs) + } ctx.Data["Labels"] = labels + ctx.Data["NumLabels"] = len(labels) if ctx.QueryInt64("assignee") == 0 { assigneeID = 0 // Reset ID to prevent unexpected selection of assignee. diff --git a/routers/routes/routes.go b/routers/routes/routes.go index afbb31d780..a3bf3f753a 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -656,7 +656,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/:username/:reponame", func() { m.Group("", func() { - m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues) + m.Get("/^:type(issues|pulls)$", repo.Issues) m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue) m.Get("/labels/", reqRepoIssuesOrPullsReader, repo.RetrieveLabels, repo.Labels) m.Get("/milestones", reqRepoIssuesOrPullsReader, repo.Milestones) diff --git a/routers/user/home.go b/routers/user/home.go index 883adf4e6c..daa58b2604 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -8,6 +8,7 @@ import ( "bytes" "fmt" "sort" + "strings" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" @@ -256,7 +257,16 @@ func Issues(ctx *context.Context) { opts.Page = page opts.PageSize = setting.UI.IssuePagingNum - opts.Labels = ctx.Query("labels") + var labelIDs []int64 + selectLabels := ctx.Query("labels") + if len(selectLabels) > 0 && selectLabels != "0" { + labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ",")) + if err != nil { + ctx.ServerError("StringsToInt64s", err) + return + } + } + opts.LabelIDs = labelIDs issues, err := models.Issues(opts) if err != nil { |