Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter Repositories by type #29231

Merged
merged 25 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
04c51f9
feature: filter repositories by type
zokkis Feb 18, 2024
3c386fd
i18n: moved translations
zokkis Feb 18, 2024
5310843
chore: shorten ev variable name
zokkis Feb 18, 2024
9d339f6
refactor: removed unused template
zokkis Feb 18, 2024
3ab87b6
style: remove divider
zokkis Feb 18, 2024
f77def7
i18n: clear filter
zokkis Feb 21, 2024
cc9971b
enhance: added template filter
zokkis Feb 21, 2024
21d32d4
i18n: template filter
zokkis Feb 21, 2024
45c5635
Merge branch 'main' into feature/filter-repo-by-type
6543 Feb 21, 2024
11f8cd9
PathEscape
zokkis Feb 22, 2024
30d9f02
lint: corrected
zokkis Feb 22, 2024
466ea37
escaping
zokkis Feb 25, 2024
f8560f1
Merge branch 'main' into feature/filter-repo-by-type
zokkis Feb 25, 2024
d4291fb
review fix
zokkis Feb 26, 2024
ae846c1
correct escaping
zokkis Feb 27, 2024
6662065
use form for search instead of printf
zokkis Feb 27, 2024
fc8a646
Merge branch 'main' into feature/filter-repo-by-type
6543 Feb 28, 2024
618c63f
convert as repo_model.SearchRepoOptions should be addressed seperatly
6543 Feb 28, 2024
e0fd398
adjust template
6543 Feb 28, 2024
86d0304
Merge branch 'main' into feature/filter-repo-by-type
6543 Feb 28, 2024
f1b518e
Merge branch 'main' into feature/filter-repo-by-type
zokkis Feb 29, 2024
3912ff0
Merge branch 'main' into feature/filter-repo-by-type
6543 Mar 3, 2024
9a553c1
switch to follow order above
6543 Mar 3, 2024
6acd87d
adjust to latest refactors
6543 Mar 3, 2024
fe7830b
Merge branch 'main' into feature/filter-repo-by-type
6543 Mar 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ confirm_delete_selected = Confirm to delete all selected items?
name = Name
value = Value

filter = Filter
filter.reset = Reset Filter
zokkis marked this conversation as resolved.
Show resolved Hide resolved
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.public = Public
filter.private = Private

[aria]
navbar = Navigation Bar
footer = Footer
Expand Down
16 changes: 16 additions & 0 deletions routers/web/explore/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ 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

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 +137,10 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
OnlyShowRelevant: opts.OnlyShowRelevant,
Archived: archived,
Fork: fork,
Mirror: mirror,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand Down
16 changes: 16 additions & 0 deletions routers/web/org/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ 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

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

var (
repos []*repo_model.Repository
count int64
Expand All @@ -114,6 +126,10 @@ func Home(ctx *context.Context) {
Actor: ctx.Doer,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
Archived: archived,
Fork: fork,
Mirror: mirror,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand Down
16 changes: 16 additions & 0 deletions routers/web/user/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,18 @@ 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

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 +414,10 @@ func NotificationWatching(ctx *context.Context) {
Collaborate: util.OptionalBoolFalse,
TopicOnly: ctx.FormBool("topic"),
IncludeDescription: setting.UI.SearchRepoDescription,
Archived: archived,
Fork: fork,
Mirror: mirror,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand Down
24 changes: 24 additions & 0 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ 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

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

switch tab {
case "followers":
ctx.Data["Cards"] = followers
Expand Down Expand Up @@ -207,6 +219,10 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
Archived: archived,
Fork: fork,
Mirror: mirror,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand All @@ -229,6 +245,10 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
Archived: archived,
Fork: fork,
Mirror: mirror,
IsPrivate: private,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand Down Expand Up @@ -274,6 +294,10 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
Archived: archived,
Fork: fork,
Mirror: mirror,
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" .}}
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
</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 @@ -39,7 +39,7 @@
{{if .ProfileReadme}}
<div id="readme_profile" class="markup">{{.ProfileReadme | Str2html}}</div>
{{end}}
{{template "explore/repo_search" .}}
{{template "shared/repo_search" .}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>
Expand Down
72 changes: 72 additions & 0 deletions templates/shared/repo_search.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<div class="ui secondary filter menu gt-ac gt-mx-0">
<form class="ui form ignore-dirty gt-f1">
<input type="hidden" name="sort" value="{{$.SortType}}">
<input type="hidden" name="language" value="{{$.Language}}">
<div class="ui fluid action input">
{{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>
</form>
{{$tabQuery := printf "tab=%s&" .TabName}}
zokkis marked this conversation as resolved.
Show resolved Hide resolved
{{if not .TabName}}{{$tabQuery = ""}}{{end}}
{{$languageQuery := printf "language=%s&" .Language}}
{{if not .TabName}}{{$languageQuery = ""}}{{end}}
{{$queryParams := printf "%s%sq=%s" $tabQuery $languageQuery .Keyword}}
zokkis marked this conversation as resolved.
Show resolved Hide resolved
<!-- Filter -->
{{$queryParamsWithSort := printf "%s&sort=%s" $queryParams .SortType}}
<form class="ui form ignore-dirty" id="repo-search-form" data-query-params="{{$queryParamsWithSort}}">
zokkis marked this conversation as resolved.
Show resolved Hide resolved
<div class="ui dropdown type jump item gt-mr-0">
<span class="text">
{{ctx.Locale.Tr "filter"}}
</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<a class="item" href="{{printf "%s?%s" .Link $queryParamsWithSort}}">{{ctx.Locale.Tr "filter.reset"}}</a>
<div class="divider"></div>
<label class="item no-blur"><input type="radio" name="archived" {{if .IsArchived.IsTrue}}checked{{end}} value="1"> {{ctx.Locale.Tr "filter.is_archived"}}</label>
<label class="item no-blur"><input type="radio" name="archived" {{if .IsArchived.IsFalse}}checked{{end}} value="0"> {{ctx.Locale.Tr "filter.not_archived"}}</label>
<div class="divider"></div>
<label class="item no-blur"><input type="radio" name="fork" {{if .IsFork.IsTrue}}checked{{end}} value="1"> {{ctx.Locale.Tr "filter.is_fork"}}</label>
<label class="item no-blur"><input type="radio" name="fork" {{if .IsFork.IsFalse}}checked{{end}} value="0"> {{ctx.Locale.Tr "filter.not_fork"}}</label>
<div class="divider"></div>
<label class="item no-blur"><input type="radio" name="mirror" {{if .IsMirror.IsTrue}}checked{{end}} value="1"> {{ctx.Locale.Tr "filter.is_mirror"}}</label>
<label class="item no-blur"><input type="radio" name="mirror" {{if .IsMirror.IsFalse}}checked{{end}} value="0"> {{ctx.Locale.Tr "filter.not_mirror"}}</label>
<div class="divider"></div>
<label class="item no-blur"><input type="radio" name="private" {{if .IsPrivate.IsFalse}}checked{{end}} value="0"> {{ctx.Locale.Tr "filter.public"}}</label>
<label class="item no-blur"><input type="radio" name="private" {{if .IsPrivate.IsTrue}}checked{{end}} value="1"> {{ctx.Locale.Tr "filter.private"}}</label>
</div>
</div>
</form>
<!-- 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">
{{$href := printf "%s?%s" .Link $queryParams}}
<a class="{{if eq .SortType "newest"}}active {{end}}item" href="{{$href}}&sort=newest">{{ctx.Locale.Tr "repo.issues.filter_sort.latest"}}</a>
<a class="{{if eq .SortType "oldest"}}active {{end}}item" href="{{$href}}&sort=oldest">{{ctx.Locale.Tr "repo.issues.filter_sort.oldest"}}</a>
<a class="{{if eq .SortType "alphabetically"}}active {{end}}item" href="{{$href}}&sort=alphabetically">{{ctx.Locale.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
<a class="{{if eq .SortType "reversealphabetically"}}active {{end}}item" href="{{$href}}&sort=reversealphabetically">{{ctx.Locale.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
<a class="{{if eq .SortType "recentupdate"}}active {{end}}item" href="{{$href}}&sort=recentupdate">{{ctx.Locale.Tr "repo.issues.filter_sort.recentupdate"}}</a>
<a class="{{if eq .SortType "leastupdate"}}active {{end}}item" href="{{$href}}&sort=leastupdate">{{ctx.Locale.Tr "repo.issues.filter_sort.leastupdate"}}</a>
{{if not .DisableStars}}
<a class="{{if eq .SortType "moststars"}}active {{end}}item" href="{{$href}}&sort=moststars">{{ctx.Locale.Tr "repo.issues.filter_sort.moststars"}}</a>
<a class="{{if eq .SortType "feweststars"}}active {{end}}item" href="{{$href}}&sort=feweststars">{{ctx.Locale.Tr "repo.issues.filter_sort.feweststars"}}</a>
{{end}}
<a class="{{if eq .SortType "mostforks"}}active {{end}}item" href="{{$href}}&sort=mostforks">{{ctx.Locale.Tr "repo.issues.filter_sort.mostforks"}}</a>
<a class="{{if eq .SortType "fewestforks"}}active {{end}}item" href="{{$href}}&sort=fewestforks">{{ctx.Locale.Tr "repo.issues.filter_sort.fewestforks"}}</a>
</div>
</div>
</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))|Escape) | Safe}}</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 | Str2html}}</div>
{{else}}
{{template "explore/repo_search" .}}
{{template "shared/repo_search" .}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
{{end}}
Expand Down
15 changes: 15 additions & 0 deletions web_src/js/features/repo-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function initRepositorySearch() {
const repositorySearchForm = document.querySelector('#repo-search-form');
if (!repositorySearchForm) return;

for (const radio of repositorySearchForm.querySelectorAll('input[type=radio]')) {
radio.addEventListener('click', (e) => {
e.preventDefault();

const formData = new FormData(repositorySearchForm);
const params = new URLSearchParams(formData);
const otherQueryParams = repositorySearchForm.getAttribute('data-query-params');
window.location.search = `${otherQueryParams}&${params.toString()}`;
});
}
}
2 changes: 2 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import {initCommonIssueListQuickGoto} from './features/common-issue-list.js';
import {initRepoContributors} from './features/contributors.js';
import {initRepoDiffCommitBranchesAndTags} from './features/repo-diff-commit.js';
import {initDirAuto} from './modules/dirauto.js';
import {initRepositorySearch} from './features/repo-search.js';

// Init Gitea's Fomantic settings
initGiteaFomantic();
Expand Down Expand Up @@ -174,6 +175,7 @@ onDomReady(() => {
initRepository();
initRepositoryActionView();
initRepoContributors();
initRepositorySearch();

initCommitStatuses();
initCaptcha();
Expand Down
Loading