pagination.go 943 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui // import "miniflux.app/ui"
  5. type pagination struct {
  6. Route string
  7. Total int
  8. Offset int
  9. ItemsPerPage int
  10. ShowNext bool
  11. ShowPrev bool
  12. NextOffset int
  13. PrevOffset int
  14. SearchQuery string
  15. }
  16. func getPagination(route string, total, offset, nbItemsPerPage int) pagination {
  17. nextOffset := 0
  18. prevOffset := 0
  19. showNext := (total - offset) > nbItemsPerPage
  20. showPrev := offset > 0
  21. if showNext {
  22. nextOffset = offset + nbItemsPerPage
  23. }
  24. if showPrev {
  25. prevOffset = offset - nbItemsPerPage
  26. }
  27. return pagination{
  28. Route: route,
  29. Total: total,
  30. Offset: offset,
  31. ItemsPerPage: nbItemsPerPage,
  32. ShowNext: showNext,
  33. NextOffset: nextOffset,
  34. ShowPrev: showPrev,
  35. PrevOffset: prevOffset,
  36. }
  37. }