forest_admin_agent 1.0.0.pre.beta.26 → 1.0.0.pre.beta.27

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: 20188623cbbdcb4d7ce701bfda5d0c4f841d547bf6fe38612f4276182eaa437a
4
- data.tar.gz: 73f8b529249cc8be259e628f1c8e75721b59c2fb645cc544246c19130ecd1106
3
+ metadata.gz: d5a1222f5af1bf778087d4b388f224d8802cb52f4aa59a203d608145f11a0920
4
+ data.tar.gz: a63be1a15f8778eb1a7766ebcc099ef66a39f8804059bb6b1fe9783c45cec718
5
5
  SHA512:
6
- metadata.gz: 3d5a14eb9fa6b8d8af91a7ad6efb33927d5773b762ff82fb73574a858a7d46c252aaad3cc19a2ba026dc1ed65ec0548ba360b90b4fb7baf357a588a66fe442d1
7
- data.tar.gz: 4822e1f4b72633515287e9a5637d4a42914ae233f5baca6f912ffaa90d15db0141c6dc783dd141f23cc3fccebca79552d95a0c3ee829b469ecb6b43f1e089209
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
@@ -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
@@ -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.26"
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.26"
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.26
4
+ version: 1.0.0.pre.beta.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu