@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/user"
"code.gitea.io/gitea/routers/user"
"github.com/Unknwon/paginater"
"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
// RenderUserSearch render user search page
func RenderUserSearch ( ctx * context . Context , opts * UserSearchOptions ) {
func RenderUserSearch ( ctx * context . Context , opts * models . SearchUserOptions , tplName base . TplName ) {
page : = ctx . QueryInt ( "page" )
opts . Page = ctx . QueryInt ( "page" )
if page <= 1 {
if opts . Page <= 1 {
page = 1
opts . Page = 1
}
}
var (
var (
@ -189,40 +181,22 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
orderBy = "name ASC"
orderBy = "name ASC"
}
}
keyword := strings . Trim ( ctx . Query ( "q" ) , " " )
opts . Keyword = strings . Trim ( ctx . Query ( "q" ) , " " )
if len ( keyword ) == 0 {
opts . OrderBy = orderBy
users , err = opts . Ranger ( & models . SearchUserOptions {
if len ( opts . Keyword ) == 0 || isKeywordValid ( opts . Keyword ) {
OrderBy : orderBy ,
users , count , err = models . SearchUsers ( opts )
Page : page ,
PageSize : opts . PageSize ,
} )
if err != nil {
if err != nil {
ctx . Handle ( 500 , "opts.Ranger " , err )
ctx . Handle ( 500 , "SearchUsers" , err )
return
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" ] = k eyword
ctx . Data [ "Keyword" ] = opts . Keyword
ctx . Data [ "Total" ] = count
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 [ "Users" ] = users
ctx . Data [ "ShowUserEmail" ] = setting . UI . ShowUserEmail
ctx . Data [ "ShowUserEmail" ] = setting . UI . ShowUserEmail
ctx . HTML ( 200 , op ts . T plName)
ctx . HTML ( 200 , tplName )
}
}
// ExploreUsers render explore users page
// ExploreUsers render explore users page
@ -231,13 +205,11 @@ func ExploreUsers(ctx *context.Context) {
ctx . Data [ "PageIsExplore" ] = true
ctx . Data [ "PageIsExplore" ] = true
ctx . Data [ "PageIsExploreUsers" ] = true
ctx . Data [ "PageIsExploreUsers" ] = true
RenderUserSearch ( ctx , & UserSearch Options{
RenderUserSearch ( ctx , & models . SearchUser Options{
Type : models . UserTypeIndividual ,
Type : models . UserTypeIndividual ,
Counter : models . CountUsers ,
Ranger : models . Users ,
PageSize : setting . UI . ExplorePagingNum ,
PageSize : setting . UI . ExplorePagingNum ,
TplName : tplExploreUsers ,
IsActive : util . OptionalBoolTrue ,
} )
} , tplExploreUsers )
}
}
// ExploreOrganizations render explore organizations page
// ExploreOrganizations render explore organizations page
@ -246,13 +218,10 @@ func ExploreOrganizations(ctx *context.Context) {
ctx . Data [ "PageIsExplore" ] = true
ctx . Data [ "PageIsExplore" ] = true
ctx . Data [ "PageIsExploreOrganizations" ] = true
ctx . Data [ "PageIsExploreOrganizations" ] = true
RenderUserSearch ( ctx , & UserSearch Options{
RenderUserSearch ( ctx , & models . SearchUser Options{
Type : models . UserTypeOrganization ,
Type : models . UserTypeOrganization ,
Counter : models . CountOrganizations ,
Ranger : models . Organizations ,
PageSize : setting . UI . ExplorePagingNum ,
PageSize : setting . UI . ExplorePagingNum ,
TplName : tplExploreOrganizations ,
} , tplExploreOrganizations )
} )
}
}
// NotFound render 404 page
// NotFound render 404 page