forest_admin_datasource_customizer 1.16.6 → 1.16.7
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 +4 -4
- data/lib/forest_admin_datasource_customizer/decorators/binary/binary_collection_decorator.rb +40 -10
- data/lib/forest_admin_datasource_customizer/decorators/rename_field/rename_field_collection_decorator.rb +3 -0
- data/lib/forest_admin_datasource_customizer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 82e278319e01d29d59e70dc15f727d82ccc9d3d48bbafa6592c33ccb11573734
|
|
4
|
+
data.tar.gz: cfaa2bfb96607e8760b136e53a05846375e3114ffe18f1fe5023ca0691911be2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1973f833993be5e828ff73df8171a32b1ac1cfc4a18c55e335b88f6955f3791482adf03c1e0ebbab457f7c7c28ba5249aeb49abd14bc7422bb2744dd487acff
|
|
7
|
+
data.tar.gz: 8b8febafd935cacff3bc44f06f555d17e23f9986d98b48998b42d2947db4805df3d64e8b93cbcd63681f7e170a62eed6af3247b8fb6aceec4148a06601313d7b
|
data/lib/forest_admin_datasource_customizer/decorators/binary/binary_collection_decorator.rb
CHANGED
|
@@ -68,7 +68,7 @@ module ForestAdminDatasourceCustomizer
|
|
|
68
68
|
|
|
69
69
|
def list(caller, filter, projection)
|
|
70
70
|
records = super
|
|
71
|
-
records.map! { |record| convert_record(false, record) }
|
|
71
|
+
records.map! { |record| convert_record(false, record, projection) }
|
|
72
72
|
|
|
73
73
|
records
|
|
74
74
|
end
|
|
@@ -126,17 +126,43 @@ module ForestAdminDatasourceCustomizer
|
|
|
126
126
|
Utils::Schema.primary_key?(@child_collection, name) || Utils::Schema.foreign_key?(@child_collection, name)
|
|
127
127
|
end
|
|
128
128
|
|
|
129
|
-
def convert_record(to_backend, record)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
def convert_record(to_backend, record, projection = nil)
|
|
130
|
+
return record unless record
|
|
131
|
+
|
|
132
|
+
result = {}
|
|
133
|
+
record.each do |path, value|
|
|
134
|
+
# Skip fields that don't exist in the schema (e.g., virtual attributes)
|
|
135
|
+
prefix = path.split(':').first
|
|
136
|
+
next unless @child_collection.schema[:fields][prefix]
|
|
137
|
+
|
|
138
|
+
if projection.nil?
|
|
139
|
+
result[path] = convert_value(to_backend, path, value, nil)
|
|
140
|
+
else
|
|
141
|
+
sub_projection = extract_sub_projection(projection, path)
|
|
142
|
+
result[path] = if sub_projection
|
|
143
|
+
convert_value(to_backend, path, value, sub_projection)
|
|
144
|
+
else
|
|
145
|
+
value
|
|
146
|
+
end
|
|
133
147
|
end
|
|
134
148
|
end
|
|
135
149
|
|
|
136
|
-
|
|
150
|
+
result
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def extract_sub_projection(projection, path)
|
|
154
|
+
# Check if the field is directly in the projection
|
|
155
|
+
return Projection.new([path]) if projection.include?(path)
|
|
156
|
+
|
|
157
|
+
# Check if any field in the projection starts with "path:"
|
|
158
|
+
sub_fields = projection.select { |p| p.start_with?("#{path}:") }
|
|
159
|
+
return nil if sub_fields.empty?
|
|
160
|
+
|
|
161
|
+
# Extract the sub-projection by removing the prefix
|
|
162
|
+
Projection.new(sub_fields.map { |p| p[(path.length + 1)..] })
|
|
137
163
|
end
|
|
138
164
|
|
|
139
|
-
def convert_value(to_backend, path, value)
|
|
165
|
+
def convert_value(to_backend, path, value, projection = nil)
|
|
140
166
|
prefix, suffix = path.split(':')
|
|
141
167
|
field = @child_collection.schema[:fields][prefix]
|
|
142
168
|
|
|
@@ -151,9 +177,13 @@ module ForestAdminDatasourceCustomizer
|
|
|
151
177
|
if field.type != 'Column'
|
|
152
178
|
foreign_collection = @datasource.get_collection(field.foreign_collection)
|
|
153
179
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
180
|
+
result = if suffix
|
|
181
|
+
foreign_collection.convert_value(to_backend, suffix, value, projection)
|
|
182
|
+
else
|
|
183
|
+
foreign_collection.convert_record(to_backend, value, projection)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
return result
|
|
157
187
|
end
|
|
158
188
|
|
|
159
189
|
binary_mode = should_use_hex(path)
|
|
@@ -201,6 +201,9 @@ module ForestAdminDatasourceCustomizer
|
|
|
201
201
|
field = from_child_collection[child_field] || child_field
|
|
202
202
|
field_schema = schema[:fields][field]
|
|
203
203
|
|
|
204
|
+
# Skip fields that don't exist in the schema (e.g., virtual attributes)
|
|
205
|
+
next unless field_schema
|
|
206
|
+
|
|
204
207
|
# Perform the mapping, recurse for relation
|
|
205
208
|
if field_schema.type == 'Column' || value.nil? || field_schema.type == 'PolymorphicManyToOne' ||
|
|
206
209
|
field_schema.type == 'PolymorphicOneToOne'
|