data_tables-responder 0.3.1 → 0.3.2

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: 1946685a7d2ed739b245b8c11ed085f976db2a6a
4
- data.tar.gz: 3ae44f3298539852f0b441b7141bee76b3c0c74c
3
+ metadata.gz: 1b8e8b8bde92df9cf464672c0272403a5b10025e
4
+ data.tar.gz: f777b05dc78a0b3e2e5cc6cbeeb021069502b162
5
5
  SHA512:
6
- metadata.gz: c8c7f010af76b62d868ab3ff270495d3a010c8aa220008ed92122de9f227cb60317b9a5ed94ab8f448abbff16e1d878a5d131e17735b0245c5a71319a96462aa
7
- data.tar.gz: e3228c8be84958dec33da231ec4496e0e316b10f1d0c08710c366100d027c10fc8e8a814063fa547e7b42c32a1bdea3dc48a73d7dbaae140cd058fd9c4301613
6
+ metadata.gz: a50cabb76cb4539b913fd7a4d839fec3400dfa3a3862a51a1a0106234b2dd4c81a225abe823670ffc300eba6edee6e690ff64d9c47e575c7ab2b8f51402f1927
7
+ data.tar.gz: d6a683c1f43ad56869ec4d4adcfed6aec6a785c898e84f57ae9d742f38444632486bb08ecf4465a2f62014b8ef429313f4c1a626e322a1b28827c2467c513196
@@ -11,11 +11,40 @@ module DataTables
11
11
 
12
12
  def as_h
13
13
  {
14
- recordsTotal: collection&.total_entries&.to_i,
15
- recordsFiltered: collection&.unscope(:limit, :offset)&.count_estimate&.to_i
14
+ recordsTotal: records_total,
15
+ recordsFiltered: records_filtered
16
16
  }
17
17
  end
18
18
 
19
+ protected
20
+
21
+ def records_filtered
22
+ @records_filtered ||= get_records_filtered
23
+ end
24
+
25
+ def records_total
26
+ @records_total ||= get_records_total
27
+ end
28
+
29
+ private
30
+
31
+ def get_records_filtered
32
+ if records_total < 1_000_000
33
+ @collection.unscope(:limit, :offset).count(@collection.model.primary_key).to_i
34
+ else
35
+ @collection.unscope(:limit, :offset).count_estimate.to_i
36
+ end
37
+ end
38
+
39
+ def get_records_total
40
+ count = @collection.model.all.count_estimate.to_i
41
+ if count < 1_000_000
42
+ count = @collection.model.all.count(@collection.model.primary_key).to_i
43
+ end
44
+
45
+ count
46
+ end
47
+
19
48
  end
20
49
  end
21
50
  end
@@ -3,6 +3,7 @@ require 'count_estimate'
3
3
  module DataTables
4
4
  module Modules
5
5
  class Pagination
6
+
6
7
  FIRST_PAGE = 1
7
8
 
8
9
  attr_reader :original_scope, :filtered_scope, :context
@@ -16,37 +17,10 @@ module DataTables
16
17
  def paginate
17
18
  start = (@request_parameters[:start] || '0').to_i
18
19
  length = (@request_parameters[:length] || '10').to_i
19
- page = (start / length) + 1
20
- @filtered_scope = @filtered_scope.paginate(page: page, per_page: length, total_entries: records_total)
21
- end
22
-
23
- def as_json
24
- {
25
- recordsTotal: @filtered_scope&.total_entries&.to_i,
26
- recordsFiltered: records_filtered&.to_i
27
- }
20
+ page = (start / length)
21
+ @filtered_scope = @filtered_scope.offset(page * length).limit(length)
28
22
  end
29
23
 
30
- protected
31
-
32
- def records_total
33
- # TODO: Check threshold
34
- count_estimate = @original_scope&.model&.all&.count_estimate.to_i
35
- if count_estimate < 1_000_000
36
- count_estimate = @original_scope&.count
37
- end
38
-
39
- count_estimate
40
- end
41
-
42
- def records_filtered
43
- @filtered_scope&.unscope(:limit, :offset)&.count_estimate
44
- end
45
-
46
- attr_reader :adapter_options
47
-
48
- private
49
-
50
24
  end
51
25
  end
52
26
  end
@@ -1,5 +1,5 @@
1
1
  module DataTables
2
2
  module Responder
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_tables-responder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Stevens
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-31 00:00:00.000000000 Z
11
+ date: 2017-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers