From 83e04328dfff3b09e5d28dd972ebee0865f96b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Niclas=20Oelschl=C3=A4ger?= <72873130+zokkis@users.noreply.github.com> Date: Sun, 3 Mar 2024 11:18:34 +0100 Subject: [PATCH] Filter Repositories by type (#29231) Filter Repositories by type (resolves #1170, #1318) before: ![image](https://github.com/go-gitea/gitea/assets/72873130/74e6be62-9010-4ab4-8f9b-bd8afbebb8fb) after: ![image](https://github.com/go-gitea/gitea/assets/72873130/e4d85ed6-7864-4150-8d72-5194dac1293f) (cherry picked from commit e3524c63d6d42865ea8288af89b372544d35474b) --- options/locale/locale_en-US.ini | 13 ++++ routers/web/explore/repo.go | 20 ++++++ routers/web/org/home.go | 20 ++++++ routers/web/user/notification.go | 20 ++++++ routers/web/user/profile.go | 30 +++++++++ templates/admin/repo/list.tmpl | 2 +- templates/admin/repo/search.tmpl | 29 -------- templates/explore/repo_search.tmpl | 44 ------------ templates/explore/repos.tmpl | 2 +- templates/org/home.tmpl | 2 +- templates/shared/repo_search.tmpl | 67 +++++++++++++++++++ .../notification_subscriptions.tmpl | 2 +- templates/user/profile.tmpl | 4 +- web_src/js/features/repo-search.js | 22 ++++++ web_src/js/index.js | 2 + 15 files changed, 200 insertions(+), 79 deletions(-) delete mode 100644 templates/admin/repo/search.tmpl delete mode 100644 templates/explore/repo_search.tmpl create mode 100644 templates/shared/repo_search.tmpl create mode 100644 web_src/js/features/repo-search.js diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index fd3aa8d6e..07ad19aa7 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -143,6 +143,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 diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index d5a46f688..cf7381512 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -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, @@ -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) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 4a7378689..71d10f3a4 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -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 @@ -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) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 09e592d63..324205ed9 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -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, @@ -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) diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 237363c19..89d22d3ef 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -164,6 +164,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 @@ -210,6 +225,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) @@ -232,6 +252,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) @@ -277,6 +302,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) diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index e11247aed..e977c8307 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -7,7 +7,7 @@