forest_admin_datasource_customizer 1.0.0.pre.beta.83 → 1.0.0.pre.beta.86
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/datasource_customizer.rb +17 -1
- data/lib/forest_admin_datasource_customizer/decorators/segment/segment_collection_decorator.rb +22 -19
- data/lib/forest_admin_datasource_customizer/decorators/sort/sort_collection_decorator.rb +6 -6
- data/lib/forest_admin_datasource_customizer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98b615fe1c829b8a99d8c2dac3bb852c09a669ae328ff353746c55f6f61c152f
|
4
|
+
data.tar.gz: ea82667001dfcd0e5e37b39feebce3a7a368188eaf55235312dd5a48bc92e6a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be6a34cd0435042dab88b00b583ff2ef064e01562391fd10f4bbbf5799b4fe478593fbb9efdc0e248879fbbe87e34c7e21ad2ed7bfca2becc4be28e8de3647fe
|
7
|
+
data.tar.gz: 9e16a66fb986e7be63cf7be72969f2e79ac565cdc752e0123585a19ede2401a0346dbd523d3cbbf630597cf6feb4a401a677f563592797e6e016869b5c5e5a4b
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module ForestAdminDatasourceCustomizer
|
2
2
|
class DatasourceCustomizer
|
3
|
-
attr_reader :stack
|
3
|
+
attr_reader :stack, :datasources
|
4
4
|
|
5
5
|
def initialize(_db_config = {})
|
6
6
|
@composite_datasource = ForestAdminDatasourceToolkit::Datasource.new
|
7
7
|
@stack = Decorators::DecoratorsStack.new(@composite_datasource)
|
8
|
+
@datasources = []
|
8
9
|
end
|
9
10
|
|
10
11
|
def schema
|
@@ -46,6 +47,8 @@ module ForestAdminDatasourceCustomizer
|
|
46
47
|
end
|
47
48
|
})
|
48
49
|
|
50
|
+
@datasources << datasource
|
51
|
+
|
49
52
|
self
|
50
53
|
end
|
51
54
|
|
@@ -72,6 +75,19 @@ module ForestAdminDatasourceCustomizer
|
|
72
75
|
self
|
73
76
|
end
|
74
77
|
|
78
|
+
def get_root_datasource_by_connection(name)
|
79
|
+
root_datasource = @datasources.find do |datasource|
|
80
|
+
datasource.live_query_connections.any? { |connection_name, _connection| connection_name == name }
|
81
|
+
end
|
82
|
+
|
83
|
+
unless root_datasource
|
84
|
+
raise ForestAdminAgent::Http::Exceptions::NotFoundError,
|
85
|
+
"Native query connection '#{name}' is unknown."
|
86
|
+
end
|
87
|
+
|
88
|
+
root_datasource
|
89
|
+
end
|
90
|
+
|
75
91
|
private
|
76
92
|
|
77
93
|
def push_customization(&customization)
|
data/lib/forest_admin_datasource_customizer/decorators/segment/segment_collection_decorator.rb
CHANGED
@@ -20,39 +20,42 @@ module ForestAdminDatasourceCustomizer
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def refine_schema(sub_schema)
|
23
|
-
sub_schema[:segments] = sub_schema[:segments]
|
23
|
+
sub_schema[:segments] = sub_schema[:segments] | @segments.keys
|
24
24
|
|
25
25
|
sub_schema
|
26
26
|
end
|
27
27
|
|
28
|
-
def refine_filter(
|
28
|
+
def refine_filter(_caller, filter = nil)
|
29
29
|
return nil unless filter
|
30
30
|
|
31
31
|
condition_tree = filter.condition_tree
|
32
32
|
segment = filter.segment
|
33
|
-
|
34
33
|
if segment && @segments.key?(segment)
|
35
|
-
|
34
|
+
condition_tree = compute_segment(segment, filter)
|
35
|
+
segment = nil
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
else
|
40
|
-
definition
|
41
|
-
end
|
38
|
+
filter.override(condition_tree: condition_tree, segment: segment)
|
39
|
+
end
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
else
|
46
|
-
ConditionTreeFactory.from_plain_object(result)
|
47
|
-
end
|
41
|
+
def compute_segment(segment_name, filter)
|
42
|
+
definition = @segments[segment_name]
|
48
43
|
|
49
|
-
|
44
|
+
result = if definition.respond_to? :call
|
45
|
+
definition.call(Context::CollectionCustomizationContext.new(self, caller))
|
46
|
+
else
|
47
|
+
definition
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
condition_tree_segment = if result.is_a? Nodes::ConditionTree
|
51
|
+
result
|
52
|
+
else
|
53
|
+
ConditionTreeFactory.from_plain_object(result)
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
+
ConditionTreeValidator.validate(condition_tree_segment, self)
|
57
|
+
|
58
|
+
ConditionTreeFactory.intersect([condition_tree_segment, filter.condition_tree])
|
56
59
|
end
|
57
60
|
end
|
58
61
|
end
|
@@ -42,10 +42,10 @@ module ForestAdminDatasourceCustomizer
|
|
42
42
|
reference_records = child_filter.page.apply(reference_records) if child_filter.page
|
43
43
|
|
44
44
|
# We now have the information we need to sort by the field
|
45
|
-
new_filter = Filter.new(condition_tree: ConditionTree::ConditionTreeFactory.match_records(
|
45
|
+
new_filter = Filter.new(condition_tree: ConditionTree::ConditionTreeFactory.match_records(self,
|
46
46
|
reference_records))
|
47
47
|
|
48
|
-
records = child_collection.list(caller, new_filter, projection.with_pks(self))
|
48
|
+
records = child_collection.list(caller, new_filter, projection.clone.with_pks(self))
|
49
49
|
records = sort_records(reference_records, records)
|
50
50
|
|
51
51
|
projection.apply(records)
|
@@ -89,7 +89,7 @@ module ForestAdminDatasourceCustomizer
|
|
89
89
|
|
90
90
|
def emulated?(path)
|
91
91
|
index = path.index(':')
|
92
|
-
return @sorts
|
92
|
+
return @sorts.key?(path) if index.nil?
|
93
93
|
|
94
94
|
foreign_collection = schema[:fields][path[0, index]].foreign_collection
|
95
95
|
association = datasource.get_collection(foreign_collection)
|
@@ -101,7 +101,7 @@ module ForestAdminDatasourceCustomizer
|
|
101
101
|
|
102
102
|
def replace_or_emulate_field_sorting(name, equivalent_sort)
|
103
103
|
FieldValidator.validate(self, name)
|
104
|
-
@sorts[name] =
|
104
|
+
@sorts[name.to_s] =
|
105
105
|
equivalent_sort ? ForestAdminDatasourceToolkit::Components::Query::Sort.new(equivalent_sort) : nil
|
106
106
|
mark_schema_as_dirty
|
107
107
|
end
|
@@ -111,11 +111,11 @@ module ForestAdminDatasourceCustomizer
|
|
111
111
|
sorted = Array.new(records.length)
|
112
112
|
|
113
113
|
reference_records.each_with_index do |record, index|
|
114
|
-
position_by_id[Record.primary_keys(
|
114
|
+
position_by_id[Record.primary_keys(self, record).join('|')] = index
|
115
115
|
end
|
116
116
|
|
117
117
|
records.each do |record|
|
118
|
-
id = Record.primary_keys(
|
118
|
+
id = Record.primary_keys(self, record).join('|')
|
119
119
|
sorted[position_by_id[id]] = record
|
120
120
|
end
|
121
121
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_admin_datasource_customizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.86
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|