avo 3.0.0.pre11 → 3.0.0.pre12

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: 8a1674354633c9b8113bfdeba7a9e53ac54bd3f75af78c9492655c485c43a0ff
4
- data.tar.gz: 53bd8bb7f50267e0b4756164fb85ffa1fe013a1c7642c4417dabd9d2320e4b57
3
+ metadata.gz: 76b9e80370d7cd7011b456fe12affdd877ac7ea71d44ae1774ff661a2a0a5452
4
+ data.tar.gz: 1ce30818dee6f87d249f1e23e5d0c7ee73c9b8e67862c77f393a7598e5d712b4
5
5
  SHA512:
6
- metadata.gz: 857ed520648c9cbe1d2361c11bd6f48266c25c1c8fc0175b0843de23edbb7518eff352f8495c95bb6238a7d4e93e7a003fa1d86467d4999524baa6c1cb19042d
7
- data.tar.gz: 32bf4c5d55be3aeae79411fd30df1a550eb8b417fd76680cee40925b4a1a9265c5a7b9d241182d638b333666fea00c95d811d9bc868a8f80b32aba3457f48e21
6
+ metadata.gz: c90992abccb5192dec1ce3414f4c14bf51dc7e665a08320df9c4a154c7539b55d4bdfa4c6d23322ffc5a550b27f9eb15815298ad07b23a2e7f7fc8ed8be4f16e
7
+ data.tar.gz: 390a9b9988437466ced356326a811d6cabdfa360d0982e8dfc464254cf3025bd6660d5ef1656fc44cee2d0fffcffd8f2907488379eb3d817cf6ea2493c976a72
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (3.0.0.pre11)
4
+ avo (3.0.0.pre12)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
@@ -18,7 +18,7 @@
18
18
  multipart: true do |form| %>
19
19
  <%= render Avo::ReferrerParamsComponent.new back_path: back_path %>
20
20
  <%= content_tag :div, class: 'space-y-12' do %>
21
- <%= render Avo::PanelComponent.new(name: title, description: @resource.resource_description, display_breadcrumbs: @reflection.blank?, index: 0, data: { panel_id: "main" }) do |c| %>
21
+ <%= render Avo::PanelComponent.new(name: title, description: @resource.description, display_breadcrumbs: @reflection.blank?, index: 0, data: { panel_id: "main" }) do |c| %>
22
22
  <% c.with_tools do %>
23
23
  <% @resource.render_edit_controls.each do |control| %>
24
24
  <%= render_control control %>
@@ -121,7 +121,7 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
121
121
  return
122
122
  end
123
123
 
124
- @resource.resource_description
124
+ @resource.description
125
125
  end
126
126
 
127
127
  def show_search_input
@@ -7,7 +7,7 @@
7
7
  selected_resources: [@resource.record.id],
8
8
  **@resource.stimulus_data_attributes
9
9
  } do %>
10
- <%= render Avo::PanelComponent.new(name: title, description: @resource.resource_description, display_breadcrumbs: @reflection.blank?, index: 0, data: { panel_id: "main" }) do |c| %>
10
+ <%= render Avo::PanelComponent.new(name: title, description: @resource.description, display_breadcrumbs: @reflection.blank?, index: 0, data: { panel_id: "main" }) do |c| %>
11
11
  <% c.with_tools do %>
12
12
  <% @resource.render_show_controls.each do |control| %>
13
13
  <%= render_control control %>
@@ -82,13 +82,7 @@ module Avo
82
82
  flash_messages messages
83
83
 
84
84
  if response[:type] == :redirect
85
- path = response[:path]
86
-
87
- if path.respond_to? :call
88
- path = instance_eval(&path)
89
- end
90
-
91
- redirect_to path
85
+ redirect_to Avo::ExecutionContext.new(target: response[:path]).handle
92
86
  elsif response[:type] == :reload
93
87
  redirect_back fallback_location: resources_path(resource: @resource)
94
88
  end
@@ -47,7 +47,7 @@ module Avo
47
47
  field_id = @index_params[:sort_by].to_sym
48
48
  field = @resource.get_field_definitions.find { |field| field.id == field_id }
49
49
  @query = if field&.sortable.is_a?(Proc)
50
- field.sortable.call(@query, @index_params[:sort_direction])
50
+ Avo::ExecutionContext.new(target: field.sortable, query: @query, direction: @index_params[:sort_direction]).handle
51
51
  else
52
52
  @query.order("#{@resource.model_class.table_name}.#{@index_params[:sort_by]} #{@index_params[:sort_direction]}")
53
53
  end
data/lib/avo/app.rb CHANGED
@@ -38,7 +38,7 @@ module Avo
38
38
  when "ActiveSupport::Cache::MemCacheStore", "ActiveSupport::Cache::RedisCacheStore"
39
39
  Rails.cache
40
40
  else
41
- ActiveSupport::Cache.lookup_store(:file_store, "/tmp/cache")
41
+ ActiveSupport::Cache.lookup_store(:file_store, Rails.root.join("tmp", "cache"))
42
42
  end
43
43
  elsif Rails.env.test?
44
44
  Rails.cache
@@ -8,6 +8,7 @@ module Avo
8
8
  include Avo::Concerns::HasControls
9
9
  include Avo::Concerns::HasStimulusControllers
10
10
  include Avo::Concerns::ModelClassConstantized
11
+ include Avo::Concerns::HasDescription
11
12
 
12
13
  # Avo::Current methods
13
14
  delegate :context, to: Avo::Current
@@ -38,7 +39,6 @@ module Avo
38
39
 
39
40
  class_attribute :id, default: :id
40
41
  class_attribute :title, default: :id
41
- class_attribute :description, default: :id
42
42
  class_attribute :search_query, default: nil
43
43
  class_attribute :search_query_help, default: ""
44
44
  class_attribute :search_result_path
@@ -280,16 +280,6 @@ module Avo
280
280
  name
281
281
  end
282
282
 
283
- def resource_description
284
- return instance_exec(&self.class.description) if self.class.description.respond_to? :call
285
-
286
- # Show the description only on the resource index view.
287
- # If the user wants to conditionally it on all pages, they should use a block.
288
- if view == :index
289
- return self.class.description if self.class.description.is_a? String
290
- end
291
- end
292
-
293
283
  def translation_key
294
284
  self.class.translation_key || "avo.resource_translations.#{class_name.underscore}"
295
285
  end
@@ -515,7 +505,7 @@ module Avo
515
505
  nil
516
506
  end
517
507
 
518
- def description
508
+ def search_description
519
509
  description_field&.value
520
510
  end
521
511
 
@@ -543,5 +533,13 @@ module Avo
543
533
  def record_id
544
534
  record.send(id_attribute)
545
535
  end
536
+
537
+ def description_attributes
538
+ {
539
+ view: view,
540
+ resource: self,
541
+ record: record
542
+ }
543
+ end
546
544
  end
547
545
  end
@@ -50,7 +50,7 @@ module Avo
50
50
  when Symbol
51
51
  context.send(name)
52
52
  when Proc
53
- name.call(context)
53
+ Avo::ExecutionContext.new(target: name, context: context).handle
54
54
  else
55
55
  name.to_s
56
56
  end
@@ -61,7 +61,7 @@ module Avo
61
61
  when Symbol
62
62
  context.send(path)
63
63
  when Proc
64
- path.call(context)
64
+ Avo::ExecutionContext.new(target: path, context: context).handle
65
65
  else
66
66
  context.url_for(path)
67
67
  end
@@ -34,9 +34,11 @@ module Avo
34
34
  end
35
35
 
36
36
  def cache_resource_filters?
37
- return Avo.configuration.cache_resource_filters unless Avo.configuration.cache_resource_filters.is_a?(Proc)
38
-
39
- Avo.configuration.cache_resource_filters.call(current_user: current_user, resource: @resource)
37
+ Avo::ExecutionContext.new(
38
+ target: Avo.configuration.cache_resource_filters,
39
+ current_user: current_user,
40
+ resource: @resource
41
+ ).handle
40
42
  end
41
43
  end
42
44
  end
@@ -0,0 +1,23 @@
1
+ # Adds the ability to set the visibility of an item in the execution context.
2
+ module Avo
3
+ module Concerns
4
+ module HasDescription
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ attr_accessor :description
9
+ end
10
+
11
+ def description
12
+ Avo::ExecutionContext.new(target: @description || self.class.description, **description_attributes).handle
13
+ end
14
+
15
+ private
16
+
17
+ # Override this method to add custom attributes to the description execution context.
18
+ def description_attributes
19
+ {}
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "3.0.0.pre11" unless const_defined?(:VERSION)
2
+ VERSION = "3.0.0.pre12" unless const_defined?(:VERSION)
3
3
  end
@@ -51,7 +51,7 @@ Avo.configure do |config|
51
51
  ## permanent enable or disable cache_resource_filters, default value is false
52
52
  # config.cache_resource_filters = false
53
53
  ## provide a lambda to enable or disable cache_resource_filters per user/resource.
54
- # config.cache_resource_filters = ->(current_user:, resource:) { current_user.cache_resource_filters?}
54
+ # config.cache_resource_filters = -> { current_user.cache_resource_filters? }
55
55
 
56
56
  ## == Customization ==
57
57
  # config.app_name = 'Avocadelicious'
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.0.0.pre11
4
+ version: 3.0.0.pre12
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-05-17 00:00:00.000000000 Z
12
+ date: 2023-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -1710,6 +1710,7 @@ files:
1710
1710
  - lib/avo/concerns/can_replace_items.rb
1711
1711
  - lib/avo/concerns/filters_session_handler.rb
1712
1712
  - lib/avo/concerns/has_controls.rb
1713
+ - lib/avo/concerns/has_description.rb
1713
1714
  - lib/avo/concerns/has_item_type.rb
1714
1715
  - lib/avo/concerns/has_items.rb
1715
1716
  - lib/avo/concerns/has_stimulus_controllers.rb