Skip to content

Commit

Permalink
Add ONLY_SHOW_RELEVANT_REPOS back, fix explore page bug, make code mo…
Browse files Browse the repository at this point in the history
…re strict (go-gitea#23766)

Follow go-gitea#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.
# Conflicts:
#	templates/explore/repo_search.tmpl
  • Loading branch information
wxiaoguang committed Mar 29, 2023
1 parent 81a995c commit ed2466b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,10 @@ ROUTER = console
;;
;; Whether to enable a Service Worker to cache frontend assets
;USE_SERVICE_WORKER = false
;;
;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
;ONLY_SHOW_RELEVANT_REPOS = false

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
4 changes: 3 additions & 1 deletion docs/content/doc/administration/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ The following configuration set `Content-Type: application/vnd.android.package-a
Values can be emoji alias (:smile:) or a unicode emoji.
For custom reactions, add a tightly cropped square image to public/img/emoji/reaction_name.png
- `CUSTOM_EMOJIS`: **gitea, codeberg, gitlab, git, github, gogs**: Additional Emojis not defined in the utf8 standard.
By default we support Gitea (:gitea:), to add more copy them to public/img/emoji/emoji_name.png and
By default, we support Gitea (:gitea:), to add more copy them to public/img/emoji/emoji_name.png and
add it to this config.
- `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used.
- `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page.
- `USE_SERVICE_WORKER`: **false**: Whether to enable a Service Worker to cache frontend assets.
- `ONLY_SHOW_RELEVANT_REPOS`: **false** Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).

### UI - Admin (`ui.admin`)

Expand Down
3 changes: 3 additions & 0 deletions modules/setting/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ func loadUIFrom(rootCfg ConfigProvider) {
UI.DefaultShowFullName = sec.Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
UI.SearchRepoDescription = sec.Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
UI.UseServiceWorker = sec.Key("USE_SERVICE_WORKER").MustBool(false)

// OnlyShowRelevantRepos=false is important for many private/enterprise instances,
// because many private repositories do not have "description/topic", users just want to search by their names.
UI.OnlyShowRelevantRepos = sec.Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)

UI.ReactionsLookup = make(container.Set[string])
Expand Down
14 changes: 11 additions & 3 deletions routers/web/explore/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package explore

import (
"fmt"
"net/http"

"code.gitea.io/gitea/models/db"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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,
})
}
7 changes: 5 additions & 2 deletions templates/explore/repo_search.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
<input type="hidden" name="language" value="{{$.Language}}">
<div class="ui fluid action input">
<input name="q" value="{{.Keyword}}" placeholder="{{.locale.Tr "explore.search"}}" autofocus>
{{if .PageIsExploreRepositories}}
<input type="hidden" name="only_show_relevant" value="{{.OnlyShowRelevant}}">
{{end}}
<button class="ui primary button">{{.locale.Tr "explore.search"}}</button>
</div>
</form>
{{if .OnlyShowRelevant}}
{{if and .PageIsExploreRepositories .OnlyShowRelevant}}
<div class="ui message explore-relevancy-note">
<span class="ui tooltip" data-content="{{.locale.Tr "explore.relevant_repositories_tooltip"}}">{{.locale.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?no_filter=1")|Escape) | Safe}}</span>
<span class="ui tooltip" data-content="{{.locale.Tr "explore.relevant_repositories_tooltip"}}">{{.locale.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?only_show_relevant=0")|Escape) | Safe}}</span>
</div>
{{end}}
<div class="ui divider"></div>

0 comments on commit ed2466b

Please sign in to comment.