lhs 20.1.3.pre.paginationfix.2 → 20.1.3.pre.paginationfix.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhs/pagination/base.rb +8 -4
- data/lib/lhs/pagination/offset.rb +4 -0
- data/lib/lhs/pagination/page.rb +4 -0
- data/lib/lhs/pagination/start.rb +4 -0
- data/lib/lhs/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9284aed364b9d0b32bd9341399c4c8309aa3438c4d6e073b89a7d4f3fcaab21
|
4
|
+
data.tar.gz: d3c50128acf732d233b61d2930f22a38d48102dca92fb13ab2f2f88a03108767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f75419036051feb2e65f155a59dfedf1364f2fb23f2f97bab4615fce6152ae8158f249a20f97308a4e8284c70180de920d5dc97ab13fbfd8f8876d2888aee7aa
|
7
|
+
data.tar.gz: 248054e48c2a757db5575c982f17356038d9d63d475f24fbd320c2bb1732481d7ff9ccc3c70b4baa50bef5c21701bec1ac2d0916ed917fdab30f58737d7472cf
|
data/lib/lhs/pagination/base.rb
CHANGED
@@ -23,12 +23,12 @@ module LHS::Pagination
|
|
23
23
|
alias count total
|
24
24
|
|
25
25
|
def limit
|
26
|
-
|
27
|
-
requested_limit = data._request.params.dig(*_record.limit_key(:params))
|
28
|
-
if
|
26
|
+
response_limit = data._raw.dig(*_record.limit_key(:body))
|
27
|
+
requested_limit = data._request.params.dig(*_record.limit_key(:params)).to_i if data&._request&.params.present?
|
28
|
+
if requested_limit && response_limit && last_page?(response_limit, requested_limit) && response_limit < requested_limit
|
29
29
|
requested_limit
|
30
30
|
else
|
31
|
-
|
31
|
+
response_limit || DEFAULT_LIMIT
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -53,6 +53,10 @@ module LHS::Pagination
|
|
53
53
|
# should be implemented in subclass (optional)
|
54
54
|
end
|
55
55
|
|
56
|
+
def last_page?
|
57
|
+
raise 'to be implemented in subclass'
|
58
|
+
end
|
59
|
+
|
56
60
|
def first_page
|
57
61
|
1
|
58
62
|
end
|
@@ -12,6 +12,10 @@ class LHS::Pagination::Offset < LHS::Pagination::Base
|
|
12
12
|
self.class.next_offset(offset, limit, step)
|
13
13
|
end
|
14
14
|
|
15
|
+
def last_page?(response_limit, requested_limit)
|
16
|
+
offset + response_limit >= total
|
17
|
+
end
|
18
|
+
|
15
19
|
def self.page_to_offset(page, limit = DEFAULT_LIMIT)
|
16
20
|
(page.to_i - 1) * limit.to_i
|
17
21
|
end
|
data/lib/lhs/pagination/page.rb
CHANGED
@@ -8,6 +8,10 @@ class LHS::Pagination::Page < LHS::Pagination::Base
|
|
8
8
|
offset
|
9
9
|
end
|
10
10
|
|
11
|
+
def last_page?(response_limit, requested_limit)
|
12
|
+
(offset-1 * requested_limit) + response_limit >= total
|
13
|
+
end
|
14
|
+
|
11
15
|
def next_offset(step = 1)
|
12
16
|
self.class.next_offset(current_page, limit, step)
|
13
17
|
end
|
data/lib/lhs/pagination/start.rb
CHANGED
@@ -12,6 +12,10 @@ class LHS::Pagination::Start < LHS::Pagination::Base
|
|
12
12
|
self.class.next_offset(offset, limit, step)
|
13
13
|
end
|
14
14
|
|
15
|
+
def last_page?(response_limit, requested_limit)
|
16
|
+
offset + response_limit > total
|
17
|
+
end
|
18
|
+
|
15
19
|
def self.page_to_offset(page, limit = DEFAULT_LIMIT)
|
16
20
|
(page.to_i - 1) * limit.to_i + 1
|
17
21
|
end
|
data/lib/lhs/version.rb
CHANGED