miniflux/internal/ui/pagination.go

60 lines
1.2 KiB
Go
Raw Normal View History

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