|
|
@ -55,10 +55,10 @@ func Home(ctx *context.Context) { |
|
|
|
// RepoSearchOptions when calling search repositories
|
|
|
|
// RepoSearchOptions when calling search repositories
|
|
|
|
type RepoSearchOptions struct { |
|
|
|
type RepoSearchOptions struct { |
|
|
|
Counter func(bool) int64 |
|
|
|
Counter func(bool) int64 |
|
|
|
Ranger func(int, int) ([]*models.Repository, error) |
|
|
|
Ranger func(*models.SearchRepoOptions) ([]*models.Repository, error) |
|
|
|
|
|
|
|
Searcher *models.User |
|
|
|
Private bool |
|
|
|
Private bool |
|
|
|
PageSize int |
|
|
|
PageSize int |
|
|
|
OrderBy string |
|
|
|
|
|
|
|
TplName base.TplName |
|
|
|
TplName base.TplName |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -78,14 +78,36 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
repos []*models.Repository |
|
|
|
repos []*models.Repository |
|
|
|
count int64 |
|
|
|
count int64 |
|
|
|
err error |
|
|
|
err error |
|
|
|
|
|
|
|
orderBy string |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
ctx.Data["SortType"] = ctx.Query("sort") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch ctx.Query("sort") { |
|
|
|
|
|
|
|
case "oldest": |
|
|
|
|
|
|
|
orderBy = "created_unix ASC" |
|
|
|
|
|
|
|
case "recentupdate": |
|
|
|
|
|
|
|
orderBy = "updated_unix DESC" |
|
|
|
|
|
|
|
case "leastupdate": |
|
|
|
|
|
|
|
orderBy = "updated_unix ASC" |
|
|
|
|
|
|
|
case "reversealphabetically": |
|
|
|
|
|
|
|
orderBy = "name DESC" |
|
|
|
|
|
|
|
case "alphabetically": |
|
|
|
|
|
|
|
orderBy = "name ASC" |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
orderBy = "created_unix DESC" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
keyword := ctx.Query("q") |
|
|
|
keyword := ctx.Query("q") |
|
|
|
if len(keyword) == 0 { |
|
|
|
if len(keyword) == 0 { |
|
|
|
repos, err = opts.Ranger(page, opts.PageSize) |
|
|
|
repos, err = opts.Ranger(&models.SearchRepoOptions{ |
|
|
|
|
|
|
|
Page: page, |
|
|
|
|
|
|
|
PageSize: opts.PageSize, |
|
|
|
|
|
|
|
Searcher: ctx.User, |
|
|
|
|
|
|
|
OrderBy: orderBy, |
|
|
|
|
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "opts.Ranger", err) |
|
|
|
ctx.Handle(500, "opts.Ranger", err) |
|
|
|
return |
|
|
|
return |
|
|
@ -95,10 +117,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { |
|
|
|
if isKeywordValid(keyword) { |
|
|
|
if isKeywordValid(keyword) { |
|
|
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ |
|
|
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ |
|
|
|
Keyword: keyword, |
|
|
|
Keyword: keyword, |
|
|
|
OrderBy: opts.OrderBy, |
|
|
|
OrderBy: orderBy, |
|
|
|
Private: opts.Private, |
|
|
|
Private: opts.Private, |
|
|
|
Page: page, |
|
|
|
Page: page, |
|
|
|
PageSize: opts.PageSize, |
|
|
|
PageSize: opts.PageSize, |
|
|
|
|
|
|
|
Searcher: ctx.User, |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "SearchRepositoryByName", err) |
|
|
|
ctx.Handle(500, "SearchRepositoryByName", err) |
|
|
@ -131,7 +154,7 @@ func ExploreRepos(ctx *context.Context) { |
|
|
|
Counter: models.CountRepositories, |
|
|
|
Counter: models.CountRepositories, |
|
|
|
Ranger: models.GetRecentUpdatedRepositories, |
|
|
|
Ranger: models.GetRecentUpdatedRepositories, |
|
|
|
PageSize: setting.UI.ExplorePagingNum, |
|
|
|
PageSize: setting.UI.ExplorePagingNum, |
|
|
|
OrderBy: "updated_unix DESC", |
|
|
|
Searcher: ctx.User, |
|
|
|
TplName: tplExploreRepos, |
|
|
|
TplName: tplExploreRepos, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -140,9 +163,8 @@ func ExploreRepos(ctx *context.Context) { |
|
|
|
type UserSearchOptions struct { |
|
|
|
type UserSearchOptions struct { |
|
|
|
Type models.UserType |
|
|
|
Type models.UserType |
|
|
|
Counter func() int64 |
|
|
|
Counter func() int64 |
|
|
|
Ranger func(int, int) ([]*models.User, error) |
|
|
|
Ranger func(*models.SearchUserOptions) ([]*models.User, error) |
|
|
|
PageSize int |
|
|
|
PageSize int |
|
|
|
OrderBy string |
|
|
|
|
|
|
|
TplName base.TplName |
|
|
|
TplName base.TplName |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -154,14 +176,35 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
users []*models.User |
|
|
|
users []*models.User |
|
|
|
count int64 |
|
|
|
count int64 |
|
|
|
err error |
|
|
|
err error |
|
|
|
|
|
|
|
orderBy string |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["SortType"] = ctx.Query("sort") |
|
|
|
|
|
|
|
//OrderBy: "id ASC",
|
|
|
|
|
|
|
|
switch ctx.Query("sort") { |
|
|
|
|
|
|
|
case "oldest": |
|
|
|
|
|
|
|
orderBy = "id ASC" |
|
|
|
|
|
|
|
case "recentupdate": |
|
|
|
|
|
|
|
orderBy = "updated_unix DESC" |
|
|
|
|
|
|
|
case "leastupdate": |
|
|
|
|
|
|
|
orderBy = "updated_unix ASC" |
|
|
|
|
|
|
|
case "reversealphabetically": |
|
|
|
|
|
|
|
orderBy = "name DESC" |
|
|
|
|
|
|
|
case "alphabetically": |
|
|
|
|
|
|
|
orderBy = "name ASC" |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
orderBy = "id DESC" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
keyword := ctx.Query("q") |
|
|
|
keyword := ctx.Query("q") |
|
|
|
if len(keyword) == 0 { |
|
|
|
if len(keyword) == 0 { |
|
|
|
users, err = opts.Ranger(page, opts.PageSize) |
|
|
|
users, err = opts.Ranger(&models.SearchUserOptions{OrderBy: orderBy, |
|
|
|
|
|
|
|
Page: page, |
|
|
|
|
|
|
|
PageSize: opts.PageSize, |
|
|
|
|
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "opts.Ranger", err) |
|
|
|
ctx.Handle(500, "opts.Ranger", err) |
|
|
|
return |
|
|
|
return |
|
|
@ -172,7 +215,7 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { |
|
|
|
users, count, err = models.SearchUserByName(&models.SearchUserOptions{ |
|
|
|
users, count, err = models.SearchUserByName(&models.SearchUserOptions{ |
|
|
|
Keyword: keyword, |
|
|
|
Keyword: keyword, |
|
|
|
Type: opts.Type, |
|
|
|
Type: opts.Type, |
|
|
|
OrderBy: opts.OrderBy, |
|
|
|
OrderBy: orderBy, |
|
|
|
Page: page, |
|
|
|
Page: page, |
|
|
|
PageSize: opts.PageSize, |
|
|
|
PageSize: opts.PageSize, |
|
|
|
}) |
|
|
|
}) |
|
|
@ -201,7 +244,6 @@ func ExploreUsers(ctx *context.Context) { |
|
|
|
Counter: models.CountUsers, |
|
|
|
Counter: models.CountUsers, |
|
|
|
Ranger: models.Users, |
|
|
|
Ranger: models.Users, |
|
|
|
PageSize: setting.UI.ExplorePagingNum, |
|
|
|
PageSize: setting.UI.ExplorePagingNum, |
|
|
|
OrderBy: "name ASC", |
|
|
|
|
|
|
|
TplName: tplExploreUsers, |
|
|
|
TplName: tplExploreUsers, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -217,7 +259,6 @@ func ExploreOrganizations(ctx *context.Context) { |
|
|
|
Counter: models.CountOrganizations, |
|
|
|
Counter: models.CountOrganizations, |
|
|
|
Ranger: models.Organizations, |
|
|
|
Ranger: models.Organizations, |
|
|
|
PageSize: setting.UI.ExplorePagingNum, |
|
|
|
PageSize: setting.UI.ExplorePagingNum, |
|
|
|
OrderBy: "name ASC", |
|
|
|
|
|
|
|
TplName: tplExploreOrganizations, |
|
|
|
TplName: tplExploreOrganizations, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|