avo 3.0.0.pre17 → 3.0.0.pre18

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: b515703f3cde0908788e725b95e1e2a0bc99c5d16f44ed401d7965e2a96a6d7a
4
- data.tar.gz: 71dc65217c6c24f775303d0a913cb59763b17762540e1941a477e138c5adf035
3
+ metadata.gz: a9c50d4849e253d4fbdd7aa6213feb651e764efe5cf5e4b34341f2dde7b7de18
4
+ data.tar.gz: 6c4a2d98de7136f1f2d4282c05870c1d2a92f2b2c56facc37c9cdf80a25a3cc7
5
5
  SHA512:
6
- metadata.gz: f67a393bd801e3500280fbaf6912df360ef29a949575f8c3e1a42c7f5d2c097b2944ab8895f8135f6263d5b75eb70ef72405f6f2300d3ceae8b063ddc2299cbc
7
- data.tar.gz: f18d6d995b2e70d487d929082bcefc156d6ae68cc0175189b490ec6dd801291482575c9f0a831c0d2c5a93f06ec06458d66cb0f948be1162ff4c72c4f1968fe8
6
+ metadata.gz: 02bcdcf818e190b9e6aa03c638f8bec67525ff4418e5c55e4f8eb4613cea9107a5151b4254a78e1c219881c1a3d1faa0cb4bacf8f38677ccfd194f434080e67f
7
+ data.tar.gz: b6ce2f86cbc6749edad03a442dc8c5b7c70de454845ea84754f66ac2b549af0be8b8def02abd538d1372a600264c7da1cf36e7183ec9f29c294be448ed9f0c3d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (3.0.0.pre17)
4
+ avo (3.0.0.pre18)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
@@ -11,7 +11,7 @@
11
11
  color: :primary,
12
12
  style: :text,
13
13
  'data-turbo-frame': 'attach_modal' do %>
14
- <%= t('avo.attach_item', item: @field.name.downcase) %>
14
+ <%= t('avo.attach_item', item: @field.name.humanize(capitalize: false)) %>
15
15
  <% end %>
16
16
  <% end %>
17
17
  <% if !@field.is_readonly? && !@field.is_disabled? && can_see_the_create_button? %>
@@ -21,7 +21,7 @@
21
21
  'data-turbo-frame': '_top',
22
22
  style: :primary,
23
23
  color: :primary do %>
24
- <%= t('avo.create_new_item', item: @field.name.downcase ) %>
24
+ <%= t('avo.create_new_item', item: @field.name.humanize(capitalize: false) ) %>
25
25
  <% end %>
26
26
  <% end %>
27
27
  <% end %>
@@ -13,10 +13,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
13
13
  end
14
14
 
15
15
  def can_detach?
16
- @reflection.present? &&
17
- @resource.record.present? &&
18
- is_has_many_association &&
19
- authorize_association_for(:detach)
16
+ is_has_many_association? ? super : false
20
17
  end
21
18
 
22
19
  def can_edit?
@@ -76,7 +73,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
76
73
  Avo.resource_manager.get_resource_by_model_class @parent_record.class
77
74
  end
78
75
 
79
- def is_has_many_association
76
+ def is_has_many_association?
80
77
  @reflection.is_a?(::ActiveRecord::Reflection::HasManyReflection) || @reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection)
81
78
  end
82
79
 
@@ -3,7 +3,7 @@
3
3
  data-modal-target="modal"
4
4
  >
5
5
  <div aria-expanded="true" class="modal-overlay absolute w-full h-full bg-opacity-25 bg-gray-800 flex justify-center items-center" data-action="click->modal#close"></div>
6
- <div aria-expanded="true" role="dialog" aria-modal="true" class="modal-body rounded-lg overflow-hidden inset-auto w-11/12 lg:w-1/2 sm:max-w-168 min-h-1/4 bg-white flex z-50 relative shadow-modal">
6
+ <div aria-expanded="true" role="dialog" aria-modal="true" class="modal-body rounded-lg inset-auto w-11/12 lg:w-1/2 sm:max-w-168 min-h-1/4 bg-white flex z-50 relative shadow-modal overflow-auto max-h-full">
7
7
  <div class="flex-1 flex flex-col justify-between">
8
8
  <div>
9
9
  <div class="p-6 text-2xl tracking-normal font-semibold text-black">
@@ -36,6 +36,11 @@
36
36
  <%= sidebar %>
37
37
  </div>
38
38
  <% end %>
39
+ <% if bare_sidebar? %>
40
+ <div class="w-full sm:w-1/3 flex-shrink-0 h-full">
41
+ <%= bare_sidebar %>
42
+ </div>
43
+ <% end %>
39
44
  </div>
40
45
  <% end %>
41
46
  <% if bare_content? %>
@@ -10,6 +10,7 @@ class Avo::PanelComponent < ViewComponent::Base
10
10
  renders_one :tools
11
11
  renders_one :body
12
12
  renders_one :sidebar
13
+ renders_one :bare_sidebar
13
14
  renders_one :bare_content
14
15
  renders_one :footer_tools
15
16
  renders_one :footer
@@ -20,7 +20,14 @@ class Avo::ResourceComponent < Avo::BaseComponent
20
20
  end
21
21
 
22
22
  def can_detach?
23
- authorize_association_for(:detach)
23
+ return false if @reflection.blank? || @resource.record.blank? || !authorize_association_for(:detach)
24
+
25
+ # If the inverse_of is a belongs_to, we need to check if it's optional in order to know if we can detach it.
26
+ if inverse_of.is_a?(ActiveRecord::Reflection::BelongsToReflection)
27
+ inverse_of.options[:optional]
28
+ else
29
+ true
30
+ end
24
31
  end
25
32
 
26
33
  def detach_path
@@ -237,7 +244,7 @@ class Avo::ResourceComponent < Avo::BaseComponent
237
244
  data: {
238
245
  confirm: "Are you sure you want to detach this #{title}."
239
246
  } do
240
- control.label || t("avo.detach_item", item: title).capitalize
247
+ control.label || t("avo.detach_item", item: title).humanize
241
248
  end
242
249
  end
243
250
 
@@ -311,4 +318,21 @@ class Avo::ResourceComponent < Avo::BaseComponent
311
318
  def is_a_related_resource?
312
319
  @reflection.present? && @resource.record.present?
313
320
  end
321
+
322
+ def inverse_of
323
+ current_reflection = @reflection.active_record.reflect_on_all_associations.find do |reflection|
324
+ reflection.name == @reflection.name.to_sym
325
+ end
326
+
327
+ inverse_of = current_reflection.inverse_of
328
+
329
+ if inverse_of.blank? && Rails.env.development?
330
+ puts "WARNING! Avo uses the 'inverse_of' option to determine the inverse association and figure out if the association permit or not detaching."
331
+ # Ex: Please configure the 'inverse_of' option for the ':users' association on the 'Project' model.
332
+ puts "Please configure the 'inverse_of' option for the '#{current_reflection.macro} :#{current_reflection.name}' association on the '#{current_reflection.active_record.name}' model."
333
+ puts "Otherwise the detach button will be visible by default.\n\n"
334
+ end
335
+
336
+ inverse_of
337
+ end
314
338
  end
@@ -7,7 +7,7 @@ class Avo::SidebarComponent < ViewComponent::Base
7
7
  end
8
8
 
9
9
  def dashboards
10
- return [] unless defined?(Avo::Dashboards)
10
+ return [] unless Avo.plugin_manager.installed?("avo-dashboards")
11
11
 
12
12
  Avo::Dashboards.dashboard_manager.dashboards_for_navigation
13
13
  end
@@ -53,7 +53,7 @@ module Avo
53
53
  record: @record,
54
54
  resource: @resource,
55
55
  user: _current_user,
56
- view: @view,
56
+ view: :new, # force the action view to in order to render new-related fields (hidden field)
57
57
  arguments: decrypted_arguments || {}
58
58
  )
59
59
  end
@@ -80,7 +80,8 @@ module Avo
80
80
  flash_messages messages
81
81
 
82
82
  if response[:type] == :redirect
83
- redirect_to Avo::ExecutionContext.new(target: response[:path]).handle
83
+ redirect_to Avo::ExecutionContext.new(target: response[:path]).handle,
84
+ **{allow_other_host: response[:allow_other_host], status: response[:status]}.compact
84
85
  elsif response[:type] == :reload
85
86
  redirect_back fallback_location: resources_path(resource: @resource)
86
87
  end
@@ -79,7 +79,7 @@ module Avo
79
79
  association_name = BaseResource.valid_association_name(@record, params[:related_name])
80
80
 
81
81
  if reflection_class == "HasManyReflection"
82
- @record.send(association_name).delete @attachment_record
82
+ @record.send(association_name).destroy @attachment_record
83
83
  else
84
84
  @record.send("#{association_name}=", nil)
85
85
  end
@@ -14,6 +14,7 @@ module Avo
14
14
  class_attribute :standalone, default: false
15
15
  class_attribute :visible
16
16
  class_attribute :may_download_file, default: false
17
+ class_attribute :turbo
17
18
 
18
19
  attr_accessor :response
19
20
  attr_accessor :record
@@ -38,9 +39,9 @@ module Avo
38
39
  def form_data_attributes
39
40
  # We can't respond with a file download from Turbo se we disable it on the form
40
41
  if may_download_file
41
- {turbo: false, remote: false, action_target: :form}
42
+ {turbo: turbo || false, remote: false, action_target: :form}
42
43
  else
43
- {turbo_frame: :_top, action_target: :form}
44
+ {turbo: turbo, turbo_frame: :_top, action_target: :form}.compact
44
45
  end
45
46
  end
46
47
 
@@ -198,8 +199,10 @@ module Avo
198
199
  self
199
200
  end
200
201
 
201
- def redirect_to(path = nil, &block)
202
+ def redirect_to(path = nil, allow_other_host: nil, status: nil, &block)
202
203
  response[:type] = :redirect
204
+ response[:allow_other_host] = allow_other_host
205
+ response[:status] = status
203
206
  response[:path] = if block.present?
204
207
  block
205
208
  else
@@ -176,7 +176,7 @@ module Avo
176
176
  default = class_name.underscore.humanize
177
177
 
178
178
  if translation_key
179
- t(translation_key, count: 1, default: default).capitalize
179
+ t(translation_key, count: 1, default: default).humanize
180
180
  else
181
181
  default
182
182
  end
@@ -187,7 +187,7 @@ module Avo
187
187
  default = name.pluralize
188
188
 
189
189
  if translation_key
190
- t(translation_key, count: 2, default: default).capitalize
190
+ t(translation_key, count: 2, default: default).humanize
191
191
  else
192
192
  default
193
193
  end
@@ -320,7 +320,7 @@ module Avo
320
320
  when :edit
321
321
  record_title
322
322
  when :new
323
- t("avo.create_new_item", item: name.downcase).upcase_first
323
+ t("avo.create_new_item", item: name.humanize(capitalize: false)).upcase_first
324
324
  end
325
325
  end
326
326
 
@@ -93,11 +93,11 @@ module Avo
93
93
  end
94
94
 
95
95
  def translated_name(default:)
96
- t(translation_key, count: 1, default: default).capitalize
96
+ t(translation_key, count: 1, default: default).humanize
97
97
  end
98
98
 
99
99
  def translated_plural_name(default:)
100
- t(translation_key, count: 2, default: default).capitalize
100
+ t(translation_key, count: 2, default: default).humanize
101
101
  end
102
102
 
103
103
  # Getting the name of the resource (user/users, post/posts)
@@ -6,7 +6,7 @@ module Avo
6
6
  super(**args)
7
7
 
8
8
  if args[:item].present?
9
- @label = I18n.t("avo.create_new_item", item: args[:item]) if label.nil?
9
+ @label = I18n.t("avo.create_new_item", item: args[:item].humanize(capitalize: false)) if label.nil?
10
10
  end
11
11
  end
12
12
  end
@@ -7,7 +7,7 @@ module Avo
7
7
 
8
8
  @label = args[:label] || I18n.t("avo.delete").capitalize
9
9
  if args[:item].present?
10
- @title = I18n.t("avo.delete_item", item: args[:item]).capitalize if title.nil?
10
+ @title = I18n.t("avo.delete_item", item: args[:item]).humanize if title.nil?
11
11
  @confirmation_message = I18n.t("avo.are_you_sure") if confirmation_message.nil?
12
12
  end
13
13
  end
@@ -6,7 +6,7 @@ module Avo
6
6
  super(**args)
7
7
 
8
8
  if args[:item].present?
9
- @title = I18n.t("avo.detach_item", item: args[:item]).capitalize if title.nil?
9
+ @title = I18n.t("avo.detach_item", item: args[:item]).humanize if title.nil?
10
10
  @confirmation_message = I18n.t("avo.are_you_sure_detach_item", item: args[:item]) if confirmation_message.nil?
11
11
  end
12
12
  end
@@ -7,7 +7,7 @@ module Avo
7
7
 
8
8
  @label = args[:label] || I18n.t("avo.edit").capitalize
9
9
  if args[:item].present?
10
- @title = I18n.t("avo.edit_item", item: args[:item]).capitalize if title.nil?
10
+ @title = I18n.t("avo.edit_item", item: args[:item]).humanize if title.nil?
11
11
  end
12
12
  end
13
13
  end
@@ -6,7 +6,7 @@ module Avo
6
6
  super(**args)
7
7
 
8
8
  if args[:item].present?
9
- @title = I18n.t("avo.view_item", item: args[:item]).capitalize if title.nil?
9
+ @title = I18n.t("avo.view_item", item: args[:item]).humanize if title.nil?
10
10
  end
11
11
  end
12
12
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "3.0.0.pre17" unless const_defined?(:VERSION)
2
+ VERSION = "3.0.0.pre18" unless const_defined?(:VERSION)
3
3
  end