forest_admin_agent 1.0.0.pre.beta.52 → 1.0.0.pre.beta.54
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: 6d00ce0b7ec12194e89b3356eeafea21b554920c02eb6e44add1446950cabe9c
|
|
4
|
+
data.tar.gz: 570008a865ef664bc286370771808897b8b0d04c2326c1b13e68e276d57815f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9b1fd6024a979ef4cbcc13812a2543fb44586b59c3af1acb5222bdff6da121d3795c910e9699ac64a5df57e94a1ba213eb2aa05b89612cbf6e191cf46ea29285
|
|
7
|
+
data.tar.gz: 882468f6dbbc8f8f742d9dce4b94925f507e2f54dee873b1186bae14391c53d2a47707a476fb41259f9d7179b81d346feb227789fb473723ffc6c6f9a4ff4eee
|
|
@@ -60,7 +60,10 @@ module ForestAdminAgent
|
|
|
60
60
|
objects.each do |obj|
|
|
61
61
|
relation = ForestAdminAgent::Facades::Container.datasource.get_collection(options[:class_name]).schema[:fields][attribute_name]
|
|
62
62
|
relation_class_name = ForestAdminAgent::Facades::Container.datasource.get_collection(relation.foreign_collection).name
|
|
63
|
-
|
|
63
|
+
option_relation = options.clone
|
|
64
|
+
option_relation[:class_name] = relation_class_name
|
|
65
|
+
obj_serializer = JSONAPI::Serializer.find_serializer(obj, option_relation)
|
|
66
|
+
|
|
64
67
|
# Use keys of ['posts', '1'] for the results to enforce uniqueness.
|
|
65
68
|
# Spec: A compound document MUST NOT include more than one resource object for each
|
|
66
69
|
# type and id pair.
|
|
@@ -200,7 +203,6 @@ module ForestAdminAgent
|
|
|
200
203
|
# of the internal special merging logic.
|
|
201
204
|
find_recursive_relationships(obj, inclusion_tree, relationship_data, passthrough_options)
|
|
202
205
|
end
|
|
203
|
-
|
|
204
206
|
result['included'] = relationship_data.map do |_, data|
|
|
205
207
|
included_passthrough_options = {}
|
|
206
208
|
included_passthrough_options[:base_url] = passthrough_options[:base_url]
|
|
@@ -53,8 +53,11 @@ module ForestAdminAgent
|
|
|
53
53
|
def self.convert_validation_list(column)
|
|
54
54
|
return [] if column.validations.empty?
|
|
55
55
|
|
|
56
|
-
rules = column.validations.
|
|
57
|
-
remove_duplicates_in_place(rules)
|
|
56
|
+
rules = column.validations.map { |rule| simplify_rule(column.column_type, rule) }
|
|
57
|
+
remove_duplicates_in_place(rules)
|
|
58
|
+
|
|
59
|
+
rules.filter { |rule| rule.is_a?(Hash) && rule.key?(:operator) }
|
|
60
|
+
.map { |rule| SUPPORTED[rule[:operator]].call(rule) }
|
|
58
61
|
end
|
|
59
62
|
|
|
60
63
|
def self.simplify_rule(column_type, rule)
|
|
@@ -74,11 +77,16 @@ module ForestAdminAgent
|
|
|
74
77
|
timezone = 'Europe/Paris' # we're sending the schema => use random tz
|
|
75
78
|
tree = ConditionTreeEquivalent.get_equivalent_tree(leaf, operators, column_type, timezone)
|
|
76
79
|
|
|
77
|
-
if tree.is_a? Nodes::ConditionTreeLeaf
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
conditions = if tree.is_a? Nodes::ConditionTreeLeaf
|
|
81
|
+
[tree]
|
|
82
|
+
else
|
|
83
|
+
tree.conditions
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
return conditions.filter { |c| c.is_a?(Nodes::ConditionTreeLeaf) }
|
|
87
|
+
.filter { |c| c.operator != Operators::EQUAL && c.operator != Operators::NOT_EQUAL }
|
|
88
|
+
.map { |c| simplify_rule(column_type, operator: c.operator, value: c.value) }
|
|
89
|
+
.first
|
|
82
90
|
rescue StandardError
|
|
83
91
|
# Just ignore errors, they mean that the operator is not supported by the frontend
|
|
84
92
|
# and that we don't have an automatic conversion for it.
|
|
@@ -91,36 +99,44 @@ module ForestAdminAgent
|
|
|
91
99
|
[]
|
|
92
100
|
end
|
|
93
101
|
|
|
94
|
-
# The frontend crashes when it receives multiple rules of the same type.
|
|
95
|
-
# This method merges the rules which can be merged and drops the others.
|
|
96
102
|
def self.remove_duplicates_in_place(rules)
|
|
97
103
|
used = {}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
|
|
105
|
+
i = 0
|
|
106
|
+
while i < rules.length
|
|
107
|
+
rule = rules[i]
|
|
108
|
+
if rule.is_a?(Hash) && rule.key?(:operator)
|
|
109
|
+
if used.key?(rule[:operator])
|
|
110
|
+
existing_rule = rules[used[rule[:operator]]]
|
|
111
|
+
new_rule = rules.delete_at(i)
|
|
112
|
+
|
|
113
|
+
merge_into(existing_rule, new_rule)
|
|
114
|
+
# Adjust the index to account for the removed element
|
|
115
|
+
i -= 1
|
|
116
|
+
else
|
|
117
|
+
used[rule[:operator]] = i
|
|
118
|
+
end
|
|
106
119
|
end
|
|
120
|
+
i += 1
|
|
107
121
|
end
|
|
108
|
-
|
|
109
|
-
rules
|
|
110
122
|
end
|
|
111
123
|
|
|
112
|
-
|
|
113
|
-
|
|
124
|
+
# rubocop:disable Style/EmptyElse
|
|
125
|
+
def self.merge_into(rule, new_rule)
|
|
126
|
+
case rule[:operator]
|
|
127
|
+
when Operators::GREATER_THAN, Operators::AFTER, Operators::LONGER_THAN
|
|
114
128
|
rule[:value] = [rule[:value], new_rule[:value]].max
|
|
115
|
-
|
|
129
|
+
when Operators::LESS_THAN, Operators::BEFORE, Operators::SHORTER_THAN
|
|
116
130
|
rule[:value] = [rule[:value], new_rule[:value]].min
|
|
117
|
-
|
|
118
|
-
|
|
131
|
+
when Operators::MATCH
|
|
132
|
+
regex = rule[:value].gsub(/\W/, '')
|
|
133
|
+
new_regex = new_rule[:value].gsub(/\W/, '')
|
|
134
|
+
rule[:value] = "/^(?=#{regex})(?=#{new_regex}).*$/i"
|
|
135
|
+
else
|
|
136
|
+
# Ignore the rules that we can't deduplicate (we could log a warning here).
|
|
119
137
|
end
|
|
120
|
-
# else Ignore the rules that we can't deduplicate (we could log a warning here).
|
|
121
|
-
|
|
122
|
-
rule
|
|
123
138
|
end
|
|
139
|
+
# rubocop:enable Style/EmptyElse
|
|
124
140
|
end
|
|
125
141
|
end
|
|
126
142
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_admin_agent
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.0.pre.beta.
|
|
4
|
+
version: 1.0.0.pre.beta.54
|
|
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: 2024-06-
|
|
12
|
+
date: 2024-06-10 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|