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.
This commit is contained in:
parent
ed5e7d03c6
commit
e57e1144c5
5 changed files with 26 additions and 6 deletions
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue