Skip to content

Commit

Permalink
feature: filter repositories by type
Browse files Browse the repository at this point in the history
  • Loading branch information
zokkis committed Feb 18, 2024
1 parent 658cbdd commit 04c51f9
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 48 deletions.
10 changes: 10 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,16 @@ issues.filter_milestones = Filter Milestone
issues.filter_projects = Filter Project
issues.filter_labels = Filter Label
issues.filter_reviewers = Filter Reviewer
issues.filter = Filter
issues.filter.reset = Reset Filter
issues.filter.is_archived = Archived
issues.filter.not_archived = Not Archived
issues.filter.is_fork = Forked
issues.filter.not_fork = Not Forked
issues.filter.is_mirror = Mirrored
issues.filter.not_mirror = Not Mirrored
issues.filter.public = Public
issues.filter.private = Private
issues.new = New Issue
issues.new.title_empty = Title cannot be empty
issues.new.labels = Labels
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" .}}
</div>
<div class="ui attached table segment">
<table class="ui very basic striped table unstackable">
Expand Down
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
73 changes: 73 additions & 0 deletions templates/shared/repo_search.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<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}}
{{if not .TabName}}{{$tabQuery = ""}}{{end}}
{{$languageQuery := printf "language=%s&" .Language}}
{{if not .TabName}}{{$languageQuery = ""}}{{end}}
{{$queryParams := printf "%s%sq=%s" $tabQuery $languageQuery .Keyword}}
<!-- Filter -->
{{$queryParamsWithSort := printf "%s&sort=%s" $queryParams .SortType}}
<form class="ui form ignore-dirty" id="repo-search-form" data-query-params="{{$queryParamsWithSort}}">
<div class="ui dropdown type jump item gt-mr-0">
<span class="text">
{{ctx.Locale.Tr "repo.issues.filter"}}
</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<a class="item" href="{{printf "%s?%s" .Link $queryParamsWithSort}}">{{ctx.Locale.Tr "repo.issues.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 "repo.issues.filter.is_archived"}}</label>
<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>
<div class="divider"></div>
<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>
<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>
<div class="divider"></div>
<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>
<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>
<div class="divider"></div>
<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>
<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>
</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}}
<div class="divider"></div>
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', (ev) => {
ev.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

0 comments on commit 04c51f9

Please sign in to comment.