|
|
@ -44,9 +44,16 @@ func Home(ctx *context.Context) { |
|
|
|
ctx.HTML(200, HOME) |
|
|
|
ctx.HTML(200, HOME) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RenderRepoSearch(ctx *context.Context, |
|
|
|
type RepoSearchOptions struct { |
|
|
|
counter func() int64, ranger func(int, int) ([]*models.Repository, error), |
|
|
|
Counter func() int64 |
|
|
|
pagingNum int, orderBy string, tplName base.TplName) { |
|
|
|
Ranger func(int, int) ([]*models.Repository, error) |
|
|
|
|
|
|
|
Private bool |
|
|
|
|
|
|
|
PageSize int |
|
|
|
|
|
|
|
OrderBy string |
|
|
|
|
|
|
|
TplName base.TplName |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { |
|
|
|
page := ctx.QueryInt("page") |
|
|
|
page := ctx.QueryInt("page") |
|
|
|
if page <= 1 { |
|
|
|
if page <= 1 { |
|
|
|
page = 1 |
|
|
|
page = 1 |
|
|
@ -60,18 +67,19 @@ func RenderRepoSearch(ctx *context.Context, |
|
|
|
|
|
|
|
|
|
|
|
keyword := ctx.Query("q") |
|
|
|
keyword := ctx.Query("q") |
|
|
|
if len(keyword) == 0 { |
|
|
|
if len(keyword) == 0 { |
|
|
|
repos, err = ranger(page, pagingNum) |
|
|
|
repos, err = opts.Ranger(page, opts.PageSize) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "ranger", err) |
|
|
|
ctx.Handle(500, "opts.Ranger", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
count = counter() |
|
|
|
count = opts.Counter() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ |
|
|
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ |
|
|
|
Keyword: keyword, |
|
|
|
Keyword: keyword, |
|
|
|
OrderBy: orderBy, |
|
|
|
OrderBy: opts.OrderBy, |
|
|
|
|
|
|
|
Private: opts.Private, |
|
|
|
Page: page, |
|
|
|
Page: page, |
|
|
|
PageSize: pagingNum, |
|
|
|
PageSize: opts.PageSize, |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "SearchRepositoryByName", err) |
|
|
|
ctx.Handle(500, "SearchRepositoryByName", err) |
|
|
@ -80,7 +88,7 @@ func RenderRepoSearch(ctx *context.Context, |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Total"] = count |
|
|
|
ctx.Data["Total"] = count |
|
|
|
ctx.Data["Page"] = paginater.New(int(count), pagingNum, page, 5) |
|
|
|
ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) |
|
|
|
|
|
|
|
|
|
|
|
for _, repo := range repos { |
|
|
|
for _, repo := range repos { |
|
|
|
if err = repo.GetOwner(); err != nil { |
|
|
|
if err = repo.GetOwner(); err != nil { |
|
|
@ -90,7 +98,7 @@ func RenderRepoSearch(ctx *context.Context, |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["Repos"] = repos |
|
|
|
ctx.Data["Repos"] = repos |
|
|
|
|
|
|
|
|
|
|
|
ctx.HTML(200, tplName) |
|
|
|
ctx.HTML(200, opts.TplName) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ExploreRepos(ctx *context.Context) { |
|
|
|
func ExploreRepos(ctx *context.Context) { |
|
|
@ -98,13 +106,25 @@ func ExploreRepos(ctx *context.Context) { |
|
|
|
ctx.Data["PageIsExplore"] = true |
|
|
|
ctx.Data["PageIsExplore"] = true |
|
|
|
ctx.Data["PageIsExploreRepositories"] = true |
|
|
|
ctx.Data["PageIsExploreRepositories"] = true |
|
|
|
|
|
|
|
|
|
|
|
RenderRepoSearch(ctx, models.CountPublicRepositories, models.GetRecentUpdatedRepositories, |
|
|
|
RenderRepoSearch(ctx, &RepoSearchOptions{ |
|
|
|
setting.ExplorePagingNum, "updated_unix DESC", EXPLORE_REPOS) |
|
|
|
Counter: models.CountPublicRepositories, |
|
|
|
|
|
|
|
Ranger: models.GetRecentUpdatedRepositories, |
|
|
|
|
|
|
|
PageSize: setting.ExplorePagingNum, |
|
|
|
|
|
|
|
OrderBy: "updated_unix DESC", |
|
|
|
|
|
|
|
TplName: EXPLORE_REPOS, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type UserSearchOptions struct { |
|
|
|
|
|
|
|
Type models.UserType |
|
|
|
|
|
|
|
Counter func() int64 |
|
|
|
|
|
|
|
Ranger func(int, int) ([]*models.User, error) |
|
|
|
|
|
|
|
PageSize int |
|
|
|
|
|
|
|
OrderBy string |
|
|
|
|
|
|
|
TplName base.TplName |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RenderUserSearch(ctx *context.Context, userType models.UserType, |
|
|
|
func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { |
|
|
|
counter func() int64, ranger func(int, int) ([]*models.User, error), |
|
|
|
|
|
|
|
pagingNum int, orderBy string, tplName base.TplName) { |
|
|
|
|
|
|
|
page := ctx.QueryInt("page") |
|
|
|
page := ctx.QueryInt("page") |
|
|
|
if page <= 1 { |
|
|
|
if page <= 1 { |
|
|
|
page = 1 |
|
|
|
page = 1 |
|
|
@ -118,19 +138,19 @@ func RenderUserSearch(ctx *context.Context, userType models.UserType, |
|
|
|
|
|
|
|
|
|
|
|
keyword := ctx.Query("q") |
|
|
|
keyword := ctx.Query("q") |
|
|
|
if len(keyword) == 0 { |
|
|
|
if len(keyword) == 0 { |
|
|
|
users, err = ranger(page, pagingNum) |
|
|
|
users, err = opts.Ranger(page, opts.PageSize) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "ranger", err) |
|
|
|
ctx.Handle(500, "opts.Ranger", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
count = counter() |
|
|
|
count = opts.Counter() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
users, count, err = models.SearchUserByName(&models.SearchUserOptions{ |
|
|
|
users, count, err = models.SearchUserByName(&models.SearchUserOptions{ |
|
|
|
Keyword: keyword, |
|
|
|
Keyword: keyword, |
|
|
|
Type: userType, |
|
|
|
Type: opts.Type, |
|
|
|
OrderBy: orderBy, |
|
|
|
OrderBy: opts.OrderBy, |
|
|
|
Page: page, |
|
|
|
Page: page, |
|
|
|
PageSize: pagingNum, |
|
|
|
PageSize: opts.PageSize, |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "SearchUserByName", err) |
|
|
|
ctx.Handle(500, "SearchUserByName", err) |
|
|
@ -139,10 +159,10 @@ func RenderUserSearch(ctx *context.Context, userType models.UserType, |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Total"] = count |
|
|
|
ctx.Data["Total"] = count |
|
|
|
ctx.Data["Page"] = paginater.New(int(count), pagingNum, page, 5) |
|
|
|
ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) |
|
|
|
ctx.Data["Users"] = users |
|
|
|
ctx.Data["Users"] = users |
|
|
|
|
|
|
|
|
|
|
|
ctx.HTML(200, tplName) |
|
|
|
ctx.HTML(200, opts.TplName) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ExploreUsers(ctx *context.Context) { |
|
|
|
func ExploreUsers(ctx *context.Context) { |
|
|
@ -150,8 +170,14 @@ func ExploreUsers(ctx *context.Context) { |
|
|
|
ctx.Data["PageIsExplore"] = true |
|
|
|
ctx.Data["PageIsExplore"] = true |
|
|
|
ctx.Data["PageIsExploreUsers"] = true |
|
|
|
ctx.Data["PageIsExploreUsers"] = true |
|
|
|
|
|
|
|
|
|
|
|
RenderUserSearch(ctx, models.USER_TYPE_INDIVIDUAL, models.CountUsers, models.Users, |
|
|
|
RenderUserSearch(ctx, &UserSearchOptions{ |
|
|
|
setting.ExplorePagingNum, "updated_unix DESC", EXPLORE_USERS) |
|
|
|
Type: models.USER_TYPE_INDIVIDUAL, |
|
|
|
|
|
|
|
Counter: models.CountUsers, |
|
|
|
|
|
|
|
Ranger: models.Users, |
|
|
|
|
|
|
|
PageSize: setting.ExplorePagingNum, |
|
|
|
|
|
|
|
OrderBy: "updated_unix DESC", |
|
|
|
|
|
|
|
TplName: EXPLORE_USERS, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func NotFound(ctx *context.Context) { |
|
|
|
func NotFound(ctx *context.Context) { |
|
|
|