|
|
@ -5,8 +5,6 @@ |
|
|
|
package routers |
|
|
|
package routers |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/paginater" |
|
|
|
"github.com/Unknwon/paginater" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/models" |
|
|
@ -45,80 +43,39 @@ func Home(ctx *context.Context) { |
|
|
|
ctx.HTML(200, HOME) |
|
|
|
ctx.HTML(200, HOME) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type RepoSearchOptions struct { |
|
|
|
func ExploreRepos(ctx *context.Context) { |
|
|
|
Counter func(bool) int64 |
|
|
|
ctx.Data["Title"] = ctx.Tr("explore") |
|
|
|
Ranger func(int, int) ([]*models.Repository, error) |
|
|
|
ctx.Data["PageIsExplore"] = true |
|
|
|
Private bool |
|
|
|
ctx.Data["PageIsExploreRepositories"] = true |
|
|
|
PageSize int |
|
|
|
|
|
|
|
OrderBy string |
|
|
|
|
|
|
|
TplName base.TplName |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { |
|
|
|
|
|
|
|
page := ctx.QueryInt("page") |
|
|
|
page := ctx.QueryInt("page") |
|
|
|
if page <= 0 { |
|
|
|
if page <= 0 { |
|
|
|
page = 1 |
|
|
|
page = 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
|
|
|
repos []*models.Repository |
|
|
|
|
|
|
|
count int64 |
|
|
|
|
|
|
|
err error |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
keyword := ctx.Query("q") |
|
|
|
keyword := ctx.Query("q") |
|
|
|
if len(keyword) == 0 { |
|
|
|
repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{ |
|
|
|
repos, err = opts.Ranger(page, opts.PageSize) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "opts.Ranger", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
count = opts.Counter(opts.Private) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
var ctxUserID int64 |
|
|
|
|
|
|
|
if ctx.IsSigned { |
|
|
|
|
|
|
|
ctxUserID = ctx.User.ID |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ |
|
|
|
|
|
|
|
Keyword: keyword, |
|
|
|
Keyword: keyword, |
|
|
|
UserID: ctxUserID, |
|
|
|
UserID: ctx.UserID(), |
|
|
|
OrderBy: opts.OrderBy, |
|
|
|
OrderBy: "updated_unix DESC", |
|
|
|
Private: opts.Private, |
|
|
|
|
|
|
|
Page: page, |
|
|
|
Page: page, |
|
|
|
PageSize: opts.PageSize, |
|
|
|
PageSize: setting.UI.ExplorePagingNum, |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "SearchRepositoryByName", err) |
|
|
|
ctx.Handle(500, "SearchRepositoryByName", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Keyword"] = 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), setting.UI.ExplorePagingNum, page, 5) |
|
|
|
|
|
|
|
|
|
|
|
for _, repo := range repos { |
|
|
|
if err = models.RepositoryList(repos).LoadAttributes(); err != nil { |
|
|
|
if err = repo.GetOwner(); err != nil { |
|
|
|
ctx.Handle(500, "LoadAttributes", err) |
|
|
|
ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err)) |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["Repos"] = repos |
|
|
|
ctx.Data["Repos"] = repos |
|
|
|
|
|
|
|
|
|
|
|
ctx.HTML(200, opts.TplName) |
|
|
|
ctx.HTML(200, EXPLORE_REPOS) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func ExploreRepos(ctx *context.Context) { |
|
|
|
|
|
|
|
ctx.Data["Title"] = ctx.Tr("explore") |
|
|
|
|
|
|
|
ctx.Data["PageIsExplore"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsExploreRepositories"] = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RenderRepoSearch(ctx, &RepoSearchOptions{ |
|
|
|
|
|
|
|
Counter: models.CountRepositories, |
|
|
|
|
|
|
|
Ranger: models.GetRecentUpdatedRepositories, |
|
|
|
|
|
|
|
PageSize: setting.UI.ExplorePagingNum, |
|
|
|
|
|
|
|
OrderBy: "updated_unix DESC", |
|
|
|
|
|
|
|
TplName: EXPLORE_REPOS, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type UserSearchOptions struct { |
|
|
|
type UserSearchOptions struct { |
|
|
|