avo 3.7.1 → 3.7.3

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: 3e38fc9752d4db0f6986c689d8dc5eafa64df514b411041ba8bfcb9507a5c5ad
4
- data.tar.gz: ace327bb7d3c220da5ae56fa14d7bc278e4b5d62dcce413ba417b0bec92d6f65
3
+ metadata.gz: 14cb5c508e7408422bb0551c9a82571ea3467965cb91b9aa47488ebd8632a9b3
4
+ data.tar.gz: 0eb34a3785aeaaf47679d5ac189a5a8ac0ff8feb0758d217f1a5e9bc38ae17ca
5
5
  SHA512:
6
- metadata.gz: b94790927c1949049b1575502ce7cc497169212410efd3d9f530373170c7b2e776ad303e51b49d432ac3aaafe9be6690f51d03e3b4a702bb311e60e0987ae0f6
7
- data.tar.gz: 302af5c5888eb4c7b1ad58a5a6b62934884777059c86f884f46968e9c8cf0e4ceca7dbfeb37714ba481d63f9a8007f6a6fcdd73e534c0c9173bbf2baf305dbd5
6
+ metadata.gz: db7afe8be4b3a1967a8ada77d55eb58ab29f617d1a9394ed6e7801aae6e1be357682c6a1ddc54e9a170eaf478046bb0d18fc4f2b592a8e740d1abb2665dc0583
7
+ data.tar.gz: 658a22d98d8fd0f24d1ce61df6b11802f5e68b8d4e630b3df41b7a5742c6d7a74b46f02bcfb5bdc65673783188f0f278c5f86b826f09482d6115a6b6fc58f6f5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (3.7.1)
4
+ avo (3.7.3)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
@@ -12,7 +12,7 @@ class Avo::BaseComponent < ViewComponent::Base
12
12
  # Use the @parent_resource to fetch the field using the @reflection name.
13
13
  def field
14
14
  reflection_name = params[:related_name]&.to_sym || @reflection.name
15
- @parent_resource.get_field_definitions.find { |f| f.id == reflection_name }
15
+ @parent_resource.get_field(reflection_name)
16
16
  rescue
17
17
  nil
18
18
  end
@@ -1,4 +1,4 @@
1
- <%= content_tag :div, class: "flex items-start py-1 leading-tight bg-gray-100 text-gray-500 text-xs", data: @data do %>
1
+ <%= content_tag :div, class: @classes, data: @data do %>
2
2
  <div class="py-2 px-6 h-full w-full">
3
3
  <% if @field.as_html %>
4
4
  <%= sanitize @field.value %>
@@ -6,6 +6,7 @@ class Avo::Fields::Common::HeadingComponent < ViewComponent::Base
6
6
  def initialize(field:)
7
7
  @field = field
8
8
  @view = field.resource.view
9
+ @classes = "flex items-start py-1 leading-tight bg-gray-100 text-gray-500 text-xs #{@field.get_html(:classes, view: @view, element: :wrapper)}"
9
10
 
10
11
  @data = stimulus_data_attributes
11
12
  add_stimulus_attributes_for(field.resource, @data)
@@ -110,7 +110,7 @@ module Avo
110
110
  end
111
111
 
112
112
  def set_reflection_field
113
- @field = @resource.get_field_definitions.find { |f| f.id == @related_resource_name.to_sym }
113
+ @field = @resource.get_field(@related_resource_name.to_sym)
114
114
  @field.hydrate(resource: @resource, record: @record, view: :new)
115
115
  rescue
116
116
  end
@@ -34,21 +34,7 @@ module Avo
34
34
  @query = @query.includes(*@resource.includes)
35
35
  end
36
36
 
37
- # Sort the items
38
- if @index_params[:sort_by].present?
39
- unless @index_params[:sort_by].eql? :created_at
40
- @query = @query.unscope(:order)
41
- end
42
-
43
- # Check if the sortable field option is actually a proc and we need to do a custom sort
44
- field_id = @index_params[:sort_by].to_sym
45
- field = @resource.get_field_definitions.find { |field| field.id == field_id }
46
- @query = if field&.sortable.is_a?(Proc)
47
- Avo::ExecutionContext.new(target: field.sortable, query: @query, direction: @index_params[:sort_direction]).handle
48
- else
49
- @query.order("#{@resource.model_class.table_name}.#{@index_params[:sort_by]} #{@index_params[:sort_direction]}")
50
- end
51
- end
37
+ apply_sorting
52
38
 
53
39
  # Apply filters to the current query
54
40
  filters_to_be_applied.each do |filter_class, filter_value|
@@ -600,5 +586,33 @@ module Avo
600
586
  def apply_pagination
601
587
  @pagy, @records = @resource.apply_pagination(index_params: @index_params, query: pagy_query)
602
588
  end
589
+
590
+ def apply_sorting
591
+ return if @index_params[:sort_by].nil?
592
+
593
+ sort_by = @index_params[:sort_by].to_sym
594
+ if sort_by != :created_at
595
+ @query = @query.unscope(:order)
596
+ end
597
+
598
+ # Verify that sort_by param actually is bonded to a field.
599
+ field = @resource.get_field(sort_by)
600
+
601
+ # Check if the sortable field option is a proc and if there is a need to do a custom sort
602
+ @query = if field.present? && field.sortable.is_a?(Proc)
603
+ Avo::ExecutionContext.new(target: field.sortable, query: @query, direction: sanitized_sort_direction).handle
604
+ # Sanitize sort_by param by checking if have bounded field.
605
+ elsif field.present? && sanitized_sort_direction
606
+ @query.order("#{@resource.model_class.table_name}.#{sort_by} #{sanitized_sort_direction}")
607
+ # Transform Model to ActiveRecord::Relation because Avo expects one.
608
+ else
609
+ @query.where("1=1")
610
+ end
611
+ end
612
+
613
+ # Sanitize sort_direction param
614
+ def sanitized_sort_direction
615
+ @sanitized_sort_direction ||= @index_params[:sort_direction].presence_in(["asc", "desc"])
616
+ end
603
617
  end
604
618
  end
@@ -173,9 +173,7 @@ module Avo
173
173
  user: _current_user
174
174
  )
175
175
 
176
- reflection_resource.detect_fields.get_field_definitions.find do |field|
177
- field.id.to_s == params[:via_association_id]
178
- end
176
+ reflection_resource.detect_fields.get_field(params[:via_association_id])
179
177
  end
180
178
 
181
179
  def fetch_parent
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "3.7.1" unless const_defined?(:VERSION)
2
+ VERSION = "3.7.3" 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: 3.7.1
4
+ version: 3.7.3
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-08 00:00:00.000000000 Z
13
+ date: 2024-05-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord