add label filters in org/{org_name}/issues
This commit is contained in:
parent
ba35934824
commit
8d13ed4a8d
7 changed files with 169 additions and 59 deletions
|
@ -538,6 +538,36 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
|||
}
|
||||
}
|
||||
|
||||
if org != nil {
|
||||
// Get Org Labels
|
||||
labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByOrgID", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Get the exclusive scope for every label ID
|
||||
labelExclusiveScopes := make([]string, 0, len(opts.LabelIDs))
|
||||
for _, labelID := range opts.LabelIDs {
|
||||
foundExclusiveScope := false
|
||||
for _, label := range labels {
|
||||
if label.ID == labelID || label.ID == -labelID {
|
||||
labelExclusiveScopes = append(labelExclusiveScopes, label.ExclusiveScope())
|
||||
foundExclusiveScope = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundExclusiveScope {
|
||||
labelExclusiveScopes = append(labelExclusiveScopes, "")
|
||||
}
|
||||
}
|
||||
|
||||
for _, l := range labels {
|
||||
l.LoadSelectedLabelsAfterClick(opts.LabelIDs, labelExclusiveScopes)
|
||||
}
|
||||
ctx.Data["Labels"] = labels
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
// Get issues as defined by opts.
|
||||
// ------------------------------
|
||||
|
@ -621,6 +651,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
|||
ctx.Data["SortType"] = sortType
|
||||
ctx.Data["IsShowClosed"] = isShowClosed
|
||||
ctx.Data["SelectLabels"] = selectedLabels
|
||||
ctx.Data["PageIsOrgIssues"] = org != nil
|
||||
|
||||
if isShowClosed {
|
||||
ctx.Data["State"] = "closed"
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -130,3 +131,36 @@ func TestDashboardPagination(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Contains(t, out, `<a class=" item navigation" href="/?page=2">`)
|
||||
}
|
||||
|
||||
func TestOrgLabels(t *testing.T) {
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
|
||||
ctx, _ := contexttest.MockContext(t, "org/org3/issues")
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadOrganization(t, ctx, 3)
|
||||
Issues(ctx)
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
|
||||
assert.True(t, ctx.Data["PageIsOrgIssues"].(bool))
|
||||
|
||||
orgLabels := []struct {
|
||||
ID int64
|
||||
OrgID int64
|
||||
Name string
|
||||
}{
|
||||
{3, 3, "orglabel3"},
|
||||
{4, 3, "orglabel4"},
|
||||
}
|
||||
|
||||
labels, ok := ctx.Data["Labels"].([]*issues_model.Label)
|
||||
|
||||
assert.True(t, ok)
|
||||
|
||||
if assert.Len(t, labels, len(orgLabels)) {
|
||||
for i, label := range labels {
|
||||
assert.EqualValues(t, orgLabels[i].OrgID, label.OrgID)
|
||||
assert.EqualValues(t, orgLabels[i].ID, label.ID)
|
||||
assert.EqualValues(t, orgLabels[i].Name, label.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue