2019-10-09 01:19:57 +02:00
|
|
|
defmodule PhilomenaWeb.PaginationView do
|
|
|
|
use PhilomenaWeb, :view
|
|
|
|
|
|
|
|
def first_page?(page) do
|
|
|
|
page.page_number == 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def last_page?(page) do
|
|
|
|
page.page_number == page.total_pages
|
|
|
|
end
|
|
|
|
|
|
|
|
def page_path(route, params, number) do
|
2019-12-08 18:55:55 +01:00
|
|
|
route.([{:page, number} | params])
|
2019-10-09 01:19:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def first_page_path(_page, route, params), do: page_path(route, params, 1)
|
|
|
|
def prev_page_path(page, route, params), do: page_path(route, params, page.page_number - 1)
|
|
|
|
def next_page_path(page, route, params), do: page_path(route, params, page.page_number + 1)
|
|
|
|
def last_page_path(page, route, params), do: page_path(route, params, page.total_pages)
|
|
|
|
|
|
|
|
def left_gap?(page) do
|
|
|
|
page.page_number >= 5
|
|
|
|
end
|
|
|
|
|
|
|
|
def left_page_numbers(page) do
|
|
|
|
number = page.page_number
|
|
|
|
min = 1
|
|
|
|
max = page.total_pages
|
|
|
|
|
2020-01-11 05:20:19 +01:00
|
|
|
(number - 5)..number
|
|
|
|
|> Enum.filter(&(&1 >= min and &1 != number and &1 <= max))
|
2019-10-09 01:19:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def right_gap?(page) do
|
|
|
|
page.total_pages - page.page_number >= 5
|
|
|
|
end
|
|
|
|
|
|
|
|
def right_page_numbers(page) do
|
|
|
|
number = page.page_number
|
|
|
|
min = 1
|
|
|
|
max = page.total_pages
|
|
|
|
|
2020-01-11 05:20:19 +01:00
|
|
|
number..(number + 5)
|
|
|
|
|> Enum.filter(&(&1 >= min and &1 != number and &1 <= max))
|
2019-10-09 01:19:57 +02:00
|
|
|
end
|
|
|
|
end
|