revelry_data 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 296d23f0e98e46c0664f29d1ad6118e68040397c
4
- data.tar.gz: 239ce54dbab4b6b0767210e2d593da8a6f0e8fbf
3
+ metadata.gz: 10cd7dcfe553e5719b1cb11796a557461db29956
4
+ data.tar.gz: 7028002a103dc8f9ca5ea086524f534af774d628
5
5
  SHA512:
6
- metadata.gz: bd54d37f10245203fc85dd18aef903371116c15f80dec10ce34dc27b0959aac3c244236907b2ffc3efe1b746f0cda21c92649d7ff2aa5a5f02a26ce5533f0f7b
7
- data.tar.gz: 3fc04359f2d45878ac49bbe49d77250b07c4db59714ff0a9104cade2fa23cfeab886dcebcb86d1ba2650330904cc3e1b802087808ef13f6043605b0100641efa
6
+ metadata.gz: 9c0731b30fa3ff57853dc9b11de52123dc25a8633478de669d838b1a8e8461bcab870f499ee40a4789cc78dfcc2ff3bdae0a94a9c94c9cf4fc9277b9126e7683
7
+ data.tar.gz: 26826ec838e7fb5f33f1febdc91a32cd3adb98743c656a5f6da0bff264ba0b31c9db58230928802cc58a9d6e0a22e9d5767d52b8aaecd3087cb9b1b025851f5c
@@ -65,7 +65,7 @@ class CollectionQueryParameters {
65
65
  * @param {String} newValue - the new value of the filter to apply
66
66
  */
67
67
  setFilter(filterName, newValue) {
68
- // if filter changes, reset pagination
68
+ // if filter changes, reset pagination
69
69
  if (this.filters[filterName] !== newValue) {
70
70
  this.resetPage()
71
71
  }
@@ -96,6 +96,38 @@ class CollectionQueryParameters {
96
96
  this.page = n
97
97
  }
98
98
 
99
+ /**
100
+ * Get the currently selected paginaion size
101
+ */
102
+ getSize() {
103
+ return this.size
104
+ }
105
+
106
+ /**
107
+ * Set the selected size to a new value and fetch is `fetchExplicitly` is
108
+ * `false`
109
+ * @param {Integer} n - the new size number
110
+ */
111
+ setSize(n) {
112
+ this.size = n
113
+ }
114
+
115
+ /**
116
+ * Get the currently selected pagination limit
117
+ */
118
+ getLimit() {
119
+ return this.offset
120
+ }
121
+
122
+ /**
123
+ * Set the selected limit to a new value and fetch is `fetchExplicitly` is
124
+ * `false`
125
+ * @param {Integer} n - the new limit number
126
+ */
127
+ setLimit(n) {
128
+ this.limit = n
129
+ }
130
+
99
131
  /**
100
132
  * Get the currently selected page number (1 by default)
101
133
  */
@@ -129,6 +161,34 @@ class CollectionQueryParameters {
129
161
  this.maybeFetch()
130
162
  }
131
163
 
164
+ /**
165
+ * Set the selected size to a new value, limit to null, resets page
166
+ * and fetch is `fetchExplicitly` is `false`
167
+ * https://github.com/cerebris/jsonapi-resources#paged-paginator
168
+ * @param {Integer} n - the new pagination size
169
+ */
170
+
171
+ set size(n) {
172
+ this._size = n
173
+ this._limit = null
174
+ this.resetPage()
175
+ this.maybeFetch()
176
+ }
177
+
178
+ /**
179
+ * Set the selected limit to a new value, size to null, resets page
180
+ * and fetch is `fetchExplicitly` is `false`
181
+ * https://github.com/cerebris/jsonapi-resources#offset-paginator
182
+ * @param {Integer} n - the new pagination limit
183
+ */
184
+
185
+ set limit(n) {
186
+ this._limit = n
187
+ this._size = null
188
+ this.resetPage()
189
+ this.maybeFetch()
190
+ }
191
+
132
192
  /**
133
193
  * Get the currently selected page number (1 by default)
134
194
  */
@@ -136,6 +196,47 @@ class CollectionQueryParameters {
136
196
  return this._page || 1
137
197
  }
138
198
 
199
+ get offset(){
200
+ if(this.page > 1){
201
+ return (this.page - 1) * this.limit
202
+ }
203
+
204
+ return 0;
205
+ }
206
+
207
+ /**
208
+ * Get the currently selected size for pagination
209
+ */
210
+
211
+ get size() {
212
+ return this._size
213
+ }
214
+
215
+ /**
216
+ * Get the currently selected limit for pagination
217
+ */
218
+
219
+ get limit() {
220
+ return this._limit
221
+ }
222
+
223
+ /**
224
+ * Get the currently selected paginator type:
225
+ * If size exist it returns paged
226
+ * If limit exist it returns offset
227
+ * If no-one exist it returns nil for backward compatibility
228
+ */
229
+
230
+ get paginatorType() {
231
+ if(this.size){
232
+ return "paged"
233
+ }
234
+
235
+ if(this.limit){
236
+ return "offset"
237
+ }
238
+ }
239
+
139
240
  /**
140
241
  * Set the page back to page 1. Frequently we do this when changing sorting
141
242
  * or filtering options so that the user is not disoriented in the result set.
@@ -179,8 +280,18 @@ class CollectionQueryParameters {
179
280
  get fetchData() {
180
281
  // Pagination options
181
282
  let params = {
182
- page: this.page,
283
+ page: {},
284
+ }
285
+
286
+ // The size option if set, otherwise skip
287
+ if(this.paginatorType === "paged") {
288
+ _.extend(params.page, {size: this.size, number: this.page})
183
289
  }
290
+
291
+ if(this.paginatorType === "offset") {
292
+ _.extend(params.page, {limit: this.limit, offset: this.offset})
293
+ }
294
+
184
295
  // The sort option if set, otherwise skip
185
296
  if(this.sort) {
186
297
  _.extend(params, {sort: this.sort})
@@ -1,3 +1,3 @@
1
1
  module RevelryData
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  module RevelryData
2
2
  <<<<<<< HEAD
3
- VERSION = "0.1.0"
3
+ VERSION = "0.0.12"
4
4
  =======
5
- VERSION = "0.0.10"
6
- >>>>>>> v0.0.10
5
+ VERSION = "0.1.2"
6
+ >>>>>>> 936d168df25b6786791e8cc1dac501aebfeb45e7
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: revelry_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Prehn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -731,7 +731,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
731
731
  version: '0'
732
732
  requirements: []
733
733
  rubyforge_project:
734
- rubygems_version: 2.2.2
734
+ rubygems_version: 2.4.5.1
735
735
  signing_key:
736
736
  specification_version: 4
737
737
  summary: Revelry Data is a library for managing data within React applications using