ocean-rails 2.0.8 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ocean/api_resource.rb +2 -2
- data/lib/ocean/ocean_application_controller.rb +15 -2
- data/lib/ocean/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd77052a13c531215d5a319c731f04a71b52641
|
4
|
+
data.tar.gz: 1f6993cbf041b79efe6f58c7dca63fddd0a23ba4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d190b929b801a83006b50a2f97022f97b46241233059c5e2d6e2ff3c398eefd0f894e64a2c4ef353b860665ed1fd2accc4cd19b436837d6ab75304c7b4730cbe
|
7
|
+
data.tar.gz: 4c278e2e491ca601d85b5d1100223f80e3012dcb2d4a36c4c68cec5e50ce69bae167a17fbb673b2318d7bcfde2d4dc485239d70e3238b301fe301f0a74159fac
|
data/lib/ocean/api_resource.rb
CHANGED
@@ -73,9 +73,9 @@ module ApiResource
|
|
73
73
|
# Pagination
|
74
74
|
if page.present?
|
75
75
|
page = page.to_i
|
76
|
-
page_size = page_size.to_i
|
77
76
|
return query.none if page < 0
|
78
|
-
|
77
|
+
page_size = page_size.to_i || collection_page_size
|
78
|
+
query = query.limit(page_size).offset(page_size * page)
|
79
79
|
end
|
80
80
|
# Finally, return the accumulated Relation
|
81
81
|
query
|
@@ -176,12 +176,25 @@ module OceanApplicationController
|
|
176
176
|
else
|
177
177
|
resources = x.dup.collect { |m| render_to_string(partial: m.to_partial_path,
|
178
178
|
locals: {m.class.model_name.i18n_key => m}) }
|
179
|
-
|
180
|
-
|
179
|
+
count = resources.count
|
180
|
+
total_count = x.unscope(:limit, :offset).count
|
181
|
+
attrs = {count: count,
|
182
|
+
total_count: total_count
|
181
183
|
}
|
182
184
|
links = {}
|
183
185
|
if href
|
184
186
|
links['self'] = {href: href, type: 'application/json'}
|
187
|
+
if params[:page]
|
188
|
+
page = params[:page].to_i
|
189
|
+
page_size = params[:page_size].to_i || x.collection_page_size
|
190
|
+
last_page = (total_count / page_size).ceil
|
191
|
+
prev_page = page > 0 && page - 1
|
192
|
+
next_page = page != last_page && page + 1
|
193
|
+
links['first_page'] = {href: url_for(params.merge(page: 0)), type: 'application/json'}
|
194
|
+
links['last_page'] = {href: url_for(params.merge(page: last_page)), type: 'application/json'}
|
195
|
+
links['previous_page'] = {href: url_for(params.merge(page: prev_page)), type: 'application/json'} if prev_page
|
196
|
+
links['next_page'] = {href: url_for(params.merge(page: next_page)), type: 'application/json'} if next_page
|
197
|
+
end
|
185
198
|
end
|
186
199
|
if links
|
187
200
|
attrs['_links'] = links
|
data/lib/ocean/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocean-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Bengtson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|