Skip to content

Commit

Permalink
Filter Repositories by type (#29231)
Browse files Browse the repository at this point in the history
  • Loading branch information
zokkis authored Mar 3, 2024
1 parent e71b692 commit e3524c6
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 77 deletions.
13 changes: 13 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ confirm_delete_selected = Confirm to delete all selected items?
name = Name
value = Value

filter = Filter
filter.clear = Clear Filter
filter.is_archived = Archived
filter.not_archived = Not Archived
filter.is_fork = Forked
filter.not_fork = Not Forked
filter.is_mirror = Mirrored
filter.not_mirror = Not Mirrored
filter.is_template = Template
filter.not_template = Not Template
filter.public = Public
filter.private = Private

[aria]
navbar = Navigation Bar
footer = Footer
Expand Down
20 changes: 20 additions & 0 deletions routers/web/explore/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
language := ctx.FormTrim("language")
ctx.Data["Language"] = language

archived := ctx.FormOptionalBool("archived")
ctx.Data["IsArchived"] = archived

fork := ctx.FormOptionalBool("fork")
ctx.Data["IsFork"] = fork

mirror := ctx.FormOptionalBool("mirror")
ctx.Data["IsMirror"] = mirror

template := ctx.FormOptionalBool("template")
ctx.Data["IsTemplate"] = template

private := ctx.FormOptionalBool("private")
ctx.Data["IsPrivate"] = private

repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{
Page: page,
Expand All @@ -125,6 +140,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
OnlyShowRelevant: opts.OnlyShowRelevant,
Archived: archived,
Fork: fork,
Mirror: mirror,
Template: template,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand Down
20 changes: 20 additions & 0 deletions routers/web/org/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ func Home(ctx *context.Context) {
page = 1
}

archived := ctx.FormOptionalBool("archived")
ctx.Data["IsArchived"] = archived

fork := ctx.FormOptionalBool("fork")
ctx.Data["IsFork"] = fork

mirror := ctx.FormOptionalBool("mirror")
ctx.Data["IsMirror"] = mirror

template := ctx.FormOptionalBool("template")
ctx.Data["IsTemplate"] = template

private := ctx.FormOptionalBool("private")
ctx.Data["IsPrivate"] = private

var (
repos []*repo_model.Repository
count int64
Expand All @@ -102,6 +117,11 @@ func Home(ctx *context.Context) {
Actor: ctx.Doer,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
Archived: archived,
Fork: fork,
Mirror: mirror,
Template: template,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand Down
20 changes: 20 additions & 0 deletions routers/web/user/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,21 @@ func NotificationWatching(ctx *context.Context) {
orderBy = db.SearchOrderByRecentUpdated
}

archived := ctx.FormOptionalBool("archived")
ctx.Data["IsArchived"] = archived

fork := ctx.FormOptionalBool("fork")
ctx.Data["IsFork"] = fork

mirror := ctx.FormOptionalBool("mirror")
ctx.Data["IsMirror"] = mirror

template := ctx.FormOptionalBool("template")
ctx.Data["IsTemplate"] = template

private := ctx.FormOptionalBool("private")
ctx.Data["IsPrivate"] = private

repos, count, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Expand All @@ -402,6 +417,11 @@ func NotificationWatching(ctx *context.Context) {
Collaborate: optional.Some(false),
TopicOnly: ctx.FormBool("topic"),
IncludeDescription: setting.UI.SearchRepoDescription,
Archived: archived,
Fork: fork,
Mirror: mirror,
Template: template,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand Down
30 changes: 30 additions & 0 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
}
ctx.Data["NumFollowing"] = numFollowing

archived := ctx.FormOptionalBool("archived")
ctx.Data["IsArchived"] = archived

fork := ctx.FormOptionalBool("fork")
ctx.Data["IsFork"] = fork

mirror := ctx.FormOptionalBool("mirror")
ctx.Data["IsMirror"] = mirror

template := ctx.FormOptionalBool("template")
ctx.Data["IsTemplate"] = template

private := ctx.FormOptionalBool("private")
ctx.Data["IsPrivate"] = private

switch tab {
case "followers":
ctx.Data["Cards"] = followers
Expand Down Expand Up @@ -208,6 +223,11 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
Archived: archived,
Fork: fork,
Mirror: mirror,
Template: template,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand All @@ -230,6 +250,11 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
Archived: archived,
Fork: fork,
Mirror: mirror,
Template: template,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand Down Expand Up @@ -275,6 +300,11 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
Archived: archived,
Fork: fork,
Mirror: mirror,
Template: template,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/repo/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
</h4>
<div class="ui attached segment">
{{template "admin/repo/search" .}}
{{template "shared/repo_search" .}}
</div>
<div class="ui attached table segment">
<table class="ui very basic striped table unstackable">
Expand Down
29 changes: 0 additions & 29 deletions templates/admin/repo/search.tmpl

This file was deleted.

42 changes: 0 additions & 42 deletions templates/explore/repo_search.tmpl

This file was deleted.

2 changes: 1 addition & 1 deletion templates/explore/repos.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div role="main" aria-label="{{.Title}}" class="page-content explore repositories">
{{template "explore/navbar" .}}
<div class="ui container">
{{template "explore/repo_search" .}}
{{template "shared/repo_search" .}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/org/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{if .ProfileReadme}}
<div id="readme_profile" class="markup">{{.ProfileReadme}}</div>
{{end}}
{{template "explore/repo_search" .}}
{{template "shared/repo_search" .}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>
Expand Down
67 changes: 67 additions & 0 deletions templates/shared/repo_search.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<div class="ui secondary filter menu">
<form id="repo-search-form" class="ui form ignore-dirty tw-flex-1 tw-flex tw-flex-row tw-gap-x-2">
{{if .Language}}<input hidden name="language" value="{{.Language}}">{{end}}
<div class="ui fluid action input tw-flex-1">
{{template "shared/searchinput" dict "Value" .Keyword}}
{{if .PageIsExploreRepositories}}
<input type="hidden" name="only_show_relevant" value="{{.OnlyShowRelevant}}">
{{else if .TabName}}
<input type="hidden" name="tab" value="{{.TabName}}">
{{end}}
<button class="ui primary button">{{ctx.Locale.Tr "explore.search"}}</button>
</div>
<!-- Filter -->
<div class="ui dropdown type jump item tw-mr-0">
<span class="text">
{{ctx.Locale.Tr "filter"}}
</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<label class="item"><input type="radio" name="clear-filter"> {{ctx.Locale.Tr "filter.clear"}}</label>
<div class="divider"></div>
<label class="item"><input type="radio" name="archived" {{if .IsArchived.Value}}checked{{end}} value="1"> {{ctx.Locale.Tr "filter.is_archived"}}</label>
<label class="item"><input type="radio" name="archived" {{if (not (.IsArchived.ValueOrDefault true))}}checked{{end}} value="0"> {{ctx.Locale.Tr "filter.not_archived"}}</label>
<div class="divider"></div>
<label class="item"><input type="radio" name="fork" {{if .IsFork.Value}}checked{{end}} value="1"> {{ctx.Locale.Tr "filter.is_fork"}}</label>
<label class="item"><input type="radio" name="fork" {{if (not (.IsFork.ValueOrDefault true))}}checked{{end}} value="0"> {{ctx.Locale.Tr "filter.not_fork"}}</label>
<div class="divider"></div>
<label class="item"><input type="radio" name="mirror" {{if .IsMirror.Value}}checked{{end}} value="1"> {{ctx.Locale.Tr "filter.is_mirror"}}</label>
<label class="item"><input type="radio" name="mirror" {{if (not (.IsMirror.ValueOrDefault true))}}checked{{end}} value="0"> {{ctx.Locale.Tr "filter.not_mirror"}}</label>
<div class="divider"></div>
<label class="item"><input type="radio" name="template" {{if .IsTemplate.Value}}checked{{end}} value="1"> {{ctx.Locale.Tr "filter.is_template"}}</label>
<label class="item"><input type="radio" name="template" {{if (not (.IsTemplate.ValueOrDefault true))}}checked{{end}} value="0"> {{ctx.Locale.Tr "filter.not_template"}}</label>
<div class="divider"></div>
<label class="item"><input type="radio" name="private" {{if .IsPrivate.Value}}checked{{end}} value="1"> {{ctx.Locale.Tr "filter.private"}}</label>
<label class="item"><input type="radio" name="private" {{if (not (.IsPrivate.ValueOrDefault true))}}checked{{end}} value="0"> {{ctx.Locale.Tr "filter.public"}}</label>
</div>
</div>
<!-- Sort -->
<div class="ui dropdown type jump item gt-mr-0">
<span class="text">
{{ctx.Locale.Tr "repo.issues.filter_sort"}}
</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<label class="{{if eq .SortType "newest"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "newest"}}checked{{end}} value="newest"> {{ctx.Locale.Tr "repo.issues.filter_sort.latest"}}</label>
<label class="{{if eq .SortType "oldest"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "oldest"}}checked{{end}} value="oldest"> {{ctx.Locale.Tr "repo.issues.filter_sort.oldest"}}</label>
<label class="{{if eq .SortType "alphabetically"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "alphabetically"}}checked{{end}} value="alphabetically"> {{ctx.Locale.Tr "repo.issues.label.filter_sort.alphabetically"}}</label>
<label class="{{if eq .SortType "reversealphabetically"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "reversealphabetically"}}checked{{end}} value="reversealphabetically"> {{ctx.Locale.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</label>
<label class="{{if eq .SortType "recentupdate"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "recentupdate"}}checked{{end}} value="recentupdate"> {{ctx.Locale.Tr "repo.issues.filter_sort.recentupdate"}}</label>
<label class="{{if eq .SortType "leastupdate"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "leastupdate"}}checked{{end}} value="leastupdate"> {{ctx.Locale.Tr "repo.issues.filter_sort.leastupdate"}}</label>
{{if not .DisableStars}}
<label class="{{if eq .SortType "moststars"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "moststars"}}checked{{end}} value="moststars"> {{ctx.Locale.Tr "repo.issues.filter_sort.moststars"}}</label>
<label class="{{if eq .SortType "feweststars"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "feweststars"}}checked{{end}} value="feweststars"> {{ctx.Locale.Tr "repo.issues.filter_sort.feweststars"}}</label>
{{end}}
<label class="{{if eq .SortType "mostforks"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "mostforks"}}checked{{end}} value="mostforks"> {{ctx.Locale.Tr "repo.issues.filter_sort.mostforks"}}</label>
<label class="{{if eq .SortType "fewestforks"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "fewestforks"}}checked{{end}} value="fewestforks"> {{ctx.Locale.Tr "repo.issues.filter_sort.fewestforks"}}</label>
<label class="{{if eq .SortType "size"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "size"}}checked{{end}} value="size"> {{ctx.Locale.Tr "repo.issues.label.filter_sort.by_size"}}</label>
<label class="{{if eq .SortType "reversesize"}}active {{end}}item"><input hidden type="radio" name="sort" {{if eq .SortType "reversesize"}}checked{{end}} value="reversesize"> {{ctx.Locale.Tr "repo.issues.label.filter_sort.reverse_by_size"}}</label>
</div>
</div>
</form>
</div>
{{if and .PageIsExploreRepositories .OnlyShowRelevant}}
<div class="ui message explore-relevancy-note">
<span data-tooltip-content="{{ctx.Locale.Tr "explore.relevant_repositories_tooltip"}}">{{ctx.Locale.Tr "explore.relevant_repositories" (printf "?only_show_relevant=0&sort=%s&q=%s&language=%s" $.SortType (QueryEscape $.Keyword) (QueryEscape $.Language))}}</span>
</div>
{{end}}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{{template "shared/issuelist" dict "." . "listType" "dashboard"}}
{{end}}
{{else}}
{{template "explore/repo_search" .}}
{{template "shared/repo_search" .}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
{{end}}
Expand Down
4 changes: 2 additions & 2 deletions templates/user/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{{template "user/dashboard/feeds" .}}
{{else if eq .TabName "stars"}}
<div class="stars">
{{template "explore/repo_search" .}}
{{template "shared/repo_search" .}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>
Expand All @@ -31,7 +31,7 @@
{{else if eq .TabName "overview"}}
<div id="readme_profile" class="markup">{{.ProfileReadme}}</div>
{{else}}
{{template "explore/repo_search" .}}
{{template "shared/repo_search" .}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
{{end}}
Expand Down
Loading

0 comments on commit e3524c6

Please sign in to comment.