mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-12 08:23:48 +02:00
0f9188597e
- Add pagination support to the API endpoints that return lists of items - Adjust UI to enable infinite scrolling via pagination
21 lines
371 B
Go
21 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)]
|
|
}
|