Skip to content

Commit 16ba16d

Browse files
authored
Allow to set explore page default sort (#27951)
as title --- *Sponsored by Kithara Software GmbH*
1 parent 69d98f8 commit 16ba16d

File tree

8 files changed

+28
-15
lines changed

8 files changed

+28
-15
lines changed

custom/conf/app.example.ini

+4
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,10 @@ LEVEL = Info
12381238
;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
12391239
;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
12401240
;ONLY_SHOW_RELEVANT_REPOS = false
1241+
;;
1242+
;; Change the sort type of the explore pages.
1243+
;; Default is "recentupdate", but you also have "alphabetically", "reverselastlogin", "newest", "oldest".
1244+
;EXPLORE_PAGING_DEFAULT_SORT = recentupdate
12411245

12421246
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12431247
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/administration/config-cheat-sheet.en-us.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ The following configuration set `Content-Type: application/vnd.android.package-a
229229
add it to this config.
230230
- `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.
231231
- `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page.
232-
- `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.
232+
- `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.
233233
A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
234+
- `EXPLORE_PAGING_DEFAULT_SORT`: **recentupdate**: Change the sort type of the explore pages. Valid values are "recentupdate", "alphabetically", "reverselastlogin", "newest" and "oldest"
234235

235236
### UI - Admin (`ui.admin`)
236237

modules/setting/ui.go

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var UI = struct {
3333
CustomEmojisMap map[string]string `ini:"-"`
3434
SearchRepoDescription bool
3535
OnlyShowRelevantRepos bool
36+
ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"`
3637

3738
Notification struct {
3839
MinTimeout time.Duration

routers/web/admin/orgs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Organizations(ctx *context.Context) {
2424
ctx.Data["PageIsAdminOrganizations"] = true
2525

2626
if ctx.FormString("sort") == "" {
27-
ctx.SetFormString("sort", explore.UserSearchDefaultAdminSort)
27+
ctx.SetFormString("sort", UserSearchDefaultAdminSort)
2828
}
2929

3030
explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{

routers/web/admin/users.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const (
3737
tplUserEdit base.TplName = "admin/user/edit"
3838
)
3939

40+
// UserSearchDefaultAdminSort is the default sort type for admin view
41+
const UserSearchDefaultAdminSort = "alphabetically"
42+
4043
// Users show all the users
4144
func Users(ctx *context.Context) {
4245
ctx.Data["Title"] = ctx.Tr("admin.users")
@@ -56,7 +59,7 @@ func Users(ctx *context.Context) {
5659

5760
sortType := ctx.FormString("sort")
5861
if sortType == "" {
59-
sortType = explore.UserSearchDefaultAdminSort
62+
sortType = UserSearchDefaultAdminSort
6063
ctx.SetFormString("sort", sortType)
6164
}
6265
ctx.PageData["adminUserListSearchForm"] = map[string]any{

routers/web/explore/org.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func Organizations(ctx *context.Context) {
2525
}
2626

2727
if ctx.FormString("sort") == "" {
28-
ctx.SetFormString("sort", UserSearchDefaultSortType)
28+
ctx.SetFormString("sort", setting.UI.ExploreDefaultSort)
2929
}
3030

3131
RenderUserSearch(ctx, &user_model.SearchUserOptions{

routers/web/explore/repo.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
5757
orderBy db.SearchOrderBy
5858
)
5959

60-
ctx.Data["SortType"] = ctx.FormString("sort")
61-
switch ctx.FormString("sort") {
60+
sortOrder := ctx.FormString("sort")
61+
if sortOrder == "" {
62+
sortOrder = setting.UI.ExploreDefaultSort
63+
}
64+
ctx.Data["SortType"] = sortOrder
65+
66+
switch sortOrder {
6267
case "newest":
6368
orderBy = db.SearchOrderByNewest
6469
case "oldest":

routers/web/explore/user.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ const (
2323
tplExploreUsers base.TplName = "explore/users"
2424
)
2525

26-
// UserSearchDefaultSortType is the default sort type for user search
27-
const (
28-
UserSearchDefaultSortType = "recentupdate"
29-
UserSearchDefaultAdminSort = "alphabetically"
30-
)
31-
3226
var nullByte = []byte{0x00}
3327

3428
func isKeywordValid(keyword string) bool {
@@ -60,8 +54,13 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions,
6054

6155
// 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
6256

63-
ctx.Data["SortType"] = ctx.FormString("sort")
64-
switch ctx.FormString("sort") {
57+
sortOrder := ctx.FormString("sort")
58+
if sortOrder == "" {
59+
sortOrder = setting.UI.ExploreDefaultSort
60+
}
61+
ctx.Data["SortType"] = sortOrder
62+
63+
switch sortOrder {
6564
case "newest":
6665
orderBy = "`user`.id DESC"
6766
case "oldest":
@@ -134,7 +133,7 @@ func Users(ctx *context.Context) {
134133
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
135134

136135
if ctx.FormString("sort") == "" {
137-
ctx.SetFormString("sort", UserSearchDefaultSortType)
136+
ctx.SetFormString("sort", setting.UI.ExploreDefaultSort)
138137
}
139138

140139
RenderUserSearch(ctx, &user_model.SearchUserOptions{

0 commit comments

Comments
 (0)