pagination.go 908 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. ShowPrev bool
  11. NextOffset int
  12. PrevOffset int
  13. SearchQuery string
  14. }
  15. func getPagination(route string, total, offset, nbItemsPerPage int) pagination {
  16. nextOffset := 0
  17. prevOffset := 0
  18. showNext := (total - offset) > nbItemsPerPage
  19. showPrev := offset > 0
  20. if showNext {
  21. nextOffset = offset + nbItemsPerPage
  22. }
  23. if showPrev {
  24. prevOffset = offset - nbItemsPerPage
  25. }
  26. return pagination{
  27. Route: route,
  28. Total: total,
  29. Offset: offset,
  30. ItemsPerPage: nbItemsPerPage,
  31. ShowNext: showNext,
  32. NextOffset: nextOffset,
  33. ShowPrev: showPrev,
  34. PrevOffset: prevOffset,
  35. }
  36. }