effective_resources 2.16.1 → 2.17.1

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: 66b9fac622ba1011fb81e24ca565d714b78028bd464b14b8e199558eb2e795f1
4
+ data.tar.gz: 72736d311ac7c200758628c5cf4b31b840b2f7e16d482f26771b79b038bb46c1
5
5
  SHA512:
6
- metadata.gz: 2db488f338acda47184ea4bf2a41d1420f338738ad97f98635e66353d00d9a5edcf61aaace5351c38becec2ee80f4884fcd7a522a3f661baa4f9b2671f0a23bb
7
- data.tar.gz: cbaea70caa43ceeb87b17fa1a31162c5d4b5369e3e5435073fb73b05c5c0dcb564f12948fb88dc62b010c1485e06880999c320c9c8a31bc01ad905df6a9e5668
6
+ metadata.gz: 6db9023e73e61521f5265407d753831fc8cc62e0b4d5481692242ccbe4643cb59dfe7b077db2de7ee66b3be4bfdf13492816804c9b76a19ac186266f89e95080
7
+ data.tar.gz: 6027c08af646b16c6e218c6842c35448aca20420919512ca81b3af573fdbbbe4d9e359a193ba80b37548449a972dccc94064edc305c512f5683b38552de25e31
@@ -66,29 +66,42 @@ 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?(:shallow)
87
+ scope.shallow
88
+ elsif scope.respond_to?(:sorted)
89
+ scope.sorted
90
+ else
91
+ scope
91
92
  end
93
+
94
+ scope = scope.unarchived if scope.respond_to?(:unarchived)
95
+
96
+ # Now that we have the scope figured out let's pull the limit number of records into an Array
97
+ # If there are more than the limit, return as: :string
98
+ resources = scope.limit(limit).to_a
99
+ return { as: :string } unless resources.length < limit
100
+
101
+ # Otherwise there are less than the limit, so we can use a collection select
102
+ {
103
+ collection: resources.map { |obj| [obj.to_s, obj.id] }
104
+ }
92
105
  end
93
106
 
94
107
  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.1'.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.1
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