forest_admin_datasource_customizer 1.0.0.pre.beta.86 → 1.0.0.pre.beta.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 427568d30553834fb7bc1f0728505c6ba7f75e72e74e9640672d0c2217d1e573
|
4
|
+
data.tar.gz: 1561de136ccf71999933f3eb57c2b82424671999cb43a043b898e3fb426f750b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9c582e66908f4aeabfbdd1de5d40b0ef6b79286530567d6077c8784af802dc06dd390a7835a12c21328abc94bd1ea2b6a72a47e781a69d8805b57156a64b971
|
7
|
+
data.tar.gz: 2336895e724b81fa17e1f4c2c589d88b151c636c843daea2735148864edfe9f81a88dfa59709ebbe95998322ceab690b81dbaae111162c372c135791e5b32d5c
|
@@ -33,6 +33,13 @@ module ForestAdminDatasourceCustomizer
|
|
33
33
|
push_customization { @stack.search.get_collection(@name).replace_search(definition) }
|
34
34
|
end
|
35
35
|
|
36
|
+
# Disable the search bar
|
37
|
+
# Example:
|
38
|
+
# collection.disable_search
|
39
|
+
def disable_search
|
40
|
+
push_customization { @stack.search.get_collection(@name).disable_search }
|
41
|
+
end
|
42
|
+
|
36
43
|
def add_field(name, definition)
|
37
44
|
push_customization do
|
38
45
|
collection_before_relations = @stack.early_computed.get_collection(@name)
|
data/lib/forest_admin_datasource_customizer/decorators/search/search_collection_decorator.rb
CHANGED
@@ -8,6 +8,11 @@ module ForestAdminDatasourceCustomizer
|
|
8
8
|
def initialize(child_collection, datasource)
|
9
9
|
super
|
10
10
|
@replacer = nil
|
11
|
+
@disabled_search = get_fields(false).empty?
|
12
|
+
end
|
13
|
+
|
14
|
+
def disable_search
|
15
|
+
@disabled_search = true
|
11
16
|
end
|
12
17
|
|
13
18
|
def replace_search(replacer)
|
@@ -15,7 +20,7 @@ module ForestAdminDatasourceCustomizer
|
|
15
20
|
end
|
16
21
|
|
17
22
|
def refine_schema(sub_schema)
|
18
|
-
sub_schema.merge({ searchable:
|
23
|
+
sub_schema.merge({ searchable: !@disabled_search })
|
19
24
|
end
|
20
25
|
|
21
26
|
def refine_filter(caller, filter)
|
@@ -48,7 +53,7 @@ module ForestAdminDatasourceCustomizer
|
|
48
53
|
private
|
49
54
|
|
50
55
|
def default_replacer(search, extended)
|
51
|
-
searchable_fields = get_fields(
|
56
|
+
searchable_fields = get_fields(extended)
|
52
57
|
|
53
58
|
conditions = searchable_fields.map do |field, schema|
|
54
59
|
build_condition(field, schema, search)
|
@@ -64,11 +69,11 @@ module ForestAdminDatasourceCustomizer
|
|
64
69
|
is_number = number?(search_string)
|
65
70
|
is_uuid = uuid?(search_string)
|
66
71
|
|
67
|
-
if column_type == PrimitiveType::NUMBER && is_number
|
72
|
+
if column_type == PrimitiveType::NUMBER && is_number
|
68
73
|
return Nodes::ConditionTreeLeaf.new(field, Operators::EQUAL, search_string.to_f)
|
69
74
|
end
|
70
75
|
|
71
|
-
if column_type == PrimitiveType::ENUM
|
76
|
+
if column_type == PrimitiveType::ENUM
|
72
77
|
search_value = lenient_find(enum_values, search_string)
|
73
78
|
|
74
79
|
return Nodes::ConditionTreeLeaf.new(field, Operators::EQUAL, search_value) if search_value
|
@@ -92,17 +97,17 @@ module ForestAdminDatasourceCustomizer
|
|
92
97
|
return Nodes::ConditionTreeLeaf.new(field, operator, search_string) if operator
|
93
98
|
end
|
94
99
|
|
95
|
-
if column_type == PrimitiveType::UUID && is_uuid
|
100
|
+
if column_type == PrimitiveType::UUID && is_uuid
|
96
101
|
return Nodes::ConditionTreeLeaf.new(field, Operators::EQUAL, search_string)
|
97
102
|
end
|
98
103
|
|
99
104
|
nil
|
100
105
|
end
|
101
106
|
|
102
|
-
def get_fields(
|
107
|
+
def get_fields(extended)
|
103
108
|
fields = []
|
104
|
-
|
105
|
-
fields.push([name, field]) if field.type == 'Column'
|
109
|
+
@child_collection.schema[:fields].each do |name, field|
|
110
|
+
fields.push([name, field]) if field.type == 'Column' && searchable_field?(field)
|
106
111
|
|
107
112
|
if field.type == 'PolymorphicManyToOne' && extended
|
108
113
|
ForestAdminAgent::Facades::Container.logger.log(
|
@@ -116,16 +121,30 @@ module ForestAdminDatasourceCustomizer
|
|
116
121
|
next unless extended &&
|
117
122
|
(field.type == 'ManyToOne' || field.type == 'OneToOne' || field.type == 'PolymorphicOneToOne')
|
118
123
|
|
119
|
-
related =
|
124
|
+
related = @child_collection.datasource.get_collection(field.foreign_collection)
|
120
125
|
|
121
126
|
related.schema[:fields].each do |sub_name, sub_field|
|
122
|
-
fields.push(["#{name}:#{sub_name}", sub_field]) if sub_field.type == 'Column'
|
127
|
+
fields.push(["#{name}:#{sub_name}", sub_field]) if sub_field.type == 'Column' &&
|
128
|
+
searchable_field?(sub_field)
|
123
129
|
end
|
124
130
|
end
|
125
131
|
|
126
132
|
fields
|
127
133
|
end
|
128
134
|
|
135
|
+
def searchable_field?(field)
|
136
|
+
operators = field.filter_operators
|
137
|
+
|
138
|
+
if field.column_type == PrimitiveType::STRING
|
139
|
+
return operators&.include?(Operators::EQUAL) ||
|
140
|
+
operators&.include?(Operators::CONTAINS) ||
|
141
|
+
operators&.include?(Operators::I_CONTAINS)
|
142
|
+
end
|
143
|
+
|
144
|
+
[PrimitiveType::UUID, PrimitiveType::ENUM, PrimitiveType::NUMBER].include?(field.column_type) &&
|
145
|
+
operators&.include?(Operators::EQUAL)
|
146
|
+
end
|
147
|
+
|
129
148
|
def lenient_find(haystack, needle)
|
130
149
|
haystack&.find { |v| v == needle.strip } || haystack&.find { |v| v.downcase == needle.downcase.strip }
|
131
150
|
end
|