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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55ffa99bff7ce09a36f31a7a12f9e0fb3eff53b07110a86724a1b7dad14a0438
|
4
|
+
data.tar.gz: 356be85dc5dd7cbaeb0bfdf562b22442ef7102277e4b76bd479e5a0e70823062
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 676d8e7f03e37d0781c909570b543a8089d9eb5a8e54f215f05bedba1977b9ad49b99e009c2c5cf20a330294c2daf0079c455df957f0198d897b6752210c74a3
|
7
|
+
data.tar.gz: eb731aef09e46cea31da8fbdc57c591ec32e09f1c7454678635b51cdee10aedc1e991e3778b215e96da7b5797bc7322151f7864b5509f03ae6dcf8a30fdbdc41
|
@@ -66,29 +66,41 @@ module Effective
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
|
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
|
73
|
-
|
74
|
-
|
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
|
-
|
81
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2023-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|