avo 2.29.0 → 2.29.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 572070da39670d32588de6616a4b51015615efe3482ea813fe148035bba33cf7
4
- data.tar.gz: 9a1056b36ab1d3ceebd06eeb505fb5641f41d9ddbe943e48e87627030df2edb0
3
+ metadata.gz: b9d8214e93c30dd465007288d2ca82334dc8f2ffd30059f0c04402b4aca22c1b
4
+ data.tar.gz: 6075d940fb8afcfff6d4c82f856b41c6545717f3847665ad962b225bd836218d
5
5
  SHA512:
6
- metadata.gz: 95570888ee4d613f5062f3cf924aa7af69d1b6675a042da4a0ed75131a5e858ab451ab4d23c85ceed79c1a8f57508ef2dda4540cdbc7462f96ff251e1f70a20c
7
- data.tar.gz: 3941183c0d08772696b52fdc5bac795d35002d87309dd7d5963d1f9b4d7b1107354ba3cf0d116a8752af35ec54a39e0f89de4c05df2e67df28aaa1b062aa1f39
6
+ metadata.gz: 4d6889479a700d4e9f574c0b036e23539512f771d5df2258f2449caf5f7221610839beb56dd7591ff0f476938edf0e7ea86b769c14d1f8e65fb81d523e7bab9e
7
+ data.tar.gz: 2301b54dfaeab3b9c077ade8b59112e011b42622f1b72ad1f3ed8593bb8c93d1f425616f737d6b898d288fe8885d8fae67b83fe19979800dec32ca1f46b051ba
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.29.0)
4
+ avo (2.29.1)
5
5
  actionview (>= 6.0)
6
6
  active_link_to
7
7
  activerecord (>= 6.0)
@@ -222,7 +222,7 @@ GEM
222
222
  image_processing (1.12.2)
223
223
  mini_magick (>= 4.9.5, < 5)
224
224
  ruby-vips (>= 2.0.17, < 3)
225
- inline_svg (1.8.0)
225
+ inline_svg (1.9.0)
226
226
  activesupport (>= 3.0)
227
227
  nokogiri (>= 1.6)
228
228
  iso (0.4.0)
@@ -31,6 +31,10 @@ class Avo::Fields::BelongsToField::EditComponent < Avo::Fields::EditComponent
31
31
  @resource.model["#{@field.foreign_key}_type"]
32
32
  end
33
33
 
34
+ def polymorphic_resource
35
+ ::Avo::App.get_resource_by_model_name(polymorphic_class)
36
+ end
37
+
34
38
  # Get the polymorphic id
35
39
  def polymorphic_id
36
40
  @resource.model["#{@field.foreign_key}_id"]
@@ -44,7 +48,7 @@ class Avo::Fields::BelongsToField::EditComponent < Avo::Fields::EditComponent
44
48
 
45
49
  return @polymorphic_record if @polymorphic_record.present?
46
50
 
47
- @polymorphic_record = @resource.find_record polymorphic_id, query: polymorphic_class.safe_constantize, params: params
51
+ @polymorphic_record = polymorphic_resource.find_record polymorphic_id, query: polymorphic_class.safe_constantize, params: params
48
52
 
49
53
  @polymorphic_record
50
54
  end
@@ -36,11 +36,15 @@ class Avo::Fields::HasOneField::ShowComponent < Avo::Fields::ShowComponent
36
36
  end
37
37
 
38
38
  def create_path
39
+ association_id = @field.resource.model_class._reflections[@field.id.to_s].inverse_of.name
40
+
39
41
  args = {
40
- via_relation: @resource.singular_model_key,
42
+ via_relation: association_id,
41
43
  via_relation_class: @resource.model_class.to_s,
42
- via_resource_id: @resource.model.to_param
44
+ via_resource_id: @resource.model.to_param,
45
+ via_association_type: :has_one
43
46
  }
47
+
44
48
  helpers.new_resource_path(resource: @field.target_resource, **args)
45
49
  end
46
50
  end
@@ -1,3 +1,5 @@
1
+ <%# via_association_type is used in has_one create actions %>
2
+ <%= hidden_field_tag :via_association_type, params[:via_association_type] if params[:via_association_type] %>
1
3
  <%= hidden_field_tag :via_resource_class, params[:via_resource_class] if params[:via_resource_class] %>
2
4
  <%= hidden_field_tag :via_resource_id, params[:via_resource_id] if params[:via_resource_id] %>
3
5
  <%= hidden_field_tag :via_relation, params[:via_relation] if params[:via_relation] %>
@@ -85,10 +85,6 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
85
85
  args[:via_relation] = @reflection.name
86
86
  end
87
87
 
88
- if @reflection.parent_reflection.present? && @reflection.parent_reflection.inverse_of.present?
89
- args[:via_relation] = @reflection.parent_reflection.inverse_of.name
90
- end
91
-
92
88
  if @reflection.inverse_of.present?
93
89
  args[:via_relation] = @reflection.inverse_of.name
94
90
  end
@@ -151,7 +151,12 @@ module Avo
151
151
  @related_record = via_resource.find_record params[:via_resource_id], params: params
152
152
  association_name = BaseResource.valid_association_name(@model, params[:via_relation])
153
153
 
154
- @model.send(association_name) << @related_record
154
+ if params[:via_association_type] == "has_one"
155
+ # On has_one scenarios we should switch the @record and @related_record
156
+ @related_record.send("#{@reflection.parent_reflection.inverse_of.name}=", @model)
157
+ else
158
+ @model.send(association_name) << @related_record
159
+ end
155
160
  end
156
161
  end
157
162
 
@@ -382,7 +382,8 @@ module Avo
382
382
 
383
383
  if field.polymorphic_as.present? && field.types.map(&:to_s).include?(@params[:via_relation_class])
384
384
  # set the value to the actual record
385
- value = @params[:via_relation_class].safe_constantize.find(@params[:via_resource_id])
385
+ via_resource = ::Avo::App.get_resource_by_model_name(@params[:via_relation_class])
386
+ value = via_resource.find_record(@params[:via_resource_id])
386
387
  elsif reflection.present? && reflection.foreign_key.present? && field.id.to_s == @params[:via_relation].to_s
387
388
  resource = Avo::App.get_resource_by_model_name params[:via_relation_class]
388
389
  model = resource.find_record @params[:via_resource_id], params: params
@@ -11,7 +11,7 @@ module Avo
11
11
 
12
12
  class_attribute :id
13
13
 
14
- def initialize(dashboard: nil, label: nil, invisible: false, index: nil, visible: nil)
14
+ def initialize(dashboard: nil, label: nil, invisible: false, index: nil, visible: true)
15
15
  @dashboard = dashboard
16
16
  @label = label
17
17
  @invisible = invisible
@@ -33,7 +33,8 @@ module Avo
33
33
  related_model = nil
34
34
  else
35
35
  related_class = model.class.reflections[name.to_s.downcase].class_name
36
- related_model = related_class.safe_constantize.find value
36
+ related_resource = ::Avo::App.get_resource_by_model_name(related_class)
37
+ related_model = related_resource.find_record value
37
38
  end
38
39
 
39
40
  model.public_send("#{key}=", related_model)
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.29.0" unless const_defined?(:VERSION)
2
+ VERSION = "2.29.1" unless const_defined?(:VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.29.0
4
+ version: 2.29.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-03-28 00:00:00.000000000 Z
12
+ date: 2023-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord