4
0

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. SearchQuery string
  7. Total int
  8. Offset int
  9. ItemsPerPage int
  10. NextOffset int
  11. LastOffset int
  12. PrevOffset int
  13. FirstOffset int
  14. UnreadOnly bool
  15. ShowNext bool
  16. ShowLast bool
  17. ShowFirst bool
  18. ShowPrev 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. }