avo 3.5.0 → 3.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cff3e9f78fc82e1a9a80221261f1aa29fec6f2efc670d590d8837c5a9224e1af
4
- data.tar.gz: fd5fb058686183dd40daeeaf5a112648e4a6162668056ce871ced723a1471fc6
3
+ metadata.gz: b09b96bd49a61cf405e01532f30b33471437b1b354efad21ccd3c0ad193fdc90
4
+ data.tar.gz: b35e575c1787a34a5b1a2185127f39075b808d833993d3bd8584ea877dc14035
5
5
  SHA512:
6
- metadata.gz: 89b46f1776ec508ca2f11343dfeb77cce80863ffbf984f4535281a22f5fa129721b819abaeca0fc3c83a95121aed822f27ef78abbe43326a13bb6d23b3e175bf
7
- data.tar.gz: 18e81a302f60c0eac7717d62e71cb6a18bcceb6108a3b60bacd92ec17b5c2b99fe898453759213abcf52be79d6212f34483697a98ec1b25aaf1ad6cf560359c6
6
+ metadata.gz: 87e3e97b4e3e001080341a61565e97674d5e7ba9703a980bae1d769180afb648d5a0dff42d7901b5f42370a2915eb689951bff02cba33cb3183a634faa3c726b
7
+ data.tar.gz: a9841007e4c2226651a0c3b86d5ed25b189f2ad5fceb258bf23f79a8c5931cfcaefa68d8657e895483404c45f6fb8064e5c4b418db5b3282cc2fe7cb2d8e485c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (3.5.0)
4
+ avo (3.5.2)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
@@ -4,7 +4,7 @@
4
4
  <%== item_selector_init @resource %>
5
5
  data-resource-name="<%= @resource.class.to_s %>"
6
6
  data-record-id="<%= @resource.record.id %>"
7
- <%= drag_reorder_item_attributes %>
7
+ <%= try :drag_reorder_item_attributes %>
8
8
  >
9
9
  <%= content_tag :div,
10
10
  class: "relative w-full pb-3/4 rounded-t overflow-hidden #{html(:cover, :classes)}",
@@ -2,7 +2,6 @@
2
2
 
3
3
  class Avo::Index::GridItemComponent < Avo::BaseComponent
4
4
  include Avo::ResourcesHelper
5
- include Avo::Concerns::CanReorderItems
6
5
  include Avo::Fields::Concerns::HasHTMLAttributes
7
6
 
8
7
  attr_reader :parent_resource, :actions
@@ -1,9 +1,4 @@
1
1
  <div class="space-x-2 flex flex-row justify-end w-full">
2
- <% if can_dnd_reorder? %>
3
- <div class="handle">
4
- <%= helpers.svg 'heroicons/outline/bars-3', class: 'text-gray-400 h-6 hover:text-gray-600 cursor-pointer' %>
5
- </div>
6
- <% end %>
7
2
  <% @resource.render_row_controls(item: singular_resource_name).each do |control| %>
8
3
  <%= render_control control %>
9
4
  <% end %>
@@ -2,7 +2,6 @@
2
2
 
3
3
  class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
4
4
  include Avo::ApplicationHelper
5
- include Avo::Concerns::CanReorderItems
6
5
 
7
6
  def initialize(resource: nil, reflection: nil, parent_record: nil, parent_resource: nil, view_type: :table, actions: nil)
8
7
  @resource = resource
@@ -162,7 +161,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
162
161
  end
163
162
 
164
163
  def render_order_controls(control)
165
- if can_reorder?
164
+ if try(:can_reorder?)
166
165
  render Avo::Pro::Ordering::ButtonsComponent.new resource: @resource, reflection: @reflection, view_type: @view_type
167
166
  end
168
167
  end
@@ -1,7 +1,7 @@
1
1
  <% if @resources.present? %>
2
2
  <turbo-frame id="<%= @resource.model_key %>_list" target="_top" class="relative w-full">
3
3
  <div class="w-full grid grid-cols-1 xs:grid-cols-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-6 gap-6 mt-8"
4
- <%= drag_reorder_attributes %>
4
+ <%= try :drag_reorder_attributes %>
5
5
  data-component-name="<%= self.class.to_s.underscore %>"
6
6
  data-selected-resources-name="<%= @resource.model_key %>" data-selected-resources="[]">
7
7
  <% @resources.each_with_index do |resource, index| %>
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Avo::Index::ResourceGridComponent < Avo::BaseComponent
4
- include Avo::Concerns::CanReorderItems
5
4
  attr_reader :actions
6
5
 
7
6
  def initialize(resources: nil, resource: nil, reflection: nil, parent_record: nil, parent_resource: nil, actions: nil)
@@ -39,7 +39,7 @@
39
39
  <% end %>
40
40
  <table class="w-full px-4 bg-white">
41
41
  <%= render partial: 'avo/partials/table_header', locals: {fields: @resource.get_fields(reflection: @reflection, only_root: true)} %>
42
- <tbody class="divide-y" <%= drag_reorder_attributes %>>
42
+ <tbody class="divide-y" <%= try :drag_reorder_attributes %>>
43
43
  <% @resources.each_with_index do |resource, index| %>
44
44
  <% cache_if Avo.configuration.cache_resources_on_index_view, resource.cache_hash(@parent_record), expires_in: 1.day do %>
45
45
  <%= render Avo::Index::TableRowComponent.new(resource: resource, reflection: @reflection, parent_record: @parent_record, parent_resource: @parent_resource, actions: @actions) %>
@@ -2,7 +2,6 @@
2
2
 
3
3
  class Avo::Index::ResourceTableComponent < Avo::BaseComponent
4
4
  include Avo::ApplicationHelper
5
- include Avo::Concerns::CanReorderItems
6
5
  attr_reader :pagy, :query
7
6
 
8
7
  def initialize(resources: nil, resource: nil, reflection: nil, parent_record: nil, parent_resource: nil, pagy: nil, query: nil, actions: nil)
@@ -5,7 +5,7 @@
5
5
  <%== item_selector_init @resource %>
6
6
  data-resource-name="<%= @resource.class.to_s %>"
7
7
  data-record-id="<%= @resource.record.id %>"
8
- <%= drag_reorder_item_attributes %>
8
+ <%= try :drag_reorder_item_attributes %>
9
9
  >
10
10
  <% if @resource.record_selector %>
11
11
  <td class="w-10">
@@ -2,7 +2,6 @@
2
2
 
3
3
  class Avo::Index::TableRowComponent < Avo::BaseComponent
4
4
  include Avo::ResourcesHelper
5
- include Avo::Concerns::CanReorderItems
6
5
 
7
6
  def initialize(resource: nil, reflection: nil, parent_record: nil, parent_resource: nil, actions: nil)
8
7
  @resource = resource
@@ -1,4 +1,6 @@
1
1
  class Avo::ResourceComponent < Avo::BaseComponent
2
+ include Avo::Concerns::ChecksAssocAuthorization
3
+
2
4
  attr_reader :fields_by_panel
3
5
  attr_reader :has_one_panels
4
6
  attr_reader :has_many_panels
@@ -7,8 +9,6 @@ class Avo::ResourceComponent < Avo::BaseComponent
7
9
  attr_reader :resource
8
10
  attr_reader :view
9
11
 
10
- include Avo::Concerns::ChecksAssocAuthorization
11
-
12
12
  def can_create?
13
13
  return authorize_association_for(:create) if @reflection.present?
14
14
 
@@ -177,24 +177,27 @@ module Avo
177
177
  end
178
178
 
179
179
  def name
180
- default = class_name.underscore.humanize
181
-
182
- if translation_key
183
- t(translation_key, count: 1, default: default).humanize
184
- else
185
- default
186
- end
180
+ name_from_translation_key(count: 1, default: class_name.underscore.humanize)
187
181
  end
188
182
  alias_method :singular_name, :name
189
183
 
190
184
  def plural_name
191
- default = name.pluralize
185
+ name_from_translation_key(count: 2, default: name.pluralize)
186
+ end
192
187
 
193
- if translation_key
194
- t(translation_key, count: 2, default: default).humanize
195
- else
196
- default
197
- end
188
+ # Get the name from the translation_key and fallback to default
189
+ # It can raise I18n::InvalidPluralizationData when using only resource_translation without pluralization keys like: one, two or other key
190
+ # Example:
191
+ # ---
192
+ # en:
193
+ # avo:
194
+ # resource_translations:
195
+ # product:
196
+ # save: "Save product"
197
+ def name_from_translation_key(count:, default:)
198
+ t(translation_key, count:, default:).humanize
199
+ rescue I18n::InvalidPluralizationData
200
+ default
198
201
  end
199
202
 
200
203
  def underscore_name
@@ -448,14 +451,14 @@ module Avo
448
451
  def file_hash
449
452
  content_to_be_hashed = ""
450
453
 
451
- # resource file hash
452
- resource_path = Rails.root.join("app", "avo", "resources", "#{self.class.name.underscore}.rb").to_s
454
+ file_name = self.class.underscore_name.tr(" ", "_")
455
+ resource_path = Rails.root.join("app", "avo", "resources", "#{file_name}.rb").to_s
453
456
  if File.file? resource_path
454
457
  content_to_be_hashed += File.read(resource_path)
455
458
  end
456
459
 
457
460
  # policy file hash
458
- policy_path = Rails.root.join("app", "policies", "#{self.class.name.underscore.gsub("_resource", "")}_policy.rb").to_s
461
+ policy_path = Rails.root.join("app", "policies", "#{file_name.gsub("_resource", "")}_policy.rb").to_s
459
462
  if File.file? policy_path
460
463
  content_to_be_hashed += File.read(policy_path)
461
464
  end
@@ -16,7 +16,7 @@ module Avo
16
16
  end
17
17
 
18
18
  def render_edit_controls
19
- [BackButton.new(label: I18n.t("avo.cancel").capitalize), DeleteButton.new, ActionsList.new, SaveButton.new]
19
+ [BackButton.new(label: I18n.t("avo.cancel").capitalize), DeleteButton.new, ActionsList.new, SaveButton.new(resource: self)]
20
20
  end
21
21
 
22
22
  def render_index_controls(item:)
@@ -5,7 +5,10 @@ module Avo
5
5
  def initialize(**args)
6
6
  super(**args)
7
7
 
8
- @label = args[:label] || I18n.t("avo.save").capitalize
8
+ @label = args[:label] || I18n.t(
9
+ "#{args[:resource].translation_key}.save",
10
+ default: I18n.t("avo.save")
11
+ ).capitalize
9
12
  end
10
13
  end
11
14
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "3.5.0" unless const_defined?(:VERSION)
2
+ VERSION = "3.5.2" 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.5.0
4
+ version: 3.5.2
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-03-13 00:00:00.000000000 Z
13
+ date: 2024-03-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -2170,7 +2170,6 @@ files:
2170
2170
  - lib/avo/base_resource_tool.rb
2171
2171
  - lib/avo/concerns/borrow_items_holder.rb
2172
2172
  - lib/avo/concerns/breadcrumbs.rb
2173
- - lib/avo/concerns/can_reorder_items.rb
2174
2173
  - lib/avo/concerns/can_replace_items.rb
2175
2174
  - lib/avo/concerns/checks_assoc_authorization.rb
2176
2175
  - lib/avo/concerns/filters_session_handler.rb
@@ -1,29 +0,0 @@
1
- module Avo
2
- module Concerns
3
- module CanReorderItems
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- if defined? Avo::Pro::Concerns::CanReorderItems
8
- include Avo::Pro::Concerns::CanReorderItems
9
- end
10
- end
11
-
12
- def can_reorder?
13
- false
14
- end
15
-
16
- def can_dnd_reorder?
17
- false
18
- end
19
-
20
- def drag_reorder_attributes
21
- ""
22
- end
23
-
24
- def drag_reorder_item_attributes
25
- ""
26
- end
27
- end
28
- end
29
- end