Skip to content

Commit 8b29f40

Browse files
committed
improve the user search sort
1 parent 40b0087 commit 8b29f40

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

modules/context/form.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ func (ctx *Context) FormOptionalBool(key string) util.OptionalBool {
6565
v = v || strings.EqualFold(s, "on")
6666
return util.OptionalBoolOf(v)
6767
}
68+
69+
func (ctx *Context) SetFormValue(key, value string) {
70+
_ = ctx.Req.FormValue(key) // force parse form
71+
ctx.Req.Form.Set(key, value)
72+
}

routers/web/admin/orgs.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ func Organizations(ctx *context.Context) {
2323
ctx.Data["Title"] = ctx.Tr("admin.organizations")
2424
ctx.Data["PageIsAdminOrganizations"] = true
2525

26-
explore.RenderUserSearchWithSort(ctx, &user_model.SearchUserOptions{
26+
if ctx.FormString("sort") == "" {
27+
ctx.SetFormValue("sort", explore.UserSearchDefaultAdminSort)
28+
}
29+
30+
explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{
2731
Actor: ctx.Doer,
2832
Type: user_model.UserTypeOrganization,
2933
ListOptions: db.ListOptions{
3034
PageSize: setting.UI.Admin.OrgPagingNum,
3135
},
3236
Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate},
33-
}, tplOrgs, explore.UserSearchDefaultAdminSort)
37+
}, tplOrgs)
3438
}

routers/web/admin/users.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ func Users(ctx *context.Context) {
5454
sortType := ctx.FormString("sort")
5555
if sortType == "" {
5656
sortType = explore.UserSearchDefaultAdminSort
57+
ctx.SetFormValue("sort", sortType)
5758
}
5859
ctx.PageData["adminUserListSearchForm"] = map[string]interface{}{
5960
"StatusFilterMap": statusFilterMap,
6061
"SortType": sortType,
6162
}
6263

63-
explore.RenderUserSearchWithSort(ctx, &user_model.SearchUserOptions{
64+
explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{
6465
Actor: ctx.Doer,
6566
Type: user_model.UserTypeIndividual,
6667
ListOptions: db.ListOptions{
@@ -73,7 +74,7 @@ func Users(ctx *context.Context) {
7374
IsTwoFactorEnabled: util.OptionalBoolParse(statusFilterMap["is_2fa_enabled"]),
7475
IsProhibitLogin: util.OptionalBoolParse(statusFilterMap["is_prohibit_login"]),
7576
ExtraParamStrings: extraParamStrings,
76-
}, tplUsers, explore.UserSearchDefaultAdminSort)
77+
}, tplUsers)
7778
}
7879

7980
// NewUser render adding a new user page

routers/web/explore/org.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func Organizations(ctx *context.Context) {
3030
visibleTypes = append(visibleTypes, structs.VisibleTypeLimited, structs.VisibleTypePrivate)
3131
}
3232

33+
if ctx.FormString("sort") == "" {
34+
ctx.SetFormValue("sort", UserSearchDefaultSortType)
35+
}
36+
3337
RenderUserSearch(ctx, &user_model.SearchUserOptions{
3438
Actor: ctx.Doer,
3539
Type: user_model.UserTypeOrganization,

routers/web/explore/user.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ func isKeywordValid(keyword string) bool {
3737

3838
// RenderUserSearch render user search page
3939
func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, tplName base.TplName) {
40-
RenderUserSearchWithSort(ctx, opts, tplName, UserSearchDefaultSortType)
41-
}
42-
43-
// RenderUserSearchWithSort render user search page with specific default sort
44-
func RenderUserSearchWithSort(ctx *context.Context, opts *user_model.SearchUserOptions, tplName base.TplName, defaultSort string) {
4540
// Sitemap index for sitemap paths
4641
opts.Page = int(ctx.ParamsInt64("idx"))
4742
isSitemap := ctx.Params("idx") != ""
@@ -65,12 +60,8 @@ func RenderUserSearchWithSort(ctx *context.Context, opts *user_model.SearchUserO
6560

6661
// 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
6762

68-
sortType := ctx.FormString("sort")
69-
if sortType == "" {
70-
sortType = defaultSort
71-
}
72-
ctx.Data["SortType"] = sortType
73-
switch sortType {
63+
ctx.Data["SortType"] = ctx.FormString("sort")
64+
switch ctx.FormString("sort") {
7465
case "newest":
7566
orderBy = "`user`.id DESC"
7667
case "oldest":
@@ -142,6 +133,10 @@ func Users(ctx *context.Context) {
142133
ctx.Data["PageIsExploreUsers"] = true
143134
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
144135

136+
if ctx.FormString("sort") == "" {
137+
ctx.SetFormValue("sort", UserSearchDefaultSortType)
138+
}
139+
145140
RenderUserSearch(ctx, &user_model.SearchUserOptions{
146141
Actor: ctx.Doer,
147142
Type: user_model.UserTypeIndividual,

0 commit comments

Comments
 (0)