Skip to content

Commit 04c51f9

Browse files
committed
feature: filter repositories by type
1 parent 658cbdd commit 04c51f9

File tree

14 files changed

+178
-48
lines changed

14 files changed

+178
-48
lines changed

options/locale/locale_en-US.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,16 @@ issues.filter_milestones = Filter Milestone
13581358
issues.filter_projects = Filter Project
13591359
issues.filter_labels = Filter Label
13601360
issues.filter_reviewers = Filter Reviewer
1361+
issues.filter = Filter
1362+
issues.filter.reset = Reset Filter
1363+
issues.filter.is_archived = Archived
1364+
issues.filter.not_archived = Not Archived
1365+
issues.filter.is_fork = Forked
1366+
issues.filter.not_fork = Not Forked
1367+
issues.filter.is_mirror = Mirrored
1368+
issues.filter.not_mirror = Not Mirrored
1369+
issues.filter.public = Public
1370+
issues.filter.private = Private
13611371
issues.new = New Issue
13621372
issues.new.title_empty = Title cannot be empty
13631373
issues.new.labels = Labels

routers/web/explore/repo.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
109109
language := ctx.FormTrim("language")
110110
ctx.Data["Language"] = language
111111

112+
archived := ctx.FormOptionalBool("archived")
113+
ctx.Data["IsArchived"] = archived
114+
115+
fork := ctx.FormOptionalBool("fork")
116+
ctx.Data["IsFork"] = fork
117+
118+
mirror := ctx.FormOptionalBool("mirror")
119+
ctx.Data["IsMirror"] = mirror
120+
121+
private := ctx.FormOptionalBool("private")
122+
ctx.Data["IsPrivate"] = private
123+
112124
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
113125
ListOptions: db.ListOptions{
114126
Page: page,
@@ -125,6 +137,10 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
125137
Language: language,
126138
IncludeDescription: setting.UI.SearchRepoDescription,
127139
OnlyShowRelevant: opts.OnlyShowRelevant,
140+
Archived: archived,
141+
Fork: fork,
142+
Mirror: mirror,
143+
IsPrivate: private,
128144
})
129145
if err != nil {
130146
ctx.ServerError("SearchRepository", err)

routers/web/org/home.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ func Home(ctx *context.Context) {
9797
page = 1
9898
}
9999

100+
archived := ctx.FormOptionalBool("archived")
101+
ctx.Data["IsArchived"] = archived
102+
103+
fork := ctx.FormOptionalBool("fork")
104+
ctx.Data["IsFork"] = fork
105+
106+
mirror := ctx.FormOptionalBool("mirror")
107+
ctx.Data["IsMirror"] = mirror
108+
109+
private := ctx.FormOptionalBool("private")
110+
ctx.Data["IsPrivate"] = private
111+
100112
var (
101113
repos []*repo_model.Repository
102114
count int64
@@ -114,6 +126,10 @@ func Home(ctx *context.Context) {
114126
Actor: ctx.Doer,
115127
Language: language,
116128
IncludeDescription: setting.UI.SearchRepoDescription,
129+
Archived: archived,
130+
Fork: fork,
131+
Mirror: mirror,
132+
IsPrivate: private,
117133
})
118134
if err != nil {
119135
ctx.ServerError("SearchRepository", err)

routers/web/user/notification.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,18 @@ func NotificationWatching(ctx *context.Context) {
389389
orderBy = db.SearchOrderByRecentUpdated
390390
}
391391

392+
archived := ctx.FormOptionalBool("archived")
393+
ctx.Data["IsArchived"] = archived
394+
395+
fork := ctx.FormOptionalBool("fork")
396+
ctx.Data["IsFork"] = fork
397+
398+
mirror := ctx.FormOptionalBool("mirror")
399+
ctx.Data["IsMirror"] = mirror
400+
401+
private := ctx.FormOptionalBool("private")
402+
ctx.Data["IsPrivate"] = private
403+
392404
repos, count, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
393405
ListOptions: db.ListOptions{
394406
PageSize: setting.UI.User.RepoPagingNum,
@@ -402,6 +414,10 @@ func NotificationWatching(ctx *context.Context) {
402414
Collaborate: util.OptionalBoolFalse,
403415
TopicOnly: ctx.FormBool("topic"),
404416
IncludeDescription: setting.UI.SearchRepoDescription,
417+
Archived: archived,
418+
Fork: fork,
419+
Mirror: mirror,
420+
IsPrivate: private,
405421
})
406422
if err != nil {
407423
ctx.ServerError("SearchRepository", err)

routers/web/user/profile.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
161161
}
162162
ctx.Data["NumFollowing"] = numFollowing
163163

164+
archived := ctx.FormOptionalBool("archived")
165+
ctx.Data["IsArchived"] = archived
166+
167+
fork := ctx.FormOptionalBool("fork")
168+
ctx.Data["IsFork"] = fork
169+
170+
mirror := ctx.FormOptionalBool("mirror")
171+
ctx.Data["IsMirror"] = mirror
172+
173+
private := ctx.FormOptionalBool("private")
174+
ctx.Data["IsPrivate"] = private
175+
164176
switch tab {
165177
case "followers":
166178
ctx.Data["Cards"] = followers
@@ -207,6 +219,10 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
207219
TopicOnly: topicOnly,
208220
Language: language,
209221
IncludeDescription: setting.UI.SearchRepoDescription,
222+
Archived: archived,
223+
Fork: fork,
224+
Mirror: mirror,
225+
IsPrivate: private,
210226
})
211227
if err != nil {
212228
ctx.ServerError("SearchRepository", err)
@@ -229,6 +245,10 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
229245
TopicOnly: topicOnly,
230246
Language: language,
231247
IncludeDescription: setting.UI.SearchRepoDescription,
248+
Archived: archived,
249+
Fork: fork,
250+
Mirror: mirror,
251+
IsPrivate: private,
232252
})
233253
if err != nil {
234254
ctx.ServerError("SearchRepository", err)
@@ -274,6 +294,10 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
274294
TopicOnly: topicOnly,
275295
Language: language,
276296
IncludeDescription: setting.UI.SearchRepoDescription,
297+
Archived: archived,
298+
Fork: fork,
299+
Mirror: mirror,
300+
IsPrivate: private,
277301
})
278302
if err != nil {
279303
ctx.ServerError("SearchRepository", err)

templates/admin/repo/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</div>
88
</h4>
99
<div class="ui attached segment">
10-
{{template "admin/repo/search" .}}
10+
{{template "shared/repo_search" .}}
1111
</div>
1212
<div class="ui attached table segment">
1313
<table class="ui very basic striped table unstackable">

templates/explore/repo_search.tmpl

Lines changed: 0 additions & 42 deletions
This file was deleted.

templates/explore/repos.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div role="main" aria-label="{{.Title}}" class="page-content explore repositories">
33
{{template "explore/navbar" .}}
44
<div class="ui container">
5-
{{template "explore/repo_search" .}}
5+
{{template "shared/repo_search" .}}
66
{{template "explore/repo_list" .}}
77
{{template "base/paginate" .}}
88
</div>

templates/org/home.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{{if .ProfileReadme}}
4040
<div id="readme_profile" class="markup">{{.ProfileReadme | Str2html}}</div>
4141
{{end}}
42-
{{template "explore/repo_search" .}}
42+
{{template "shared/repo_search" .}}
4343
{{template "explore/repo_list" .}}
4444
{{template "base/paginate" .}}
4545
</div>

templates/shared/repo_search.tmpl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<div class="ui secondary filter menu gt-ac gt-mx-0">
2+
<form class="ui form ignore-dirty gt-f1">
3+
<input type="hidden" name="sort" value="{{$.SortType}}">
4+
<input type="hidden" name="language" value="{{$.Language}}">
5+
<div class="ui fluid action input">
6+
{{template "shared/searchinput" dict "Value" .Keyword}}
7+
{{if .PageIsExploreRepositories}}
8+
<input type="hidden" name="only_show_relevant" value="{{.OnlyShowRelevant}}">
9+
{{else if .TabName}}
10+
<input type="hidden" name="tab" value="{{.TabName}}">
11+
{{end}}
12+
<button class="ui primary button">{{ctx.Locale.Tr "explore.search"}}</button>
13+
</div>
14+
</form>
15+
{{$tabQuery := printf "tab=%s&" .TabName}}
16+
{{if not .TabName}}{{$tabQuery = ""}}{{end}}
17+
{{$languageQuery := printf "language=%s&" .Language}}
18+
{{if not .TabName}}{{$languageQuery = ""}}{{end}}
19+
{{$queryParams := printf "%s%sq=%s" $tabQuery $languageQuery .Keyword}}
20+
<!-- Filter -->
21+
{{$queryParamsWithSort := printf "%s&sort=%s" $queryParams .SortType}}
22+
<form class="ui form ignore-dirty" id="repo-search-form" data-query-params="{{$queryParamsWithSort}}">
23+
<div class="ui dropdown type jump item gt-mr-0">
24+
<span class="text">
25+
{{ctx.Locale.Tr "repo.issues.filter"}}
26+
</span>
27+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
28+
<div class="menu">
29+
<a class="item" href="{{printf "%s?%s" .Link $queryParamsWithSort}}">{{ctx.Locale.Tr "repo.issues.filter.reset"}}</a>
30+
<div class="divider"></div>
31+
<label class="item no-blur"><input type="radio" name="archived" {{if .IsArchived.IsTrue}}checked{{end}} value="1"> {{ctx.Locale.Tr "repo.issues.filter.is_archived"}}</label>
32+
<label class="item no-blur"><input type="radio" name="archived" {{if .IsArchived.IsFalse}}checked{{end}} value="0"> {{ctx.Locale.Tr "repo.issues.filter.not_archived"}}</label>
33+
<div class="divider"></div>
34+
<label class="item no-blur"><input type="radio" name="fork" {{if .IsFork.IsTrue}}checked{{end}} value="1"> {{ctx.Locale.Tr "repo.issues.filter.is_fork"}}</label>
35+
<label class="item no-blur"><input type="radio" name="fork" {{if .IsFork.IsFalse}}checked{{end}} value="0"> {{ctx.Locale.Tr "repo.issues.filter.not_fork"}}</label>
36+
<div class="divider"></div>
37+
<label class="item no-blur"><input type="radio" name="mirror" {{if .IsMirror.IsTrue}}checked{{end}} value="1"> {{ctx.Locale.Tr "repo.issues.filter.is_mirror"}}</label>
38+
<label class="item no-blur"><input type="radio" name="mirror" {{if .IsMirror.IsFalse}}checked{{end}} value="0"> {{ctx.Locale.Tr "repo.issues.filter.not_mirror"}}</label>
39+
<div class="divider"></div>
40+
<label class="item no-blur"><input type="radio" name="private" {{if .IsPrivate.IsFalse}}checked{{end}} value="0"> {{ctx.Locale.Tr "repo.issues.filter.public"}}</label>
41+
<label class="item no-blur"><input type="radio" name="private" {{if .IsPrivate.IsTrue}}checked{{end}} value="1"> {{ctx.Locale.Tr "repo.issues.filter.private"}}</label>
42+
</div>
43+
</div>
44+
</form>
45+
<!-- Sort -->
46+
<div class="ui dropdown type jump item gt-mr-0">
47+
<span class="text">
48+
{{ctx.Locale.Tr "repo.issues.filter_sort"}}
49+
</span>
50+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
51+
<div class="menu">
52+
{{$href := printf "%s?%s" .Link $queryParams}}
53+
<a class="{{if eq .SortType "newest"}}active {{end}}item" href="{{$href}}&sort=newest">{{ctx.Locale.Tr "repo.issues.filter_sort.latest"}}</a>
54+
<a class="{{if eq .SortType "oldest"}}active {{end}}item" href="{{$href}}&sort=oldest">{{ctx.Locale.Tr "repo.issues.filter_sort.oldest"}}</a>
55+
<a class="{{if eq .SortType "alphabetically"}}active {{end}}item" href="{{$href}}&sort=alphabetically">{{ctx.Locale.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
56+
<a class="{{if eq .SortType "reversealphabetically"}}active {{end}}item" href="{{$href}}&sort=reversealphabetically">{{ctx.Locale.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
57+
<a class="{{if eq .SortType "recentupdate"}}active {{end}}item" href="{{$href}}&sort=recentupdate">{{ctx.Locale.Tr "repo.issues.filter_sort.recentupdate"}}</a>
58+
<a class="{{if eq .SortType "leastupdate"}}active {{end}}item" href="{{$href}}&sort=leastupdate">{{ctx.Locale.Tr "repo.issues.filter_sort.leastupdate"}}</a>
59+
{{if not .DisableStars}}
60+
<a class="{{if eq .SortType "moststars"}}active {{end}}item" href="{{$href}}&sort=moststars">{{ctx.Locale.Tr "repo.issues.filter_sort.moststars"}}</a>
61+
<a class="{{if eq .SortType "feweststars"}}active {{end}}item" href="{{$href}}&sort=feweststars">{{ctx.Locale.Tr "repo.issues.filter_sort.feweststars"}}</a>
62+
{{end}}
63+
<a class="{{if eq .SortType "mostforks"}}active {{end}}item" href="{{$href}}&sort=mostforks">{{ctx.Locale.Tr "repo.issues.filter_sort.mostforks"}}</a>
64+
<a class="{{if eq .SortType "fewestforks"}}active {{end}}item" href="{{$href}}&sort=fewestforks">{{ctx.Locale.Tr "repo.issues.filter_sort.fewestforks"}}</a>
65+
</div>
66+
</div>
67+
</div>
68+
{{if and .PageIsExploreRepositories .OnlyShowRelevant}}
69+
<div class="ui message explore-relevancy-note">
70+
<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>
71+
</div>
72+
{{end}}
73+
<div class="divider"></div>

templates/user/notification/notification_subscriptions.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
{{template "shared/issuelist" dict "." . "listType" "dashboard"}}
7070
{{end}}
7171
{{else}}
72-
{{template "explore/repo_search" .}}
72+
{{template "shared/repo_search" .}}
7373
{{template "explore/repo_list" .}}
7474
{{template "base/paginate" .}}
7575
{{end}}

templates/user/profile.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
{{template "user/dashboard/feeds" .}}
2121
{{else if eq .TabName "stars"}}
2222
<div class="stars">
23-
{{template "explore/repo_search" .}}
23+
{{template "shared/repo_search" .}}
2424
{{template "explore/repo_list" .}}
2525
{{template "base/paginate" .}}
2626
</div>
@@ -31,7 +31,7 @@
3131
{{else if eq .TabName "overview"}}
3232
<div id="readme_profile" class="markup">{{.ProfileReadme | Str2html}}</div>
3333
{{else}}
34-
{{template "explore/repo_search" .}}
34+
{{template "shared/repo_search" .}}
3535
{{template "explore/repo_list" .}}
3636
{{template "base/paginate" .}}
3737
{{end}}

web_src/js/features/repo-search.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function initRepositorySearch() {
2+
const repositorySearchForm = document.querySelector('#repo-search-form');
3+
if (!repositorySearchForm) return;
4+
5+
for (const radio of repositorySearchForm.querySelectorAll('input[type=radio]')) {
6+
radio.addEventListener('click', (ev) => {
7+
ev.preventDefault();
8+
9+
const formData = new FormData(repositorySearchForm);
10+
const params = new URLSearchParams(formData);
11+
const otherQueryParams = repositorySearchForm.getAttribute('data-query-params');
12+
window.location.search = `${otherQueryParams}&${params.toString()}`;
13+
});
14+
}
15+
}

web_src/js/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import {initCommonIssueListQuickGoto} from './features/common-issue-list.js';
8686
import {initRepoContributors} from './features/contributors.js';
8787
import {initRepoDiffCommitBranchesAndTags} from './features/repo-diff-commit.js';
8888
import {initDirAuto} from './modules/dirauto.js';
89+
import {initRepositorySearch} from './features/repo-search.js';
8990

9091
// Init Gitea's Fomantic settings
9192
initGiteaFomantic();
@@ -174,6 +175,7 @@ onDomReady(() => {
174175
initRepository();
175176
initRepositoryActionView();
176177
initRepoContributors();
178+
initRepositorySearch();
177179

178180
initCommitStatuses();
179181
initCaptcha();

0 commit comments

Comments
 (0)