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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99124b74e8108992635d7c4932b1e1a3e670cdef851df6af0174b1b13434845e
4
- data.tar.gz: a4fb88fed216fd288ff7a2d89e13216ed21f576482f450b08300dc22ed805579
3
+ metadata.gz: d5a1222f5af1bf778087d4b388f224d8802cb52f4aa59a203d608145f11a0920
4
+ data.tar.gz: a63be1a15f8778eb1a7766ebcc099ef66a39f8804059bb6b1fe9783c45cec718
5
5
  SHA512:
6
- metadata.gz: ef8333542d36d50484ede07d6bee4923e777eba881b6c49678e803387c271b8b4487ebf9b9f37697f8e23381c07e6a05af1a4eee07b8ead80277904fda28baf4
7
- data.tar.gz: c32a53f151d3135e98349148e214f5ef90f9134a5cdf74fe3ac6bb072c241d7aef7a99a9cd3d8f8295d8acfa517bcae54567bf8b389ce533dfc1b3fe4c295f1f
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 ['Includes_All'] if type.is_a? Array
66
+ return [Operators::INCLUDES_ALL] if type.is_a? Array
67
67
 
68
68
  []
69
69
  end
@@ -7,7 +7,7 @@ module ForestAdminAgent
7
7
  class SchemaEmitter
8
8
  LIANA_NAME = "forest-rails"
9
9
 
10
- LIANA_VERSION = "1.0.0-beta.25"
10
+ LIANA_VERSION = "1.0.0-beta.27"
11
11
 
12
12
  def self.get_serialized_schema(datasource)
13
13
  schema_path = Facades::Container.cache(:schema_path)
@@ -1,3 +1,3 @@
1
1
  module ForestAdminAgent
2
- VERSION = "1.0.0-beta.25"
2
+ VERSION = "1.0.0-beta.27"
3
3
  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.25
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: 2023-12-20 00:00:00.000000000 Z
12
+ date: 2024-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport