miniflux-v2/ui/pagination.go

47 lines
927 B
Go
Raw Normal View History

2017-11-20 06:10:04 +01:00
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package ui
2017-11-20 06:10:04 +01:00
const (
2017-11-28 06:30:04 +01:00
nbItemsPerPage = 100
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
ShowPrev bool
NextOffset int
PrevOffset int
}
2017-11-28 06:30:04 +01:00
func (c *Controller) getPagination(route string, total, offset int) pagination {
2017-11-20 06:10:04 +01:00
nextOffset := 0
prevOffset := 0
2017-11-28 06:30:04 +01:00
showNext := (total - offset) > nbItemsPerPage
2017-11-20 06:10:04 +01:00
showPrev := offset > 0
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,
NextOffset: nextOffset,
ShowPrev: showPrev,
PrevOffset: prevOffset,
}
}