avo 2.21.0 → 2.21.1.pre.issue1444

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.

Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/app/components/avo/empty_state_component.html.erb +1 -1
  4. data/app/components/avo/empty_state_component.rb +10 -12
  5. data/app/components/avo/fields/belongs_to_field/edit_component.rb +1 -1
  6. data/app/components/avo/fields/boolean_field/edit_component.html.erb +1 -1
  7. data/app/components/avo/fields/boolean_group_field/edit_component.html.erb +1 -1
  8. data/app/components/avo/fields/code_field/edit_component.html.erb +2 -2
  9. data/app/components/avo/fields/country_field/edit_component.html.erb +1 -1
  10. data/app/components/avo/fields/date_field/edit_component.html.erb +2 -2
  11. data/app/components/avo/fields/date_time_field/edit_component.html.erb +2 -2
  12. data/app/components/avo/fields/edit_component.rb +0 -4
  13. data/app/components/avo/fields/external_image_field/edit_component.html.erb +1 -1
  14. data/app/components/avo/fields/file_field/edit_component.html.erb +1 -1
  15. data/app/components/avo/fields/files_field/edit_component.html.erb +1 -1
  16. data/app/components/avo/fields/has_one_field/show_component.html.erb +3 -3
  17. data/app/components/avo/fields/markdown_field/edit_component.html.erb +1 -1
  18. data/app/components/avo/fields/markdown_field/show_component.html.erb +1 -1
  19. data/app/components/avo/fields/number_field/edit_component.html.erb +1 -1
  20. data/app/components/avo/fields/password_field/edit_component.html.erb +1 -1
  21. data/app/components/avo/fields/progress_bar_field/edit_component.html.erb +1 -1
  22. data/app/components/avo/fields/select_field/edit_component.html.erb +1 -1
  23. data/app/components/avo/fields/show_component.rb +0 -4
  24. data/app/components/avo/fields/status_field/edit_component.html.erb +1 -1
  25. data/app/components/avo/fields/tags_field/edit_component.html.erb +2 -2
  26. data/app/components/avo/fields/text_field/edit_component.html.erb +1 -1
  27. data/app/components/avo/fields/textarea_field/edit_component.html.erb +1 -1
  28. data/app/components/avo/fields/time_field/edit_component.html.erb +2 -2
  29. data/app/components/avo/fields/trix_field/edit_component.html.erb +2 -3
  30. data/app/components/avo/fields/trix_field/edit_component.rb +1 -5
  31. data/app/components/avo/index/resource_grid_component.html.erb +1 -1
  32. data/app/components/avo/index/resource_table_component.rb +3 -3
  33. data/app/components/avo/paginator_component.html.erb +5 -1
  34. data/app/components/avo/paginator_component.rb +0 -8
  35. data/app/components/avo/resource_component.rb +2 -17
  36. data/app/components/avo/views/resource_index_component.html.erb +1 -1
  37. data/app/controllers/avo/attachments_controller.rb +0 -4
  38. data/app/controllers/avo/base_controller.rb +2 -8
  39. data/app/controllers/avo/dashboards/cards_controller.rb +1 -1
  40. data/app/controllers/avo/search_controller.rb +5 -11
  41. data/app/javascript/js/controllers/fields/trix_field_controller.js +3 -6
  42. data/app/javascript/js/controllers/item_select_all_controller.js +4 -7
  43. data/app/views/avo/actions/show.html.erb +1 -1
  44. data/app/views/avo/base/_multiple_select_filter.html.erb +1 -1
  45. data/app/views/avo/partials/_resource_search.html.erb +1 -1
  46. data/config/i18n-tasks.yml +1 -1
  47. data/config/initializers/pagy.rb +0 -16
  48. data/config/master.key +1 -0
  49. data/lib/avo/base_action.rb +0 -8
  50. data/lib/avo/base_card.rb +2 -5
  51. data/lib/avo/base_resource.rb +2 -3
  52. data/lib/avo/concerns/handles_field_args.rb +1 -8
  53. data/lib/avo/fields/base_field.rb +1 -2
  54. data/lib/avo/fields/select_field.rb +1 -1
  55. data/lib/avo/services/authorization_service.rb +2 -2
  56. data/lib/avo/version.rb +1 -1
  57. data/lib/generators/avo/templates/field/components/edit_component.html.erb.tt +1 -1
  58. data/lib/generators/avo/templates/locales/avo.en.yml +2 -3
  59. data/lib/generators/avo/templates/locales/avo.fr.yml +2 -3
  60. data/lib/generators/avo/templates/locales/avo.nb.yml +2 -3
  61. data/lib/generators/avo/templates/locales/avo.nn.yml +2 -3
  62. data/lib/generators/avo/templates/locales/avo.pt-BR.yml +2 -3
  63. data/lib/generators/avo/templates/locales/avo.ro.yml +55 -56
  64. data/lib/generators/avo/templates/locales/avo.tr.yml +2 -3
  65. data/public/avo-assets/avo.base.js +2 -2
  66. data/public/avo-assets/avo.base.js.map +2 -2
  67. metadata +5 -9
  68. data/lib/avo/fields/concerns/is_disabled.rb +0 -19
  69. data/lib/avo/hosts/resource_record_host.rb +0 -7
  70. data/lib/generators/avo/templates/locales/avo.pt.yml +0 -120
  71. data/lib/generators/avo/templates/locales/pagy/nn.yml +0 -15
  72. data/lib/generators/avo/templates/locales/pagy/ro.yml +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 302280e8ea8c09012d0f68c72b017a8e903261346e02fdb8b4eaf2daa3160d39
4
- data.tar.gz: eef2ab4ee6fd1576311d85ef6ae91add6f655f9762e3cc736f39bbb2f039c31e
3
+ metadata.gz: 24cf9486da47ba10e6a5daa1580d555a14c87f9c642a5a8d56d69a9f47784f4e
4
+ data.tar.gz: e85a3b0a6bc76ba138b523601a64a74539559d919a4c984dc18a7361304527e1
5
5
  SHA512:
6
- metadata.gz: bdf810fecb08f2a6d8a157238b28df1141b396b1a62387a88bb6094d0ac4c39195d36c319751eb7dca1368ed6f5174a241a23279bf558ade568091ce201d65ae
7
- data.tar.gz: 983acf054fc7a5c8fd4f1f32b9f1a6c45e187d9c87f70a223203e8445f3d0ecd1d05eb80ac0fc02ec497604636a37a20d8ab8365a21477dbd9decc60ad1760f5
6
+ metadata.gz: 34db8a5f063bef99fd6a4cdb5cc72df589e1f0329286ec7f22653de5c96a47788a7c9ad82a7197b11acb90355f9c8f5fd4ba594bf29dace1613d74d31a520917
7
+ data.tar.gz: 05b2170b8af382365f157c31335b1f913f44a7d5117fe22a1cf6130200362b788812315604e7836570e384a1f2708d58625503aad2fcbbad3a738cb2163ba0f1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.21.0)
4
+ avo (2.21.1.pre.issue1444)
5
5
  actionview (>= 6.0)
6
6
  active_link_to
7
7
  activerecord (>= 6.0)
@@ -409,7 +409,7 @@ GEM
409
409
  tzinfo (2.0.5)
410
410
  concurrent-ruby (~> 1.0)
411
411
  unicode-display_width (2.2.0)
412
- view_component (2.78.0)
412
+ view_component (2.77.0)
413
413
  activesupport (>= 5.0.0, < 8.0)
414
414
  concurrent-ruby (~> 1.0)
415
415
  method_source (~> 1.0)
@@ -4,7 +4,7 @@
4
4
  <div class="relative flex-1 flex flex-col items-center justify-center space-y-12 py-24">
5
5
  <%= helpers.svg view_type_svg, class: 'h-[250px]' %>
6
6
  <div class="text-gray-500 text-center">
7
- <%= text %>
7
+ <%= message %>
8
8
  </div>
9
9
  </div>
10
10
  <% if @add_background %>
@@ -1,26 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Avo::EmptyStateComponent < ViewComponent::Base
4
- attr_reader :message, :view_type, :add_background, :by_association
5
-
6
- def initialize(message: nil, view_type: :table, add_background: false, by_association: false)
4
+ def initialize(message: nil, resource_name: nil, related_name: nil, view_type: :table, add_background: false)
7
5
  @message = message
8
6
  @view_type = view_type
7
+ @related_name = related_name
8
+ @resource_name = resource_name
9
9
  @add_background = add_background
10
- @by_association = by_association
11
10
  end
12
11
 
13
- def text
14
- message || locale_message
15
- end
12
+ def message
13
+ return @message if @message.present?
16
14
 
17
- def view_type_svg
18
- "#{view_type}-empty-state"
15
+ translation_tag = @related_name.present? ? 'avo.no_related_item_found' : 'avo.no_item_found'
16
+ helpers.t translation_tag, item: @resource_name
19
17
  end
20
18
 
21
- private
19
+ def view_type_svg
20
+ return "grid-empty-state" if @view_type.to_sym == :grid
22
21
 
23
- def locale_message
24
- helpers.t by_association ? 'avo.no_related_item_found' : 'avo.no_item_found'
22
+ "table-empty-state"
25
23
  end
26
24
  end
@@ -8,7 +8,7 @@ class Avo::Fields::BelongsToField::EditComponent < Avo::Fields::EditComponent
8
8
  end
9
9
 
10
10
  def disabled
11
- return true if @field.is_readonly? || @field.is_disabled?
11
+ return true if @field.is_readonly?
12
12
 
13
13
  # When visiting the record through it's association we keep the field disabled by default
14
14
  # We make an exception when the user deliberately instructs Avo to allow detaching in this scenario
@@ -4,7 +4,7 @@
4
4
  checked: @field.value,
5
5
  class: "text-lg h-4 w-4 checked:bg-primary-400 focus:checked:!bg-primary-400 #{@field.get_html(:classes, view: view, element: :input)}",
6
6
  data: @field.get_html(:data, view: view, element: :input),
7
- disabled: disabled?,
7
+ disabled: @field.is_readonly?,
8
8
  style: @field.get_html(:style, view: view, element: :input)
9
9
  %>
10
10
  </div>
@@ -20,7 +20,7 @@
20
20
  <%= check_box_tag "#{model_param_key}[#{@field.id}][]", id, checked, {
21
21
  class: "w-4 h-4 #{@field.get_html(:classes, view: view, element: :input)}",
22
22
  data: @field.get_html(:data, view: view, element: :input),
23
- disabled: disabled?,
23
+ disabled: @field.is_readonly?,
24
24
  id: "#{model_param_key}_#{@field.id}_#{id}",
25
25
  style: @field.get_html(:style, view: view, element: :input)
26
26
  } %> <%= label %>
@@ -8,12 +8,12 @@
8
8
  language: @field.language,
9
9
  theme: @field.theme,
10
10
  'tab-size': @field.tab_size,
11
- 'read-only': disabled?,
11
+ 'read-only': @field.is_readonly?,
12
12
  'indent-with-tabs': @field.indent_with_tabs,
13
13
  'line-wrapping': @field.line_wrapping,
14
14
  **@field.get_html(:data, view: view, element: :input),
15
15
  },
16
- disabled: disabled?,
16
+ disabled: @field.is_readonly?,
17
17
  placeholder: @field.placeholder,
18
18
  style: @field.get_html(:style, view: view, element: :input)
19
19
  %>
@@ -8,7 +8,7 @@
8
8
  },
9
9
  class: classes("w-full"),
10
10
  data: @field.get_html(:data, view: view, element: :input),
11
- disabled: disabled?,
11
+ disabled: @field.is_readonly?,
12
12
  style: @field.get_html(:style, view: view, element: :input),
13
13
  placeholder: @field.include_blank.present? ? nil : @field.placeholder
14
14
  %>
@@ -18,7 +18,7 @@
18
18
  placeholder: @field.placeholder,
19
19
  **@field.get_html(:data, view: view, element: :input)
20
20
  },
21
- disabled: disabled?,
21
+ disabled: @field.is_readonly?,
22
22
  placeholder: @field.placeholder,
23
23
  style: @field.get_html(:style, view: view, element: :input)
24
24
  %>
@@ -30,7 +30,7 @@
30
30
  placeholder: @field.placeholder,
31
31
  **@field.get_html(:data, view: view, element: :input)
32
32
  },
33
- disabled: disabled?,
33
+ disabled: @field.is_readonly?,
34
34
  placeholder: @field.placeholder,
35
35
  style: @field.get_html(:style, view: view, element: :input)
36
36
  %>
@@ -20,7 +20,7 @@
20
20
  placeholder: @field.placeholder,
21
21
  **@field.get_html(:data, view: view, element: :input)
22
22
  },
23
- disabled: disabled?,
23
+ disabled: @field.is_readonly?,
24
24
  placeholder: @field.placeholder,
25
25
  style: @field.get_html(:style, view: view, element: :input)
26
26
  %>
@@ -32,7 +32,7 @@
32
32
  placeholder: @field.placeholder,
33
33
  **@field.get_html(:data, view: view, element: :input)
34
34
  },
35
- disabled: disabled?,
35
+ disabled: @field.is_readonly?,
36
36
  placeholder: @field.placeholder,
37
37
  style: @field.get_html(:style, view: view, element: :input)
38
38
  %>
@@ -42,8 +42,4 @@ class Avo::Fields::EditComponent < ViewComponent::Base
42
42
  view: view
43
43
  }
44
44
  end
45
-
46
- def disabled?
47
- field.is_readonly? || field.is_disabled?
48
- end
49
45
  end
@@ -2,7 +2,7 @@
2
2
  <%= @form.text_field @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
5
- disabled: disabled?,
5
+ disabled: @field.is_readonly?,
6
6
  placeholder: @field.placeholder,
7
7
  style: @field.get_html(:style, view: view, element: :input)
8
8
  %>
@@ -10,7 +10,7 @@
10
10
  accept: @field.accept,
11
11
  data: @field.get_html(:data, view: view, element: :input),
12
12
  direct_upload: @field.direct_upload,
13
- disabled: disabled?,
13
+ disabled: @field.is_readonly?,
14
14
  style: @field.get_html(:style, view: view, element: :input),
15
15
  class: "w-full"
16
16
  %>
@@ -7,7 +7,7 @@
7
7
  accept: @field.accept,
8
8
  data: @field.get_html(:data, view: view, element: :input),
9
9
  direct_upload: @field.direct_upload,
10
- disabled: disabled?,
10
+ disabled: @field.is_readonly?,
11
11
  multiple: true,
12
12
  style: @field.get_html(:style, view: view, element: :input),
13
13
  class: "w-full"
@@ -5,7 +5,7 @@
5
5
  <% else %>
6
6
  <%= render Avo::PanelComponent.new(name: @field.name) do |c| %>
7
7
  <% c.tools do %>
8
- <% if !@field.is_readonly? && !@field.is_disabled? && can_attach? %>
8
+ <% if !@field.is_readonly? && can_attach? %>
9
9
  <%= a_link attach_path,
10
10
  icon: 'heroicons/outline/link',
11
11
  color: :primary,
@@ -13,7 +13,7 @@
13
13
  <%= t('avo.attach_item', item: @field.name.downcase) %>
14
14
  <% end %>
15
15
  <% end %>
16
- <% if !@field.is_readonly? && !@field.is_disabled? && can_see_the_create_button? %>
16
+ <% if !@field.is_readonly? && can_see_the_create_button? %>
17
17
  <%= a_link create_path,
18
18
  icon: 'heroicons/outline/plus',
19
19
  'data-target': 'create',
@@ -27,7 +27,7 @@
27
27
 
28
28
  <% c.body do %>
29
29
  <div class="py-8 flex justify-center items-center">
30
- <%= empty_state by_association: params[:related_name].present? %>
30
+ <%= empty_state resource_name: @field.id, related_name: params[:related_name] %>
31
31
  </div>
32
32
  <% end %>
33
33
  <% end %>
@@ -7,7 +7,7 @@
7
7
  'simple-mde-target': 'element',
8
8
  'component-options': @field.options.to_json,
9
9
  },
10
- disabled: disabled?,
10
+ disabled: @field.is_readonly?,
11
11
  placeholder: @field.placeholder,
12
12
  style: @field.get_html(:style, view: view, element: :input)
13
13
  %>
@@ -3,7 +3,7 @@
3
3
  <%= text_area_tag @field.id, @field.value,
4
4
  class: helpers.input_classes('w-full js-has-simple-mde-editor'),
5
5
  placeholder: @field.placeholder,
6
- disabled: disabled?,
6
+ disabled: @field.is_readonly?,
7
7
  'data-simple-mde-target': 'element',
8
8
  'data-component-options': @field.options.to_json,
9
9
  'data-view': :show %>
@@ -2,7 +2,7 @@
2
2
  <%= @form.number_field @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
5
- disabled: disabled?,
5
+ disabled: @field.is_readonly?,
6
6
  max: @field.max,
7
7
  min: @field.min,
8
8
  placeholder: @field.placeholder,
@@ -2,7 +2,7 @@
2
2
  <%= @form.password_field @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
5
- disabled: disabled?,
5
+ disabled: @field.is_readonly?,
6
6
  placeholder: @field.placeholder,
7
7
  style: @field.get_html(:style, view: view, element: :input)
8
8
  %>
@@ -7,7 +7,7 @@
7
7
  <%= @form.range_field @field.id,
8
8
  class: "w-full #{@field.get_html(:classes, view: view, element: :input)}",
9
9
  data: @field.get_html(:data, view: view, element: :input),
10
- disabled: disabled?,
10
+ disabled: @field.is_readonly?,
11
11
  max: @field.max,
12
12
  min: 0,
13
13
  placeholder: @field.placeholder,
@@ -7,7 +7,7 @@
7
7
  },
8
8
  class: classes("w-full"),
9
9
  data: @field.get_html(:data, view: view, element: :input),
10
- disabled: disabled?,
10
+ disabled: @field.is_readonly?,
11
11
  style: @field.get_html(:style, view: view, element: :input),
12
12
  value: @field.model.present? ? @field.model[@field.id] : @field.value,
13
13
  placeholder: @field.include_blank.present? ? nil : @field.placeholder
@@ -52,8 +52,4 @@ class Avo::Fields::ShowComponent < ViewComponent::Base
52
52
  view: view
53
53
  }
54
54
  end
55
-
56
- def disabled?
57
- field.is_readonly? || field.is_disabled?
58
- end
59
55
  end
@@ -2,7 +2,7 @@
2
2
  <%= @form.text_field @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
5
- disabled: disabled?,
5
+ disabled: @field.is_readonly?,
6
6
  placeholder: @field.placeholder,
7
7
  style: @field.get_html(:style, view: view, element: :input),
8
8
  value: @resource.model.present? ? @resource.model[@field.id] : @field.value
@@ -6,7 +6,7 @@
6
6
  data: {
7
7
  'tags-field-target': 'fakeInput',
8
8
  },
9
- disabled: disabled?,
9
+ disabled: @field.is_readonly?,
10
10
  placeholder: @field.placeholder,
11
11
  style: @field.get_html(:style, view: view, element: :input),
12
12
  value: ''
@@ -22,7 +22,7 @@
22
22
  'delimiters': @field.delimiters,
23
23
  'close-on-select': @field.close_on_select ? 1 : 0,
24
24
  },
25
- disabled: disabled?,
25
+ disabled: @field.is_readonly?,
26
26
  placeholder: @field.placeholder,
27
27
  style: @field.get_html(:style, view: view, element: :input),
28
28
  value: @field.field_value.to_json
@@ -2,7 +2,7 @@
2
2
  <%= form.text_field @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
5
- disabled: disabled?,
5
+ disabled: @field.is_readonly?,
6
6
  placeholder: @field.placeholder,
7
7
  style: @field.get_html(:style, view: view, element: :input),
8
8
  # value: @field.value,
@@ -2,7 +2,7 @@
2
2
  <%= @form.text_area @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
5
- disabled: disabled?,
5
+ disabled: @field.is_readonly?,
6
6
  placeholder: @field.placeholder,
7
7
  rows: @field.rows,
8
8
  style: @field.get_html(:style, view: view, element: :input)
@@ -20,7 +20,7 @@
20
20
  placeholder: @field.placeholder,
21
21
  **@field.get_html(:data, view: view, element: :input)
22
22
  },
23
- disabled: disabled?,
23
+ disabled: @field.is_readonly?,
24
24
  placeholder: @field.placeholder,
25
25
  style: @field.get_html(:style, view: view, element: :input)
26
26
  %>
@@ -32,7 +32,7 @@
32
32
  placeholder: @field.placeholder,
33
33
  **@field.get_html(:data, view: view, element: :input)
34
34
  },
35
- disabled: disabled?,
35
+ disabled: @field.is_readonly?,
36
36
  placeholder: @field.placeholder,
37
37
  style: @field.get_html(:style, view: view, element: :input)
38
38
  %>
@@ -1,6 +1,5 @@
1
1
  <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
- <%= content_tag :div,
3
- class: "relative block overflow-x-auto max-w-full",
2
+ <%= content_tag :div, class: "relative block overflow-x-auto max-w-full",
4
3
  data: {
5
4
  controller: "trix-field",
6
5
  trix_field_target: "controller",
@@ -25,7 +24,7 @@
25
24
  <%= @form.text_area @field.id,
26
25
  class: classes("w-full hidden"),
27
26
  data: @field.get_html(:data, view: view, element: :input),
28
- disabled: disabled?,
27
+ disabled: @field.is_readonly?,
29
28
  id: trix_id,
30
29
  placeholder: @field.placeholder,
31
30
  style: @field.get_html(:style, view: view, element: :input)
@@ -20,10 +20,6 @@ class Avo::Fields::TrixField::EditComponent < Avo::Fields::EditComponent
20
20
  end
21
21
 
22
22
  def trix_id
23
- if resource_name.present?
24
- "trix_#{resource_name}_#{@field.id}"
25
- elsif form.present?
26
- "trix_#{form.index}_#{@field.id}"
27
- end
23
+ "trix_#{resource_name}_#{@field.id}"
28
24
  end
29
25
  end
@@ -9,6 +9,6 @@
9
9
  </div>
10
10
  <% else %>
11
11
  <div class="bg-white rounded shadow-panel">
12
- <%= helpers.empty_state by_association: params[:related_name].present?, view_type: :grid %>
12
+ <%= helpers.empty_state resource_name: @resource.name.downcase.pluralize, related_name: params[:related_name], view_type: :grid %>
13
13
  </div>
14
14
  <% end %>
@@ -2,7 +2,7 @@
2
2
 
3
3
  class Avo::Index::ResourceTableComponent < ViewComponent::Base
4
4
  include Avo::ApplicationHelper
5
- attr_reader :pagy, :query
5
+ attr_reader :pagy
6
6
 
7
7
  def initialize(resources: nil, resource: nil, reflection: nil, parent_model: nil, parent_resource: nil, pagy: nil, query: nil)
8
8
  @resources = resources
@@ -15,10 +15,10 @@ class Avo::Index::ResourceTableComponent < ViewComponent::Base
15
15
  end
16
16
 
17
17
  def encrypted_query
18
- return :select_all_disabled if query.nil? || !query.respond_to?(:all) || !query.all.respond_to?(:to_sql)
18
+ return if @query.nil?
19
19
 
20
20
  Avo::Services::EncryptionService.encrypt(
21
- message: query.all.to_sql,
21
+ message: @query.all.to_sql,
22
22
  purpose: :select_all
23
23
  )
24
24
  end
@@ -25,7 +25,11 @@
25
25
  %> <%= t('avo.per_page').downcase %>
26
26
  </div>
27
27
  <% per_page_options.each do |option| %>
28
- <%= link_to "Change to #{option} items per page", change_items_per_page_url(option), class: 'hidden', 'data-per-page-option': option, 'data-turbo-frame': turbo_frame %>
28
+ <% if parent_model.present? %>
29
+ <%= link_to "Change to #{option} items per page", helpers.related_resources_path(parent_model, parent_model, per_page: option, keep_query_params: true, page: 1), class: 'hidden', 'data-per-page-option': option, 'data-turbo-frame': turbo_frame %>
30
+ <% else %>
31
+ <%= link_to "Change to #{option} items per page", helpers.resources_path(resource: resource, per_page: option, keep_query_params: true, page: 1), class: 'hidden', 'data-per-page-option': option, 'data-turbo-frame': turbo_frame %>
32
+ <% end %>
29
33
  <% end %>
30
34
  </div>
31
35
  </div>
@@ -16,12 +16,4 @@ class Avo::PaginatorComponent < ViewComponent::Base
16
16
  @parent_model = parent_model
17
17
  @discreet_pagination = discreet_pagination
18
18
  end
19
-
20
- def change_items_per_page_url(option)
21
- if parent_model.present?
22
- helpers.related_resources_path(parent_model, parent_model, per_page: option, keep_query_params: true, page: 1)
23
- else
24
- helpers.resources_path(resource: resource, per_page: option, keep_query_params: true, page: 1)
25
- end
26
- end
27
19
  end
@@ -53,7 +53,6 @@ class Avo::ResourceComponent < Avo::BaseComponent
53
53
  end
54
54
  end
55
55
 
56
- # Ex: A Post has many Comments
57
56
  def authorize_association_for(policy_method)
58
57
  policy_result = true
59
58
 
@@ -68,25 +67,11 @@ class Avo::ResourceComponent < Avo::BaseComponent
68
67
 
69
68
  if association_name.present?
70
69
  method_name = "#{policy_method}_#{association_name}?".to_sym
71
-
72
- # Use the policy methods from the parent (Post)
70
+ # Prepare the authorization service
73
71
  service = reflection_resource.authorization
74
72
 
75
73
  if service.has_method?(method_name, raise_exception: false)
76
- # Some policy methods should get the parent record in order to have the necessarry information to do the authorization
77
- # Example: Post->has_many->Comments
78
- # When you want to authorize the creation/attaching of a Comment, you don't have the Comment instance.
79
- # But you do have the Post instance and you can get that in your policy to authorize against.
80
- parent_policy_methods = [:view, :create, :attach, :act_on]
81
-
82
- record = if parent_policy_methods.include?(policy_method)
83
- # Use the parent record (Post)
84
- reflection_resource.model
85
- else
86
- # Override the record with the child record (Comment)
87
- resource.model
88
- end
89
- policy_result = service.authorize_action(method_name, record: record, raise_exception: false)
74
+ policy_result = service.authorize_action(method_name, raise_exception: false)
90
75
  end
91
76
  end
92
77
  end
@@ -52,7 +52,7 @@
52
52
  <%= render(Avo::Index::ResourceTableComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_model: @parent_model, parent_resource: @parent_resource, pagy: @pagy, query: @query)) %>
53
53
  </div>
54
54
  <% else %>
55
- <%= helpers.empty_state by_association: params[:related_name].present?, view_type: view_type, add_background: true %>
55
+ <%= helpers.empty_state resource_name: @resource.name.downcase.pluralize, related_name: params[:related_name], view_type: view_type, add_background: true %>
56
56
  <% end %>
57
57
  <% end %>
58
58
  <% end %>
@@ -10,10 +10,6 @@ module Avo
10
10
  blob = ActiveStorage::Blob.create_and_upload! io: params[:file], filename: params[:filename]
11
11
  association_name = BaseResource.valid_attachment_name(@model, params[:attachment_key])
12
12
 
13
- if association_name.blank?
14
- raise ActionController::BadRequest.new("Could not find the attachment association for #{params[:attachment_key]} (check the `attachment_key` for this Trix field)")
15
- end
16
-
17
13
  @model.send(association_name).attach blob
18
14
 
19
15
  render json: {
@@ -14,7 +14,6 @@ module Avo
14
14
  before_action :fill_model, only: [:create, :update]
15
15
  # Don't run base authorizations for associations
16
16
  before_action :authorize_base_action, if: -> { controller_name != "associations" }
17
- before_action :set_pagy_locale, only: :index
18
17
 
19
18
  def index
20
19
  @page_title = @resource.plural_name.humanize
@@ -224,11 +223,11 @@ module Avo
224
223
  # In case there's an error somewhere else than the model
225
224
  # Example: When you save a license that should create a user for it and creating that user throws and error.
226
225
  # Example: When you Try to delete a record and has a foreign key constraint.
227
- exception_message = exception.message
226
+ @errors = Array.wrap(exception.message)
228
227
  end
229
228
 
230
229
  # Add the errors from the model
231
- @errors = @model.errors.full_messages.reject { |error| exception_message.include? error }.unshift exception_message
230
+ @errors = Array.wrap([@errors, @model.errors.full_messages]).compact
232
231
 
233
232
  succeeded
234
233
  end
@@ -511,10 +510,5 @@ module Avo
511
510
  def is_associated_record?
512
511
  params[:via_relation_class].present? && params[:via_resource_id].present?
513
512
  end
514
-
515
- # Set pagy locale from params or from avo configuration, if both nil locale = "en"
516
- def set_pagy_locale
517
- @pagy_locale = locale.to_s || Avo.configuration.locale || "en"
518
- end
519
513
  end
520
514
  end
@@ -21,7 +21,7 @@ module Avo
21
21
 
22
22
  def set_card
23
23
  @card = @dashboard.item_at_index(params[:index].to_i).tap do |card|
24
- card.hydrate(dashboard: @dashboard)
24
+ card.hydrate(dashboard: @dashboard, params: params)
25
25
  end
26
26
  end
27
27
 
@@ -44,33 +44,27 @@ module Avo
44
44
  end
45
45
 
46
46
  def search_resource(resource)
47
- query = Avo::Hosts::SearchScopeHost.new(
47
+ query = Avo::Hosts::SearchScopeHost.new(
48
48
  block: resource.search_query,
49
49
  params: params,
50
- scope: resource.class.scope
50
+ scope: resource.class.scope.limit(8)
51
51
  ).handle
52
52
 
53
- # Get the count
54
- results_count = query.count
55
-
56
- # Get the results
57
- query = query.limit(8)
58
-
59
53
  query = apply_scope(query) if should_apply_any_scope?
60
54
 
61
55
  results = apply_search_metadata(query, resource)
62
56
 
63
57
  header = resource.plural_name
64
58
 
65
- if results_count > 0
66
- header = "#{header} (#{results_count})"
59
+ if results.length > 0
60
+ header += " (#{results.length})"
67
61
  end
68
62
 
69
63
  result_object = {
70
64
  header: header,
71
65
  help: resource.class.search_query_help,
72
66
  results: results,
73
- count: results_count
67
+ count: results.length
74
68
  }
75
69
 
76
70
  [resource.name.pluralize.downcase, result_object]
@@ -55,7 +55,7 @@ export default class extends Controller {
55
55
  }
56
56
 
57
57
  // Prevent file uploads for resources that haven't been saved yet.
58
- if (!this.resourceId) {
58
+ if (this.resourceId === '') {
59
59
  event.preventDefault()
60
60
  alert("You can't upload files into the Trix editor until you save the resource.")
61
61
 
@@ -63,7 +63,7 @@ export default class extends Controller {
63
63
  }
64
64
 
65
65
  // Prevent file uploads for fields without an attachment key.
66
- if (!this.attachmentKey) {
66
+ if (this.attachmentKey === '') {
67
67
  event.preventDefault()
68
68
  alert("You haven't set an `attachment_key` to this Trix field.")
69
69
  }
@@ -93,10 +93,7 @@ export default class extends Controller {
93
93
 
94
94
  xhr.open('POST', this.uploadUrl, true)
95
95
 
96
- const csrfToken = document.querySelector('meta[name="csrf-token"]')?.content
97
- if (csrfToken) {
98
- xhr.setRequestHeader('X-CSRF-Token', csrfToken)
99
- }
96
+ xhr.setRequestHeader('X-CSRF-Token', document.querySelector('meta[name="csrf-token"]').content)
100
97
 
101
98
  xhr.upload.addEventListener('progress', (event) => {
102
99
  // eslint-disable-next-line no-mixed-operators