pagination.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }
  19. func getPagination(route string, total, offset, nbItemsPerPage int) pagination {
  20. nextOffset := 0
  21. prevOffset := 0
  22. firstOffset := 0
  23. lastOffset := (total / nbItemsPerPage) * nbItemsPerPage
  24. if lastOffset == total {
  25. lastOffset -= nbItemsPerPage
  26. }
  27. showNext := (total - offset) > nbItemsPerPage
  28. showPrev := offset > 0
  29. showLast := showNext
  30. showFirst := showPrev
  31. if showNext {
  32. nextOffset = offset + nbItemsPerPage
  33. }
  34. if showPrev {
  35. prevOffset = offset - nbItemsPerPage
  36. }
  37. return pagination{
  38. Route: route,
  39. Total: total,
  40. Offset: offset,
  41. ItemsPerPage: nbItemsPerPage,
  42. ShowNext: showNext,
  43. ShowLast: showLast,
  44. NextOffset: nextOffset,
  45. LastOffset: lastOffset,
  46. ShowPrev: showPrev,
  47. ShowFirst: showFirst,
  48. PrevOffset: prevOffset,
  49. FirstOffset: firstOffset,
  50. }
  51. }