mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 12:21:03 +00:00
0f9188597e
- Add pagination support to the API endpoints that return lists of items - Adjust UI to enable infinite scrolling via pagination
20 lines
371 B
Go
20 lines
371 B
Go
package model
|
|
|
|
type ListOptions struct {
|
|
All bool
|
|
Page int
|
|
PerPage int
|
|
}
|
|
|
|
func ApplyPagination[T any](d *ListOptions, slice []T) []T {
|
|
if d.All {
|
|
return slice
|
|
}
|
|
if d.PerPage*(d.Page-1) > len(slice) {
|
|
return []T{}
|
|
}
|
|
if d.PerPage*(d.Page) > len(slice) {
|
|
return slice[d.PerPage*(d.Page-1):]
|
|
}
|
|
return slice[d.PerPage*(d.Page-1) : d.PerPage*(d.Page)]
|
|
}
|