forest_admin_agent 1.0.0.pre.beta.25 → 1.0.0.pre.beta.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/forest_admin_agent/routes/resources/list.rb +25 -3
- data/lib/forest_admin_agent/utils/condition_tree_parser.rb +2 -0
- data/lib/forest_admin_agent/utils/id.rb +13 -0
- data/lib/forest_admin_agent/utils/query_string_parser.rb +17 -0
- data/lib/forest_admin_agent/utils/schema/frontend_filterable.rb +1 -1
- data/lib/forest_admin_agent/utils/schema/schema_emitter.rb +1 -1
- data/lib/forest_admin_agent/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: d5a1222f5af1bf778087d4b388f224d8802cb52f4aa59a203d608145f11a0920
|
4
|
+
data.tar.gz: a63be1a15f8778eb1a7766ebcc099ef66a39f8804059bb6b1fe9783c45cec718
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b395ae4c2e8a0d5c1a5f974170dc863af79f969d0118b703b97dde95e92b119f007bdc5373bac86fd271029f69493baca613f0608e031cfb7b1cf0284514bfc0
|
7
|
+
data.tar.gz: 90a0a84788e6e13aa7a324463aee664c44f28952e22625335bbf95f7534ccccced3f8e397834658e1bb1154e6aa8756e39408fa3f5ad4c4e84885d5f360a6513
|
@@ -15,7 +15,6 @@ module ForestAdminAgent
|
|
15
15
|
def handle_request(args = {})
|
16
16
|
build(args)
|
17
17
|
@permissions.can?(:browse, @collection)
|
18
|
-
|
19
18
|
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
|
20
19
|
condition_tree: ConditionTreeFactory.intersect([
|
21
20
|
@permissions.get_scope(@collection),
|
@@ -23,8 +22,11 @@ module ForestAdminAgent
|
|
23
22
|
@collection, args
|
24
23
|
)
|
25
24
|
]),
|
26
|
-
page: ForestAdminAgent::Utils::QueryStringParser.parse_pagination(args)
|
25
|
+
page: ForestAdminAgent::Utils::QueryStringParser.parse_pagination(args),
|
26
|
+
search: ForestAdminAgent::Utils::QueryStringParser.parse_search(@collection, args),
|
27
|
+
search_extended: ForestAdminAgent::Utils::QueryStringParser.parse_search_extended(args)
|
27
28
|
)
|
29
|
+
|
28
30
|
projection = ForestAdminAgent::Utils::QueryStringParser.parse_projection_with_pks(@collection, args)
|
29
31
|
records = @collection.list(@caller, filter, projection)
|
30
32
|
|
@@ -34,10 +36,30 @@ module ForestAdminAgent
|
|
34
36
|
records,
|
35
37
|
is_collection: true,
|
36
38
|
serializer: Serializer::ForestSerializer,
|
37
|
-
include: projection.relations.keys
|
39
|
+
include: projection.relations.keys,
|
40
|
+
meta: handle_search_decorator(args[:params]['search'], records)
|
38
41
|
)
|
39
42
|
}
|
40
43
|
end
|
44
|
+
|
45
|
+
def handle_search_decorator(search_value, records)
|
46
|
+
decorator = { decorators: [] }
|
47
|
+
unless search_value.nil?
|
48
|
+
records.each_with_index do |entry, index|
|
49
|
+
decorator[:decorators][index] = { id: Utils::Id.pack_id(@collection, entry), search: [] }
|
50
|
+
# attributes method is defined on ActiveRecord::Base model
|
51
|
+
attributes = entry.respond_to?(:attributes) ? entry.attributes : entry
|
52
|
+
|
53
|
+
attributes.each do |field_key, field_value|
|
54
|
+
if !field_value.is_a?(Array) && field_value.to_s.downcase.include?(search_value.downcase)
|
55
|
+
decorator[:decorators][index][:search] << field_key
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
decorator
|
62
|
+
end
|
41
63
|
end
|
42
64
|
end
|
43
65
|
end
|
@@ -40,6 +40,8 @@ module ForestAdminAgent
|
|
40
40
|
return values.map { |item| !%w[false 0 no].include?(item) } if schema.column_type == 'Boolean'
|
41
41
|
|
42
42
|
return values.map(&:to_f).select { |item| item.is_a? Numeric } if schema.column_type == 'Number'
|
43
|
+
|
44
|
+
return values
|
43
45
|
end
|
44
46
|
|
45
47
|
leaf['value']
|
@@ -3,6 +3,19 @@ module ForestAdminAgent
|
|
3
3
|
class Id
|
4
4
|
include ForestAdminDatasourceToolkit::Utils
|
5
5
|
include ForestAdminDatasourceToolkit
|
6
|
+
|
7
|
+
def self.pack_ids(schema, records)
|
8
|
+
records.map { |packed_id| pack_id(schema, packed_id) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.pack_id(schema, record)
|
12
|
+
pk_names = ForestAdminDatasourceToolkit::Utils::Schema.primary_keys(schema)
|
13
|
+
|
14
|
+
raise Exceptions::ForestException, 'This collection has no primary key' if pk_names.empty?
|
15
|
+
|
16
|
+
pk_names.map { |pk| record[pk].to_s }.join('|')
|
17
|
+
end
|
18
|
+
|
6
19
|
def self.unpack_id(collection, packed_id, with_key: false)
|
7
20
|
primary_keys = ForestAdminDatasourceToolkit::Utils::Schema.primary_keys(collection)
|
8
21
|
primary_key_values = packed_id.to_s.split('|')
|
@@ -85,6 +85,23 @@ module ForestAdminAgent
|
|
85
85
|
|
86
86
|
Page.new(offset: offset, limit: items_per_pages.to_i)
|
87
87
|
end
|
88
|
+
|
89
|
+
def self.parse_search(collection, args)
|
90
|
+
search = args.dig(:params, :data, :attributes, :all_records_subset_query, :search) || args.dig(:params, :search)
|
91
|
+
|
92
|
+
raise ForestException, 'Collection is not searchable' if search && !collection.is_searchable?
|
93
|
+
|
94
|
+
search
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.parse_search_extended(args)
|
98
|
+
extended = args.dig(:params, :data, :attributes, :all_records_subset_query,
|
99
|
+
:searchExtended) || args.dig(:params, :searchExtended)
|
100
|
+
|
101
|
+
return false if extended.nil?
|
102
|
+
|
103
|
+
extended != '0'
|
104
|
+
end
|
88
105
|
end
|
89
106
|
end
|
90
107
|
end
|
@@ -63,7 +63,7 @@ module ForestAdminAgent
|
|
63
63
|
def self.get_required_operators(type)
|
64
64
|
return OPERATOR_BY_TYPE[type] if type.is_a?(String) && OPERATOR_BY_TYPE.key?(type)
|
65
65
|
|
66
|
-
return [
|
66
|
+
return [Operators::INCLUDES_ALL] if type.is_a? Array
|
67
67
|
|
68
68
|
[]
|
69
69
|
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.27
|
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: 2024-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|