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 +4 -4
- data/Gemfile.lock +1 -1
- data/app/components/avo/base_component.rb +1 -1
- data/app/components/avo/fields/common/heading_component.html.erb +1 -1
- data/app/components/avo/fields/common/heading_component.rb +1 -0
- data/app/controllers/avo/associations_controller.rb +1 -1
- data/app/controllers/avo/base_controller.rb +29 -15
- data/app/controllers/avo/search_controller.rb +1 -3
- data/lib/avo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14cb5c508e7408422bb0551c9a82571ea3467965cb91b9aa47488ebd8632a9b3
|
4
|
+
data.tar.gz: 0eb34a3785aeaaf47679d5ac189a5a8ac0ff8feb0758d217f1a5e9bc38ae17ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db7afe8be4b3a1967a8ada77d55eb58ab29f617d1a9394ed6e7801aae6e1be357682c6a1ddc54e9a170eaf478046bb0d18fc4f2b592a8e740d1abb2665dc0583
|
7
|
+
data.tar.gz: 658a22d98d8fd0f24d1ce61df6b11802f5e68b8d4e630b3df41b7a5742c6d7a74b46f02bcfb5bdc65673783188f0f278c5f86b826f09482d6115a6b6fc58f6f5
|
data/Gemfile.lock
CHANGED
@@ -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.
|
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:
|
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.
|
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
|
-
|
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.
|
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
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.
|
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-
|
13
|
+
date: 2024-05-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|