effective_resources 2.16.1 → 2.17.0

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
  SHA256:
3
- metadata.gz: 3b1e8e92150d8fa0101d28d961ccac6f0b8826a2992e22abe0f7f38ae185a498
4
- data.tar.gz: c479a6c8c700a8125241914ffe0a17a1b58da136fc28479d6d1f1a5005241575
3
+ metadata.gz: 55ffa99bff7ce09a36f31a7a12f9e0fb3eff53b07110a86724a1b7dad14a0438
4
+ data.tar.gz: 356be85dc5dd7cbaeb0bfdf562b22442ef7102277e4b76bd479e5a0e70823062
5
5
  SHA512:
6
- metadata.gz: 2db488f338acda47184ea4bf2a41d1420f338738ad97f98635e66353d00d9a5edcf61aaace5351c38becec2ee80f4884fcd7a522a3f661baa4f9b2671f0a23bb
7
- data.tar.gz: cbaea70caa43ceeb87b17fa1a31162c5d4b5369e3e5435073fb73b05c5c0dcb564f12948fb88dc62b010c1485e06880999c320c9c8a31bc01ad905df6a9e5668
6
+ metadata.gz: 676d8e7f03e37d0781c909570b543a8089d9eb5a8e54f215f05bedba1977b9ad49b99e009c2c5cf20a330294c2daf0079c455df957f0198d897b6752210c74a3
7
+ data.tar.gz: eb731aef09e46cea31da8fbdc57c591ec32e09f1c7454678635b51cdee10aedc1e991e3778b215e96da7b5797bc7322151f7864b5509f03ae6dcf8a30fdbdc41
@@ -66,29 +66,41 @@ module Effective
66
66
  end
67
67
  end
68
68
 
69
- def search_form_field_collection(association = nil, max_id = 1000)
69
+ # Load the limit records + 1. If there are all there, return as: :string
70
+ # Otherwise return an Array of the processed results ready for a select field
71
+ # Only hit the database once
72
+ def search_form_field_collection(association = nil, limit: 100)
70
73
  res = (association.nil? ? self : Effective::Resource.new(association))
71
74
 
72
- if res.max_id > max_id
73
- { as: :string }
74
- else
75
- if res.klass.unscoped.respond_to?(:datatables_scope)
76
- { collection: res.klass.datatables_scope.map { |obj| [obj.to_s, obj.id] } }
77
- elsif res.klass.unscoped.respond_to?(:datatables_filter)
78
- collection = res.klass.datatables_filter
75
+ # Return string if this isnt a relational thing
76
+ klass = res.klass
77
+ return { as: :string } unless klass.respond_to?(:unscoped)
79
78
 
80
- if collection.kind_of?(Array)
81
- { collection: collection }
82
- else
83
- { collection: collection.map { |obj| [obj.to_s, obj.id] } }
84
- end
79
+ # Default scope
80
+ scope = res.klass.unscoped
85
81
 
86
- elsif res.klass.unscoped.respond_to?(:sorted)
87
- { collection: res.klass.sorted.map { |obj| [obj.to_s, obj.id] } }
88
- else
89
- { collection: res.klass.all.map { |obj| [obj.to_s, obj.id] }.sort { |x, y| x[0] <=> y[0] } }
90
- end
82
+ scope = if scope.respond_to?(:datatables_scope)
83
+ scope.datatables_scope
84
+ elsif scope.respond_to?(:datatables_filter)
85
+ scope.datatables_filter
86
+ elsif scope.respond_to?(:sorted)
87
+ scope.sorted
88
+ else
89
+ scope
91
90
  end
91
+
92
+ scope = scope.deep if scope.respond_to?(:deep)
93
+ scope = scope.unarchived if scope.respond_to?(:unarchived)
94
+
95
+ # Now that we have the scope figured out let's pull the limit number of records into an Array
96
+ # If there are more than the limit, return as: :string
97
+ resources = scope.limit(limit).to_a
98
+ return { as: :string } unless resources.length < limit
99
+
100
+ # Otherwise there are less than the limit, so we can use a collection select
101
+ {
102
+ collection: resources.map { |obj| [obj.to_s, obj.id] }
103
+ }
92
104
  end
93
105
 
94
106
  end
@@ -22,11 +22,6 @@ module Effective
22
22
  klass.unscoped.table
23
23
  end
24
24
 
25
- def max_id
26
- return 999999 unless klass.respond_to?(:unscoped)
27
- @max_id ||= klass.unscoped.maximum(klass.primary_key).to_i
28
- end
29
-
30
25
  def sql_column(name)
31
26
  column = column(name)
32
27
  return nil unless table && column
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.16.1'.freeze
2
+ VERSION = '2.17.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.16.1
4
+ version: 2.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-09 00:00:00.000000000 Z
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails