Fix bug about ListOptions and stars/watchers pagnation (#14556)
* Fix bug about ListOptions and stars/watchers pagnation * fix unit test Co-authored-by: 6543 <6543@obermui.de>release/v1.15
parent
80b1d02b2f
commit
3537d80088
|
@ -18,7 +18,7 @@ func TestGetCommitStatuses(t *testing.T) {
|
||||||
|
|
||||||
sha1 := "1234123412341234123412341234123412341234"
|
sha1 := "1234123412341234123412341234123412341234"
|
||||||
|
|
||||||
statuses, maxResults, err := GetCommitStatuses(repo1, sha1, &CommitStatusOptions{})
|
statuses, maxResults, err := GetCommitStatuses(repo1, sha1, &CommitStatusOptions{ListOptions: ListOptions{Page: 1, PageSize: 50}})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int(maxResults), 5)
|
assert.Equal(t, int(maxResults), 5)
|
||||||
assert.Len(t, statuses, 5)
|
assert.Len(t, statuses, 5)
|
||||||
|
|
|
@ -16,13 +16,13 @@ type ListOptions struct {
|
||||||
Page int // start from 1
|
Page int // start from 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts ListOptions) getPaginatedSession() *xorm.Session {
|
func (opts *ListOptions) getPaginatedSession() *xorm.Session {
|
||||||
opts.setDefaultValues()
|
opts.setDefaultValues()
|
||||||
|
|
||||||
return x.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
|
return x.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts ListOptions) setSessionPagination(sess *xorm.Session) *xorm.Session {
|
func (opts *ListOptions) setSessionPagination(sess *xorm.Session) *xorm.Session {
|
||||||
opts.setDefaultValues()
|
opts.setDefaultValues()
|
||||||
|
|
||||||
if opts.PageSize <= 0 {
|
if opts.PageSize <= 0 {
|
||||||
|
@ -31,21 +31,21 @@ func (opts ListOptions) setSessionPagination(sess *xorm.Session) *xorm.Session {
|
||||||
return sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
|
return sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts ListOptions) setEnginePagination(e Engine) Engine {
|
func (opts *ListOptions) setEnginePagination(e Engine) Engine {
|
||||||
opts.setDefaultValues()
|
opts.setDefaultValues()
|
||||||
|
|
||||||
return e.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
|
return e.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStartEnd returns the start and end of the ListOptions
|
// GetStartEnd returns the start and end of the ListOptions
|
||||||
func (opts ListOptions) GetStartEnd() (start, end int) {
|
func (opts *ListOptions) GetStartEnd() (start, end int) {
|
||||||
opts.setDefaultValues()
|
opts.setDefaultValues()
|
||||||
start = (opts.Page - 1) * opts.PageSize
|
start = (opts.Page - 1) * opts.PageSize
|
||||||
end = start + opts.Page
|
end = start + opts.Page
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts ListOptions) setDefaultValues() {
|
func (opts *ListOptions) setDefaultValues() {
|
||||||
if opts.PageSize <= 0 {
|
if opts.PageSize <= 0 {
|
||||||
opts.PageSize = setting.API.DefaultPagingNum
|
opts.PageSize = setting.API.DefaultPagingNum
|
||||||
}
|
}
|
||||||
|
|
|
@ -713,7 +713,10 @@ func RenderUserCards(ctx *context.Context, total int, getter func(opts models.Li
|
||||||
pager := context.NewPagination(total, models.ItemsPerPage, page, 5)
|
pager := context.NewPagination(total, models.ItemsPerPage, page, 5)
|
||||||
ctx.Data["Page"] = pager
|
ctx.Data["Page"] = pager
|
||||||
|
|
||||||
items, err := getter(models.ListOptions{Page: pager.Paginater.Current()})
|
items, err := getter(models.ListOptions{
|
||||||
|
Page: pager.Paginater.Current(),
|
||||||
|
PageSize: models.ItemsPerPage,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("getter", err)
|
ctx.ServerError("getter", err)
|
||||||
return
|
return
|
||||||
|
@ -744,6 +747,7 @@ func Stars(ctx *context.Context) {
|
||||||
func Forks(ctx *context.Context) {
|
func Forks(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("repos.forks")
|
ctx.Data["Title"] = ctx.Tr("repos.forks")
|
||||||
|
|
||||||
|
// TODO: need pagination
|
||||||
forks, err := ctx.Repo.Repository.GetForks(models.ListOptions{})
|
forks, err := ctx.Repo.Repository.GetForks(models.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetForks", err)
|
ctx.ServerError("GetForks", err)
|
||||||
|
|
Loading…
Reference in New Issue