mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Always display self, first, last pagination links
This commit is contained in:
parent
dff621e174
commit
7387266c37
@ -35,19 +35,21 @@ module ActiveModelSerializers
|
|||||||
private
|
private
|
||||||
|
|
||||||
def pages_from
|
def pages_from
|
||||||
return {} if collection.total_pages <= FIRST_PAGE
|
|
||||||
|
|
||||||
{}.tap do |pages|
|
{}.tap do |pages|
|
||||||
pages[:self] = collection.current_page
|
pages[:self] = collection.current_page
|
||||||
|
pages[:first] = FIRST_PAGE
|
||||||
|
pages[:last] = collection.total_pages
|
||||||
|
|
||||||
unless collection.current_page == FIRST_PAGE
|
if collection.total_pages > 0
|
||||||
pages[:first] = FIRST_PAGE
|
unless collection.current_page == FIRST_PAGE
|
||||||
pages[:prev] = collection.current_page - FIRST_PAGE
|
pages[:prev] = collection.current_page - FIRST_PAGE
|
||||||
end
|
end
|
||||||
|
|
||||||
unless collection.current_page == collection.total_pages
|
unless collection.current_page == collection.total_pages
|
||||||
pages[:next] = collection.current_page + FIRST_PAGE
|
pages[:next] = collection.current_page + FIRST_PAGE
|
||||||
pages[:last] = collection.total_pages
|
end
|
||||||
|
else
|
||||||
|
pages[:last] = FIRST_PAGE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -54,6 +54,14 @@ module ActiveModelSerializers
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def empty_collection_links
|
||||||
|
{
|
||||||
|
self: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||||
|
first: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||||
|
last: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def links
|
def links
|
||||||
{
|
{
|
||||||
links: {
|
links: {
|
||||||
@ -71,6 +79,7 @@ module ActiveModelSerializers
|
|||||||
links: {
|
links: {
|
||||||
self: "#{URI}?page%5Bnumber%5D=3&page%5Bsize%5D=2",
|
self: "#{URI}?page%5Bnumber%5D=3&page%5Bsize%5D=2",
|
||||||
first: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
first: "#{URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||||
|
last: "#{URI}?page%5Bnumber%5D=3&page%5Bsize%5D=2",
|
||||||
prev: "#{URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2"
|
prev: "#{URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +120,7 @@ module ActiveModelSerializers
|
|||||||
def expected_response_with_no_data_pagination_links
|
def expected_response_with_no_data_pagination_links
|
||||||
{}.tap do |hash|
|
{}.tap do |hash|
|
||||||
hash[:data] = []
|
hash[:data] = []
|
||||||
hash[:links] = {}
|
hash.merge! links: empty_collection_links
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user