diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-03-29 21:41:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-29 08:41:45 -0500 |
commit | e57e1144c5ae7a2995e6818c6ae32139e563add7 (patch) | |
tree | eea2b49bef9f1469f99467b5855f74fc28274db4 /routers/web/explore | |
parent | ed5e7d03c6c44666c6fe97a15e8ce33d223c4466 (diff) | |
download | gitea-e57e1144c5ae7a2995e6818c6ae32139e563add7.tar.gz gitea-e57e1144c5ae7a2995e6818c6ae32139e563add7.zip |
Add ONLY_SHOW_RELEVANT_REPOS back, fix explore page bug, make code more strict (#23766)
Follow #21962
After I eat my own dogfood, I would say that
ONLY_SHOW_RELEVANT_REPOS=false is necessary for many private/enterprise
instances, because many private repositories do not have
"description/topic", users just want to search by their names.
This PR also adds `PageIsExploreRepositories` check, to make code more
strict, because the `search` template is shared for different purpose.
And during the test, I found a bug that the "Search" button didn't
respect the "relevant" parameter, so this PR fixes the bug by the way
together.
I think this PR needs to be backported.
Diffstat (limited to 'routers/web/explore')
-rw-r--r-- | routers/web/explore/repo.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index cc3af8cb2c..be5ad1b015 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -4,6 +4,7 @@ package explore import ( + "fmt" "net/http" "code.gitea.io/gitea/models/db" @@ -18,7 +19,7 @@ import ( const ( // tplExploreRepos explore repositories page template tplExploreRepos base.TplName = "explore/repos" - relevantReposOnlyParam string = "no_filter" + relevantReposOnlyParam string = "only_show_relevant" ) // RepoSearchOptions when calling search repositories @@ -137,7 +138,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { pager.SetDefaultParams(ctx) pager.AddParam(ctx, "topic", "TopicOnly") pager.AddParam(ctx, "language", "Language") - pager.AddParamString(relevantReposOnlyParam, ctx.FormString(relevantReposOnlyParam)) + pager.AddParamString(relevantReposOnlyParam, fmt.Sprint(opts.OnlyShowRelevant)) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, opts.TplName) @@ -156,11 +157,18 @@ func Repos(ctx *context.Context) { ownerID = ctx.Doer.ID } + onlyShowRelevant := setting.UI.OnlyShowRelevantRepos + + _ = ctx.Req.ParseForm() // parse the form first, to prepare the ctx.Req.Form field + if len(ctx.Req.Form[relevantReposOnlyParam]) != 0 { + onlyShowRelevant = ctx.FormBool(relevantReposOnlyParam) + } + RenderRepoSearch(ctx, &RepoSearchOptions{ PageSize: setting.UI.ExplorePagingNum, OwnerID: ownerID, Private: ctx.Doer != nil, TplName: tplExploreRepos, - OnlyShowRelevant: !ctx.FormBool(relevantReposOnlyParam), + OnlyShowRelevant: onlyShowRelevant, }) } |