From 2bdf5421e73ab1586bbe6aa1919654e066acd2d2 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 7 Nov 2023 17:57:47 +0100 Subject: [PATCH 1/5] explore pages: set default sort before switch statement --- routers/web/explore/repo.go | 9 +++++++-- routers/web/explore/user.go | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index e5f7977abd01e..3f167a2847a47 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -57,8 +57,13 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { orderBy db.SearchOrderBy ) - ctx.Data["SortType"] = ctx.FormString("sort") - switch ctx.FormString("sort") { + sortOrder := ctx.FormString("sort") + if sortOrder == "" { + sortOrder = UserSearchDefaultSortType + } + ctx.Data["SortType"] = sortOrder + + switch sortOrder { case "newest": orderBy = db.SearchOrderByNewest case "oldest": diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index c760004088ea3..c874042362263 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -60,8 +60,13 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, // we can not set orderBy to `models.SearchOrderByXxx`, because there may be a JOIN in the statement, different tables may have the same name columns - ctx.Data["SortType"] = ctx.FormString("sort") - switch ctx.FormString("sort") { + sortOrder := ctx.FormString("sort") + if sortOrder == "" { + sortOrder = UserSearchDefaultSortType + } + ctx.Data["SortType"] = sortOrder + + switch sortOrder { case "newest": orderBy = "`user`.id DESC" case "oldest": From 17f2a0d407113fe41f4df8042a16bec84b9b0408 Mon Sep 17 00:00:00 2001 From: "m.huber" Date: Tue, 7 Nov 2023 18:06:47 +0100 Subject: [PATCH 2/5] explore pages: allow default sort to be configured --- custom/conf/app.example.ini | 4 ++++ docs/content/administration/config-cheat-sheet.en-us.md | 3 ++- modules/setting/ui.go | 1 + routers/web/explore/org.go | 2 +- routers/web/explore/repo.go | 2 +- routers/web/explore/user.go | 4 ++-- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 2209822ff0869..375962e68643c 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1235,6 +1235,10 @@ LEVEL = Info ;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used. ;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic). ;ONLY_SHOW_RELEVANT_REPOS = false +;; +;; Change the sort type of the explore pages. +;; Default is "recentupdate", but you also have "alphabetically", "reverselastlogin", "newest", "oldest". +;EXPLORE_PAGING_DEFAULT_SORT = recentupdate ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/docs/content/administration/config-cheat-sheet.en-us.md b/docs/content/administration/config-cheat-sheet.en-us.md index 715bd6d325f59..6ebeabaad92a1 100644 --- a/docs/content/administration/config-cheat-sheet.en-us.md +++ b/docs/content/administration/config-cheat-sheet.en-us.md @@ -228,8 +228,9 @@ The following configuration set `Content-Type: application/vnd.android.package-a add it to this config. - `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. - `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page. -- `ONLY_SHOW_RELEVANT_REPOS`: **false** Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used. +- `ONLY_SHOW_RELEVANT_REPOS`: **false**: Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used. A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic). +- `EXPLORE_PAGING_DEFAULT_SORT`: **recentupdate**: Change the sort type of the explore pages. Valid vaules are "recentupdate", "alphabetically", "reverselastlogin", "newest" and "oldest" ### UI - Admin (`ui.admin`) diff --git a/modules/setting/ui.go b/modules/setting/ui.go index 231698bf60589..31042d3ee0dda 100644 --- a/modules/setting/ui.go +++ b/modules/setting/ui.go @@ -33,6 +33,7 @@ var UI = struct { CustomEmojisMap map[string]string `ini:"-"` SearchRepoDescription bool OnlyShowRelevantRepos bool + ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"` Notification struct { MinTimeout time.Duration diff --git a/routers/web/explore/org.go b/routers/web/explore/org.go index e37bce6b40e4f..dc1318beefec0 100644 --- a/routers/web/explore/org.go +++ b/routers/web/explore/org.go @@ -25,7 +25,7 @@ func Organizations(ctx *context.Context) { } if ctx.FormString("sort") == "" { - ctx.SetFormString("sort", UserSearchDefaultSortType) + ctx.SetFormString("sort", setting.UI.ExploreDefaultSort) } RenderUserSearch(ctx, &user_model.SearchUserOptions{ diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index 3f167a2847a47..0446edebe6913 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -59,7 +59,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { sortOrder := ctx.FormString("sort") if sortOrder == "" { - sortOrder = UserSearchDefaultSortType + sortOrder = setting.UI.ExploreDefaultSort } ctx.Data["SortType"] = sortOrder diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index c874042362263..87a22559bb2b6 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -62,7 +62,7 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, sortOrder := ctx.FormString("sort") if sortOrder == "" { - sortOrder = UserSearchDefaultSortType + sortOrder = setting.UI.ExploreDefaultSort } ctx.Data["SortType"] = sortOrder @@ -139,7 +139,7 @@ func Users(ctx *context.Context) { ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled if ctx.FormString("sort") == "" { - ctx.SetFormString("sort", UserSearchDefaultSortType) + ctx.SetFormString("sort", setting.UI.ExploreDefaultSort) } RenderUserSearch(ctx, &user_model.SearchUserOptions{ From a06c79129d9511d6fdf8221625bfcd5a0981044f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 7 Nov 2023 21:20:21 +0100 Subject: [PATCH 3/5] rm unused --- routers/web/explore/user.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index 87a22559bb2b6..f1ba86ec5bc8d 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -23,11 +23,8 @@ const ( tplExploreUsers base.TplName = "explore/users" ) -// UserSearchDefaultSortType is the default sort type for user search -const ( - UserSearchDefaultSortType = "recentupdate" - UserSearchDefaultAdminSort = "alphabetically" -) +// UserSearchDefaultAdminSort is the default sort type for admin view +const UserSearchDefaultAdminSort = "alphabetically" var nullByte = []byte{0x00} From b6160790e1fb5fc6ed1821d8152ecf1eac720bce Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 7 Nov 2023 21:21:51 +0100 Subject: [PATCH 4/5] refactor nit: mv const to used package --- routers/web/admin/orgs.go | 2 +- routers/web/admin/users.go | 5 ++++- routers/web/explore/user.go | 3 --- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/routers/web/admin/orgs.go b/routers/web/admin/orgs.go index ab44f8048bf13..00131c9e2f7f4 100644 --- a/routers/web/admin/orgs.go +++ b/routers/web/admin/orgs.go @@ -24,7 +24,7 @@ func Organizations(ctx *context.Context) { ctx.Data["PageIsAdminOrganizations"] = true if ctx.FormString("sort") == "" { - ctx.SetFormString("sort", explore.UserSearchDefaultAdminSort) + ctx.SetFormString("sort", UserSearchDefaultAdminSort) } explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{ diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index 630d739836beb..58120818b0bce 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -37,6 +37,9 @@ const ( tplUserEdit base.TplName = "admin/user/edit" ) +// UserSearchDefaultAdminSort is the default sort type for admin view +const UserSearchDefaultAdminSort = "alphabetically" + // Users show all the users func Users(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("admin.users") @@ -56,7 +59,7 @@ func Users(ctx *context.Context) { sortType := ctx.FormString("sort") if sortType == "" { - sortType = explore.UserSearchDefaultAdminSort + sortType = UserSearchDefaultAdminSort ctx.SetFormString("sort", sortType) } ctx.PageData["adminUserListSearchForm"] = map[string]any{ diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index f1ba86ec5bc8d..09d31f95ef47d 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -23,9 +23,6 @@ const ( tplExploreUsers base.TplName = "explore/users" ) -// UserSearchDefaultAdminSort is the default sort type for admin view -const UserSearchDefaultAdminSort = "alphabetically" - var nullByte = []byte{0x00} func isKeywordValid(keyword string) bool { From 21ec34d2cbed97492930093beab7c84d20f980b9 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 8 Nov 2023 01:56:54 +0100 Subject: [PATCH 5/5] Update docs/content/administration/config-cheat-sheet.en-us.md --- docs/content/administration/config-cheat-sheet.en-us.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/administration/config-cheat-sheet.en-us.md b/docs/content/administration/config-cheat-sheet.en-us.md index 6ebeabaad92a1..f1b22046f98e1 100644 --- a/docs/content/administration/config-cheat-sheet.en-us.md +++ b/docs/content/administration/config-cheat-sheet.en-us.md @@ -230,7 +230,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a - `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page. - `ONLY_SHOW_RELEVANT_REPOS`: **false**: Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used. A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic). -- `EXPLORE_PAGING_DEFAULT_SORT`: **recentupdate**: Change the sort type of the explore pages. Valid vaules are "recentupdate", "alphabetically", "reverselastlogin", "newest" and "oldest" +- `EXPLORE_PAGING_DEFAULT_SORT`: **recentupdate**: Change the sort type of the explore pages. Valid values are "recentupdate", "alphabetically", "reverselastlogin", "newest" and "oldest" ### UI - Admin (`ui.admin`)