forest_admin_datasource_customizer 1.12.8 → 1.12.9
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/composite_datasource.rb +77 -0
- data/lib/forest_admin_datasource_customizer/datasource_customizer.rb +3 -31
- data/lib/forest_admin_datasource_customizer/decorators/rename_collection/rename_collection_datasource_decorator.rb +3 -3
- data/lib/forest_admin_datasource_customizer/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0b602ad730759006a6897f4bffe4387c700dfb9e63da39f222e4ed5f14315456
|
|
4
|
+
data.tar.gz: 05501e5c27f83663f192c190d1e540584125e3a22a0aa97dd2125c185e3f7263
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b4d0efa7d03ee6a5362f50bcbb38990dca98835a31d1c05514be262c6f02b29a63dd7c3fe146a1cfc31dac13b1b1de5b32bb4a9c07fb2de1d0abc9d4271440d
|
|
7
|
+
data.tar.gz: d32642ef7762138472deddf1d6011f27470b76b4c53891a7670c19b20eb2e7e920bedcf087c002f47c059ed4e801e09a2f778a76f45f2f574d7faf371a222a75
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
module ForestAdminDatasourceCustomizer
|
|
2
|
+
class CompositeDatasource
|
|
3
|
+
def initialize
|
|
4
|
+
@datasources = []
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def live_query_connections
|
|
8
|
+
@datasources.each_with_object({}) do |ds, acc|
|
|
9
|
+
acc.merge!(ds.live_query_connections || {})
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def schema
|
|
14
|
+
{ charts: @datasources.flat_map { |ds| ds.schema[:charts] } }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def collections
|
|
18
|
+
@datasources.reduce({}) { |acc, ds| acc.merge(ds.collections) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get_collection(name)
|
|
22
|
+
@datasources.each do |ds|
|
|
23
|
+
return ds.get_collection(name)
|
|
24
|
+
rescue StandardError
|
|
25
|
+
# ignore and continue
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
raise ForestAdminDatasourceToolkit::Exceptions::ForestException,
|
|
29
|
+
"Collection '#{name}' not found. List of available collections: #{collections.keys.sort.join(", ")}"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def render_chart(caller_obj, name)
|
|
33
|
+
@datasources.each do |ds|
|
|
34
|
+
return ds.render_chart(caller_obj, name) if ds.schema[:charts].include?(name)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
raise ForestAdminDatasourceToolkit::Exceptions::ForestException,
|
|
38
|
+
"Chart '#{name}' is not defined in the dataSource."
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def execute_native_query(connection_name, query, context_variables = {})
|
|
42
|
+
unless live_query_connections.key?(connection_name)
|
|
43
|
+
raise ForestAdminDatasourceToolkit::Exceptions::ForestException,
|
|
44
|
+
"Native query connection '#{name}' is unknown."
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
ds = @datasources.find do |d|
|
|
48
|
+
(d.live_query_connections || {}).key?(connection_name)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
ds.execute_native_query(connection_name, query, context_variables)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def add_data_source(datasource)
|
|
55
|
+
existing_names = collections.map { |c| c.respond_to?(:name) ? c.name : c.to_s }
|
|
56
|
+
datasource.collections.each do |c|
|
|
57
|
+
new_name = c.respond_to?(:name) ? c.name : c.to_s
|
|
58
|
+
raise ArgumentError, "Collection '#{new_name}' already exists" if existing_names.include?(new_name)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
existing_charts = schema[:charts]
|
|
62
|
+
(datasource.schema[:charts] || []).each do |chart|
|
|
63
|
+
raise ArgumentError, "Chart '#{chart}' is already defined in datasource." if existing_charts.include?(chart)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
existing_conns = live_query_connections
|
|
67
|
+
(datasource.live_query_connections || {}).each_key do |conn_name|
|
|
68
|
+
if existing_conns.key?(conn_name)
|
|
69
|
+
raise ArgumentError, "Native Query connection '#{conn_name}' is already defined"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
@datasources << datasource
|
|
74
|
+
nil
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -3,9 +3,8 @@ module ForestAdminDatasourceCustomizer
|
|
|
3
3
|
attr_reader :stack, :datasources
|
|
4
4
|
|
|
5
5
|
def initialize(_db_config = {})
|
|
6
|
-
@composite_datasource =
|
|
6
|
+
@composite_datasource = ForestAdminDatasourceCustomizer::CompositeDatasource.new
|
|
7
7
|
@stack = Decorators::DecoratorsStack.new(@composite_datasource)
|
|
8
|
-
@datasources = []
|
|
9
8
|
end
|
|
10
9
|
|
|
11
10
|
def schema
|
|
@@ -42,17 +41,9 @@ module ForestAdminDatasourceCustomizer
|
|
|
42
41
|
datasource = rename_collection_decorator
|
|
43
42
|
end
|
|
44
43
|
|
|
45
|
-
datasource
|
|
46
|
-
@composite_datasource.add_collection(collection)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
datasource.schema[:charts].each do |chart|
|
|
50
|
-
@composite_datasource.add_chart(chart)
|
|
51
|
-
end
|
|
44
|
+
@composite_datasource.add_data_source(datasource)
|
|
52
45
|
})
|
|
53
46
|
|
|
54
|
-
@datasources << datasource
|
|
55
|
-
|
|
56
47
|
self
|
|
57
48
|
end
|
|
58
49
|
|
|
@@ -79,30 +70,11 @@ module ForestAdminDatasourceCustomizer
|
|
|
79
70
|
self
|
|
80
71
|
end
|
|
81
72
|
|
|
82
|
-
def get_root_datasource_by_connection(name)
|
|
83
|
-
root_datasource = @datasources.find do |datasource|
|
|
84
|
-
datasource.live_query_connections.any? { |connection_name, _connection| connection_name == name }
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
unless root_datasource
|
|
88
|
-
raise ForestAdminAgent::Http::Exceptions::NotFoundError,
|
|
89
|
-
"Native query connection '#{name}' is unknown."
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
root_datasource
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def render_chart(caller, name)
|
|
96
|
-
return @composite_datasource.render_chart(caller, name) if @composite_datasource.schema[:charts].any?(name)
|
|
97
|
-
|
|
98
|
-
raise ForestAdminAgent::Http::Exceptions::NotFoundError, "Chart '#{name}' is not defined in the dataSource."
|
|
99
|
-
end
|
|
100
|
-
|
|
101
73
|
def reload!(logger: nil)
|
|
102
74
|
old_composite = @composite_datasource
|
|
103
75
|
|
|
104
76
|
begin
|
|
105
|
-
new_composite =
|
|
77
|
+
new_composite = ForestAdminDatasourceCustomizer::CompositeDatasource.new
|
|
106
78
|
@stack.reload!(new_composite, logger)
|
|
107
79
|
@composite_datasource = new_composite
|
|
108
80
|
rescue StandardError => e
|
|
@@ -14,7 +14,7 @@ module ForestAdminDatasourceCustomizer
|
|
|
14
14
|
|
|
15
15
|
def collections
|
|
16
16
|
@child_datasource.collections.to_h do |name, _collection|
|
|
17
|
-
[name, method(:get_collection).super_method.call(name)]
|
|
17
|
+
[get_collection_name(name), method(:get_collection).super_method.call(name)]
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -48,7 +48,7 @@ module ForestAdminDatasourceCustomizer
|
|
|
48
48
|
|
|
49
49
|
def rename_collection(current_name, new_name)
|
|
50
50
|
# Check collection exists
|
|
51
|
-
get_collection(current_name)
|
|
51
|
+
collection = get_collection(current_name)
|
|
52
52
|
|
|
53
53
|
return unless current_name != new_name
|
|
54
54
|
|
|
@@ -65,7 +65,7 @@ module ForestAdminDatasourceCustomizer
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
polymorphic_relations = %w[PolymorphicOneToOne PolymorphicOneToMany]
|
|
68
|
-
|
|
68
|
+
collection.schema[:fields].each do |field_name, field_schema|
|
|
69
69
|
next unless polymorphic_relations.include?(field_schema.type)
|
|
70
70
|
|
|
71
71
|
reverse_relation_name = Utils::Collection.get_inverse_relation(get_collection(current_name), field_name)
|
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.12.
|
|
4
|
+
version: 1.12.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthieu
|
|
@@ -144,6 +144,7 @@ files:
|
|
|
144
144
|
- forest_admin_datasource_customizer.gemspec
|
|
145
145
|
- lib/forest_admin_datasource_customizer.rb
|
|
146
146
|
- lib/forest_admin_datasource_customizer/collection_customizer.rb
|
|
147
|
+
- lib/forest_admin_datasource_customizer/composite_datasource.rb
|
|
147
148
|
- lib/forest_admin_datasource_customizer/context/agent_customization_context.rb
|
|
148
149
|
- lib/forest_admin_datasource_customizer/context/collection_customization_context.rb
|
|
149
150
|
- lib/forest_admin_datasource_customizer/context/relaxed_wrappers/relaxed_collection.rb
|