now with pagination
This commit is contained in:
@@ -13,4 +13,24 @@ defmodule LabelmakerWeb.LabelsHTML do
|
||||
|
||||
defp pad(num) when num < 10, do: "0#{num}"
|
||||
defp pad(num), do: "#{num}"
|
||||
|
||||
def pagination_range(current_page, total_pages) do
|
||||
cond do
|
||||
total_pages <= 7 ->
|
||||
# Show all pages if there are 7 or fewer
|
||||
1..total_pages
|
||||
|
||||
current_page <= 4 ->
|
||||
# Near the beginning: show first 5, then last
|
||||
[1, 2, 3, 4, 5, :ellipsis, total_pages]
|
||||
|
||||
current_page >= total_pages - 3 ->
|
||||
# Near the end: show first, then last 5
|
||||
[1, :ellipsis, total_pages - 4, total_pages - 3, total_pages - 2, total_pages - 1, total_pages]
|
||||
|
||||
true ->
|
||||
# In the middle: show first, current +/- 1, and last
|
||||
[1, :ellipsis, current_page - 1, current_page, current_page + 1, :ellipsis, total_pages]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user