pagination.go 948 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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
  5. const (
  6. nbItemsPerPage = 100
  7. )
  8. type pagination struct {
  9. Route string
  10. Total int
  11. Offset int
  12. ItemsPerPage int
  13. ShowNext bool
  14. ShowPrev bool
  15. NextOffset int
  16. PrevOffset int
  17. SearchQuery string
  18. }
  19. func (c *Controller) getPagination(route string, total, offset int) pagination {
  20. nextOffset := 0
  21. prevOffset := 0
  22. showNext := (total - offset) > nbItemsPerPage
  23. showPrev := offset > 0
  24. if showNext {
  25. nextOffset = offset + nbItemsPerPage
  26. }
  27. if showPrev {
  28. prevOffset = offset - nbItemsPerPage
  29. }
  30. return pagination{
  31. Route: route,
  32. Total: total,
  33. Offset: offset,
  34. ItemsPerPage: nbItemsPerPage,
  35. ShowNext: showNext,
  36. NextOffset: nextOffset,
  37. ShowPrev: showPrev,
  38. PrevOffset: prevOffset,
  39. }
  40. }