pagination.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package ui // import "miniflux.app/v2/internal/ui"
  4. type pagination struct {
  5. Route string
  6. Total int
  7. Offset int
  8. ItemsPerPage int
  9. ShowNext bool
  10. ShowLast bool
  11. ShowFirst bool
  12. ShowPrev bool
  13. NextOffset int
  14. LastOffset int
  15. PrevOffset int
  16. FirstOffset int
  17. SearchQuery string
  18. UnreadOnly bool
  19. }
  20. func getPagination(route string, total, offset, nbItemsPerPage int) pagination {
  21. nextOffset := 0
  22. prevOffset := 0
  23. firstOffset := 0
  24. lastOffset := (total / nbItemsPerPage) * nbItemsPerPage
  25. if lastOffset == total {
  26. lastOffset -= nbItemsPerPage
  27. }
  28. showNext := (total - offset) > nbItemsPerPage
  29. showPrev := offset > 0
  30. showLast := showNext
  31. showFirst := showPrev
  32. if showNext {
  33. nextOffset = offset + nbItemsPerPage
  34. }
  35. if showPrev {
  36. prevOffset = offset - nbItemsPerPage
  37. }
  38. return pagination{
  39. Route: route,
  40. Total: total,
  41. Offset: offset,
  42. ItemsPerPage: nbItemsPerPage,
  43. ShowNext: showNext,
  44. ShowLast: showLast,
  45. NextOffset: nextOffset,
  46. LastOffset: lastOffset,
  47. ShowPrev: showPrev,
  48. ShowFirst: showFirst,
  49. PrevOffset: prevOffset,
  50. FirstOffset: firstOffset,
  51. }
  52. }