Also fixed pagination for negative offsets (refs #54)

This commit is contained in:
Timo Smit 2017-02-04 14:20:18 +01:00
parent e962fde32e
commit 1fe77fdaa4
1 changed files with 8 additions and 4 deletions

View File

@ -22,10 +22,14 @@ function pagination.calculate(count, limit, offset)
offset = offset or 0 offset = offset or 0
if offset < 0 then if offset < 0 then
if count < math.abs(offset) then
limit = count
offset = 0
else
limit = math.min(math.abs(offset), 30)
offset = count + offset offset = count + offset
end end
elseif limit + offset > count then
if limit + offset > count then
limit = count % limit limit = count % limit
end end