diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-10-25 01:36:19 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-10-24 20:36:19 +0300 |
commit | 6eeadb2082193f8e3dc5269dfc6da2daef7eb6a1 (patch) | |
tree | d28d3be3451194e98a5c01097347e7eebdb6393f /routers/home.go | |
parent | 03900303a9500b33b33ff03fd6dd325147a1117e (diff) | |
download | gitea-6eeadb2082193f8e3dc5269dfc6da2daef7eb6a1.tar.gz gitea-6eeadb2082193f8e3dc5269dfc6da2daef7eb6a1.zip |
Hide unactive on explore users and some refactors (#2741)
* hide unactive on explore users and some refactors
* fix test for removed Organizations
* fix test for removed Organizations
* fix imports
* fix logic bug
* refactor the toConds
* Rename TestOrganizations to TestSearchUsers and add tests for users
* fix other tests
* fix other tests
* fix watchers tests
* fix comments and remove unused code
Diffstat (limited to 'routers/home.go')
-rw-r--r-- | routers/home.go | 67 |
1 files changed, 18 insertions, 49 deletions
diff --git a/routers/home.go b/routers/home.go index 768eb22077..d653d1e843 100644 --- a/routers/home.go +++ b/routers/home.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/routers/user" "github.com/Unknwon/paginater" @@ -147,20 +148,11 @@ func ExploreRepos(ctx *context.Context) { }) } -// UserSearchOptions options when render search user page -type UserSearchOptions struct { - Type models.UserType - Counter func() int64 - Ranger func(*models.SearchUserOptions) ([]*models.User, error) - PageSize int - TplName base.TplName -} - // RenderUserSearch render user search page -func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { - page := ctx.QueryInt("page") - if page <= 1 { - page = 1 +func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplName base.TplName) { + opts.Page = ctx.QueryInt("page") + if opts.Page <= 1 { + opts.Page = 1 } var ( @@ -189,40 +181,22 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { orderBy = "name ASC" } - keyword := strings.Trim(ctx.Query("q"), " ") - if len(keyword) == 0 { - users, err = opts.Ranger(&models.SearchUserOptions{ - OrderBy: orderBy, - Page: page, - PageSize: opts.PageSize, - }) + opts.Keyword = strings.Trim(ctx.Query("q"), " ") + opts.OrderBy = orderBy + if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) { + users, count, err = models.SearchUsers(opts) if err != nil { - ctx.Handle(500, "opts.Ranger", err) + ctx.Handle(500, "SearchUsers", err) return } - count = opts.Counter() - } else { - if isKeywordValid(keyword) { - users, count, err = models.SearchUserByName(&models.SearchUserOptions{ - Keyword: keyword, - Type: opts.Type, - OrderBy: orderBy, - Page: page, - PageSize: opts.PageSize, - }) - if err != nil { - ctx.Handle(500, "SearchUserByName", err) - return - } - } } - ctx.Data["Keyword"] = keyword + ctx.Data["Keyword"] = opts.Keyword ctx.Data["Total"] = count - ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) + ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, opts.Page, 5) ctx.Data["Users"] = users ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail - ctx.HTML(200, opts.TplName) + ctx.HTML(200, tplName) } // ExploreUsers render explore users page @@ -231,13 +205,11 @@ func ExploreUsers(ctx *context.Context) { ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExploreUsers"] = true - RenderUserSearch(ctx, &UserSearchOptions{ + RenderUserSearch(ctx, &models.SearchUserOptions{ Type: models.UserTypeIndividual, - Counter: models.CountUsers, - Ranger: models.Users, PageSize: setting.UI.ExplorePagingNum, - TplName: tplExploreUsers, - }) + IsActive: util.OptionalBoolTrue, + }, tplExploreUsers) } // ExploreOrganizations render explore organizations page @@ -246,13 +218,10 @@ func ExploreOrganizations(ctx *context.Context) { ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExploreOrganizations"] = true - RenderUserSearch(ctx, &UserSearchOptions{ + RenderUserSearch(ctx, &models.SearchUserOptions{ Type: models.UserTypeOrganization, - Counter: models.CountOrganizations, - Ranger: models.Organizations, PageSize: setting.UI.ExplorePagingNum, - TplName: tplExploreOrganizations, - }) + }, tplExploreOrganizations) } // NotFound render 404 page |