avo 2.50.0 → 2.52.0

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: 6ec2fc0304d9fb79831bfe41b68a8ca9b4df52526e2212f2e8db9cd073837ee8
4
- data.tar.gz: 45b6b466d8528de3f7bbf182b53ce38b1efb5c14ad6958fa58e5ce4a83070a57
3
+ metadata.gz: ecf46732c743cb0408230bc9b73ec747d2094603d9ac4673b9a8bcf6e3510247
4
+ data.tar.gz: b74e17cfa53122dc69ccc4cf91578132f59ac3b3ef3f912e0991360db1380ecc
5
5
  SHA512:
6
- metadata.gz: 65de9dbd9c220bd8a9723f5e952db9339def09d0f4a9ec0470b3f7dca05d8c970591341cff79986167136821658ad5a400e74bdce12ea66c692108b53b82ffa4
7
- data.tar.gz: 5732cf3b83f079b62f4eb4754114d759ad5a4ecc5673ddebe0e7da58f3ff48b294266945d2104ac70aa16681acdc3bafd09b81c2a7227851791786f19589a1f5
6
+ metadata.gz: e9e9b5751953ed132817a67240cda51c1aa46c23331fe54715fac61207e60eba5cd1605b650b34eed205818b20fd8ce965757f40ba9b200974aae45a6aaf1660
7
+ data.tar.gz: f97d7ef68d013033215daed86e2be33bb116c37ddd9a6113bc8d4eb1954ede77689a20c664ea4e9fe896e726d96e4e2f909f6231bfbb5cfe07bc05e8275a4cd8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.50.0)
4
+ avo (2.52.0)
5
5
  actionview (>= 6.0)
6
6
  active_link_to
7
7
  activerecord (>= 6.0)
@@ -48,13 +48,18 @@ module Avo
48
48
  @query = @query.unscope(:order)
49
49
  end
50
50
 
51
+ sanitized_sort_direction = @index_params[:sort_direction].presence_in(["asc", "desc"])
52
+
51
53
  # Check if the sortable field option is actually a proc and we need to do a custom sort
52
- field_id = @index_params[:sort_by].to_sym
53
- field = @resource.get_field_definitions.find { |field| field.id == field_id }
54
+ sort_by = @index_params[:sort_by].to_sym
55
+ field = @resource.get_field(sort_by)
54
56
  @query = if field&.sortable.is_a?(Proc)
55
- field.sortable.call(@query, @index_params[:sort_direction])
57
+ field.sortable.call(@query, sanitized_sort_direction)
58
+ elsif field.present? && sanitized_sort_direction
59
+ @query.order("#{@resource.model_class.table_name}.#{sort_by} #{sanitized_sort_direction}")
60
+ # Transform Model to ActiveRecord::Relation because Avo expects one.
56
61
  else
57
- @query.order("#{@resource.model_class.table_name}.#{@index_params[:sort_by]} #{@index_params[:sort_direction]}")
62
+ @query.where("1=1")
58
63
  end
59
64
  end
60
65
 
@@ -114,7 +114,7 @@ module Avo
114
114
  end
115
115
 
116
116
  def get_record_associations(record)
117
- record._reflections
117
+ record.class.reflections
118
118
  end
119
119
 
120
120
  def valid_association_name(record, association_name)
@@ -382,7 +382,7 @@ module Avo
382
382
 
383
383
  if field.type == "belongs_to"
384
384
 
385
- reflection = @model._reflections[@params[:via_relation]]
385
+ reflection = @model.class.reflections[@params[:via_relation]]
386
386
 
387
387
  if field.polymorphic_as.present? && field.types.map(&:to_s).include?(@params[:via_relation_class])
388
388
  # set the value to the actual record
@@ -245,10 +245,10 @@ module Avo
245
245
 
246
246
  reflection_key = polymorphic_as || id
247
247
 
248
- if @model._reflections[reflection_key.to_s].klass.present?
249
- App.get_resource_by_model_name @model._reflections[reflection_key.to_s].klass.to_s
250
- elsif @model._reflections[reflection_key.to_s].options[:class_name].present?
251
- App.get_resource_by_model_name @model._reflections[reflection_key.to_s].options[:class_name]
248
+ if @model.class.reflect_on_association(reflection_key).klass.present?
249
+ App.get_resource_by_model_name @model.class.reflect_on_association(reflection_key).klass.to_s
250
+ elsif @model.class.reflect_on_association(reflection_key).options[:class_name].present?
251
+ App.get_resource_by_model_name @model.class.reflect_on_association(reflection_key).options[:class_name]
252
252
  else
253
253
  App.get_resource_by_name reflection_key.to_s
254
254
  end
@@ -59,10 +59,10 @@ module Avo
59
59
  end
60
60
 
61
61
  def target_resource
62
- if @model._reflections[id.to_s].klass.present?
63
- Avo::App.get_resource_by_model_name @model._reflections[id.to_s].klass.to_s
64
- elsif @model._reflections[id.to_s].options[:class_name].present?
65
- Avo::App.get_resource_by_model_name @model._reflections[id.to_s].options[:class_name]
62
+ if @model.class.reflect_on_association(id).klass.present?
63
+ Avo::App.get_resource_by_model_name @model.class.reflect_on_association(id).klass.to_s
64
+ elsif @model.class.reflect_on_association(id).options[:class_name].present?
65
+ Avo::App.get_resource_by_model_name @model.class.reflect_on_association(id).options[:class_name]
66
66
  else
67
67
  Avo::App.get_resource_by_name id.to_s
68
68
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.50.0" unless const_defined?(:VERSION)
2
+ VERSION = "2.52.0" 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.50.0
4
+ version: 2.52.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-05-07 00:00:00.000000000 Z
13
+ date: 2024-08-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord