1
0
Fork 0
miniflux/internal/ui/pagination.go

43 lines
908 B
Go
Raw Normal View History

// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
2017-11-20 00:10:04 -05:00
package ui // import "miniflux.app/v2/internal/ui"
2017-11-20 00:10:04 -05:00
2017-11-28 00:30:04 -05:00
type pagination struct {
2017-11-20 00:10:04 -05:00
Route string
Total int
Offset int
ItemsPerPage int
ShowNext bool
ShowPrev bool
NextOffset int
PrevOffset int
2018-07-05 01:05:19 -04:00
SearchQuery string
2017-11-20 00:10:04 -05:00
}
func getPagination(route string, total, offset, nbItemsPerPage int) pagination {
2017-11-20 00:10:04 -05:00
nextOffset := 0
prevOffset := 0
2017-11-28 00:30:04 -05:00
showNext := (total - offset) > nbItemsPerPage
2017-11-20 00:10:04 -05:00
showPrev := offset > 0
if showNext {
2017-11-28 00:30:04 -05:00
nextOffset = offset + nbItemsPerPage
2017-11-20 00:10:04 -05:00
}
if showPrev {
2017-11-28 00:30:04 -05:00
prevOffset = offset - nbItemsPerPage
2017-11-20 00:10:04 -05:00
}
2017-11-28 00:30:04 -05:00
return pagination{
2017-11-20 00:10:04 -05:00
Route: route,
Total: total,
Offset: offset,
2017-11-28 00:30:04 -05:00
ItemsPerPage: nbItemsPerPage,
2017-11-20 00:10:04 -05:00
ShowNext: showNext,
NextOffset: nextOffset,
ShowPrev: showPrev,
PrevOffset: prevOffset,
}
}