diff --git a/internal/njudge/memory/problemlist.go b/internal/njudge/memory/problemlist.go
index d9b6864..bf31cc0 100644
--- a/internal/njudge/memory/problemlist.go
+++ b/internal/njudge/memory/problemlist.go
@@ -132,6 +132,13 @@ func (p *ProblemListQuery) filterInvisible(ctx context.Context, req njudge.Probl
return true, nil
}
+func (p *ProblemListQuery) filterAuthor(ctx context.Context, req njudge.ProblemListRequest, pr njudge.Problem) (bool, error) {
+ if req.AuthorFilter != nil {
+ return strings.Contains(pr.Author, *req.AuthorFilter), nil
+ }
+ return true, nil
+}
+
func (p *ProblemListQuery) GetProblemList(ctx context.Context, req njudge.ProblemListRequest) (*njudge.ProblemList, error) {
allProblems, err := p.ps.GetAll(ctx)
if err != nil {
@@ -144,6 +151,7 @@ func (p *ProblemListQuery) GetProblemList(ctx context.Context, req njudge.Proble
p.filterTitle,
p.filterCategory,
p.filterInvisible,
+ p.filterAuthor,
}
problems := make([]njudge.Problem, 0)
diff --git a/internal/njudge/problemlist.go b/internal/njudge/problemlist.go
index db70e7f..1de786f 100644
--- a/internal/njudge/problemlist.go
+++ b/internal/njudge/problemlist.go
@@ -26,12 +26,13 @@ type ProblemListRequest struct {
PerPage int
TitleFilter string
TagFilter []string
+ AuthorFilter *string
CategoryFilter CategoryFilter
User *User
}
func (r ProblemListRequest) IsFiltered() bool {
- return r.TitleFilter != "" || len(r.TagFilter) > 0 || r.CategoryFilter.Type != CategoryFilterNone
+ return r.TitleFilter != "" || len(r.TagFilter) > 0 || r.CategoryFilter.Type != CategoryFilterNone || r.AuthorFilter != nil
}
type ProblemList struct {
diff --git a/internal/web/handlers/problemset/problemset.go b/internal/web/handlers/problemset/problemset.go
index 075ed76..d114f81 100644
--- a/internal/web/handlers/problemset/problemset.go
+++ b/internal/web/handlers/problemset/problemset.go
@@ -26,6 +26,8 @@ type ProblemListRequest struct {
TitleFilter string `query:"title"`
CategoryFilter int `query:"category"`
TagFilter string `query:"tags"`
+ FilterAuthor string `query:"filterAuthor"`
+ Author string `query:"author"`
Problemset string `param:"name"`
}
@@ -105,6 +107,10 @@ func GetProblemList(store problems.Store, ps njudge.Problems, cs njudge.Categori
User: c.Get("user").(*njudge.User),
}
+ if data.FilterAuthor == "on" {
+ listRequest.AuthorFilter = &data.Author
+ }
+
if data.TagFilter != "" {
listRequest.TagFilter = strings.Split(data.TagFilter, ",")
}
@@ -228,6 +234,8 @@ func GetProblemList(store problems.Store, ps njudge.Problems, cs njudge.Categori
result.CategoryFilterOptions = []templates.CategoryFilterOption{
{Name: "-"},
}
+ result.FilterAuthor = data.FilterAuthor == "on"
+ result.AuthorFilter = data.Author
result.CategoryFilterOptions = append(result.CategoryFilterOptions,
makeCategoryFilterOptions(tr, categories, data.CategoryFilter, categoryNameByID, par)...)
diff --git a/internal/web/templates/problemset.templ b/internal/web/templates/problemset.templ
index b1a7e08..e9adf5b 100644
--- a/internal/web/templates/problemset.templ
+++ b/internal/web/templates/problemset.templ
@@ -35,6 +35,8 @@ type ProblemListViewModel struct {
TitleFilter string
TagsFilter string
CategoryFilterOptions []CategoryFilterOption
+ FilterAuthor bool
+ AuthorFilter string
}
templ tagList(tags []njudge.Tag) {
@@ -87,6 +89,18 @@ templ problemListFilter(vm ProblemListViewModel) {
+
if vm.Filtered {
{Tr(ctx, "Clear")}
diff --git a/internal/web/templates/problemset_templ.go b/internal/web/templates/problemset_templ.go
index ef2baf4..96bbe13 100644
--- a/internal/web/templates/problemset_templ.go
+++ b/internal/web/templates/problemset_templ.go
@@ -45,6 +45,8 @@ type ProblemListViewModel struct {
TitleFilter string
TagsFilter string
CategoryFilterOptions []CategoryFilterOption
+ FilterAuthor bool
+ AuthorFilter string
}
func tagList(tags []njudge.Tag) templ.Component {
@@ -68,7 +70,7 @@ func tagList(tags []njudge.Tag) templ.Component {
var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(tag.Name)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 42, Col: 53}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 44, Col: 53}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
if templ_7745c5c3_Err != nil {
@@ -138,7 +140,7 @@ func problemListFilter(vm ProblemListViewModel) templ.Component {
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(Tr(ctx, "Filter"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 61, Col: 76}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 63, Col: 76}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
@@ -182,7 +184,7 @@ func problemListFilter(vm ProblemListViewModel) templ.Component {
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(Tr(ctx, "Title"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 70, Col: 66}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 72, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
@@ -195,7 +197,7 @@ func problemListFilter(vm ProblemListViewModel) templ.Component {
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(vm.TitleFilter)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 71, Col: 65}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 73, Col: 65}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
@@ -208,7 +210,7 @@ func problemListFilter(vm ProblemListViewModel) templ.Component {
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(Tr(ctx, "Category"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 74, Col: 72}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 76, Col: 72}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
@@ -226,7 +228,7 @@ func problemListFilter(vm ProblemListViewModel) templ.Component {
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(filterOption.Value)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 77, Col: 61}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 79, Col: 61}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
@@ -249,7 +251,7 @@ func problemListFilter(vm ProblemListViewModel) templ.Component {
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(filterOption.Name)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 77, Col: 117}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 79, Col: 117}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
@@ -267,7 +269,7 @@ func problemListFilter(vm ProblemListViewModel) templ.Component {
var templ_7745c5c3_Var14 string
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(Tr(ctx, "Tags"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 82, Col: 64}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 84, Col: 64}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil {
@@ -285,7 +287,7 @@ func problemListFilter(vm ProblemListViewModel) templ.Component {
var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(tag.Name)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 85, Col: 55}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 87, Col: 55}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
if templ_7745c5c3_Err != nil {
@@ -298,7 +300,7 @@ func problemListFilter(vm ProblemListViewModel) templ.Component {
var templ_7745c5c3_Var16 string
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(tag.Name)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 85, Col: 66}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 87, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
if templ_7745c5c3_Err != nil {
@@ -316,25 +318,74 @@ func problemListFilter(vm ProblemListViewModel) templ.Component {
var templ_7745c5c3_Var17 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(vm.TagsFilter)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 88, Col: 63}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/problemset.templ`, Line: 90, Col: 63}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"form-control\" id=\"tagsFilterHidden\" type=\"hidden\">