avo 2.16.0 → 2.16.1.pre.1.nativefields

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 (84) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -2
  3. data/Gemfile.lock +78 -86
  4. data/app/components/avo/base_component.rb +7 -1
  5. data/app/components/avo/field_wrapper_component.html.erb +40 -0
  6. data/app/components/avo/field_wrapper_component.rb +102 -0
  7. data/app/components/avo/fields/badge_field/show_component.html.erb +1 -1
  8. data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +3 -3
  9. data/app/components/avo/fields/belongs_to_field/show_component.html.erb +1 -1
  10. data/app/components/avo/fields/boolean_field/edit_component.html.erb +1 -1
  11. data/app/components/avo/fields/boolean_field/show_component.html.erb +1 -1
  12. data/app/components/avo/fields/boolean_group_field/edit_component.html.erb +1 -1
  13. data/app/components/avo/fields/boolean_group_field/show_component.html.erb +1 -1
  14. data/app/components/avo/fields/code_field/edit_component.html.erb +2 -2
  15. data/app/components/avo/fields/code_field/show_component.html.erb +2 -2
  16. data/app/components/avo/fields/country_field/edit_component.html.erb +1 -1
  17. data/app/components/avo/fields/country_field/show_component.html.erb +1 -1
  18. data/app/components/avo/fields/date_field/edit_component.html.erb +1 -1
  19. data/app/components/avo/fields/date_field/show_component.html.erb +1 -1
  20. data/app/components/avo/fields/date_time_field/edit_component.html.erb +1 -1
  21. data/app/components/avo/fields/date_time_field/show_component.html.erb +1 -1
  22. data/app/components/avo/fields/edit_component.rb +22 -4
  23. data/app/components/avo/fields/external_image_field/edit_component.html.erb +1 -1
  24. data/app/components/avo/fields/external_image_field/show_component.html.erb +1 -1
  25. data/app/components/avo/fields/file_field/edit_component.html.erb +1 -1
  26. data/app/components/avo/fields/file_field/show_component.html.erb +1 -1
  27. data/app/components/avo/fields/files_field/edit_component.html.erb +1 -1
  28. data/app/components/avo/fields/files_field/show_component.html.erb +1 -1
  29. data/app/components/avo/fields/gravatar_field/show_component.html.erb +1 -1
  30. data/app/components/avo/fields/id_field/edit_component.html.erb +1 -1
  31. data/app/components/avo/fields/id_field/show_component.html.erb +1 -1
  32. data/app/components/avo/fields/key_value_field/edit_component.html.erb +2 -2
  33. data/app/components/avo/fields/key_value_field/show_component.html.erb +1 -1
  34. data/app/components/avo/fields/markdown_field/edit_component.html.erb +2 -2
  35. data/app/components/avo/fields/markdown_field/show_component.html.erb +1 -1
  36. data/app/components/avo/fields/number_field/edit_component.html.erb +1 -1
  37. data/app/components/avo/fields/number_field/show_component.html.erb +1 -1
  38. data/app/components/avo/fields/password_field/edit_component.html.erb +1 -1
  39. data/app/components/avo/fields/progress_bar_field/edit_component.html.erb +1 -1
  40. data/app/components/avo/fields/progress_bar_field/show_component.html.erb +1 -1
  41. data/app/components/avo/fields/select_field/edit_component.html.erb +1 -2
  42. data/app/components/avo/fields/select_field/show_component.html.erb +1 -1
  43. data/app/components/avo/fields/show_component.rb +36 -1
  44. data/app/components/avo/fields/status_field/edit_component.html.erb +1 -1
  45. data/app/components/avo/fields/status_field/show_component.html.erb +1 -1
  46. data/app/components/avo/fields/tags_field/edit_component.html.erb +1 -5
  47. data/app/components/avo/fields/tags_field/show_component.html.erb +1 -1
  48. data/app/components/avo/fields/text_field/edit_component.html.erb +2 -2
  49. data/app/components/avo/fields/text_field/show_component.html.erb +1 -1
  50. data/app/components/avo/fields/textarea_field/edit_component.html.erb +1 -1
  51. data/app/components/avo/fields/textarea_field/show_component.html.erb +1 -1
  52. data/app/components/avo/fields/trix_field/edit_component.html.erb +2 -2
  53. data/app/components/avo/fields/trix_field/edit_component.rb +19 -1
  54. data/app/components/avo/fields/trix_field/show_component.html.erb +1 -1
  55. data/app/components/avo/index/resource_controls_component.rb +1 -0
  56. data/app/components/avo/views/resource_edit_component.html.erb +28 -26
  57. data/app/controllers/avo/application_controller.rb +8 -1
  58. data/app/controllers/avo/base_controller.rb +5 -5
  59. data/app/helpers/avo/application_helper.rb +31 -3
  60. data/app/helpers/avo/resources_helper.rb +4 -8
  61. data/app/javascript/js/controllers/action_controller.js +3 -1
  62. data/app/javascript/js/controllers/fields/date_field_controller.js +21 -1
  63. data/app/javascript/js/controllers/search_controller.js +122 -118
  64. data/avo.gemspec +1 -1
  65. data/config/master.key +1 -0
  66. data/lib/avo/base_resource.rb +5 -3
  67. data/lib/avo/concerns/fetches_things.rb +2 -0
  68. data/lib/avo/fields/base_field.rb +4 -0
  69. data/lib/avo/fields/select_field.rb +1 -0
  70. data/lib/avo/menu/menu.rb +2 -0
  71. data/lib/avo/services/authorization_service.rb +24 -20
  72. data/lib/avo/version.rb +1 -1
  73. data/lib/generators/avo/templates/field/components/edit_component.html.erb.tt +1 -1
  74. data/lib/generators/avo/templates/field/components/show_component.html.erb.tt +1 -1
  75. data/public/avo-assets/avo.base.css +26 -8
  76. data/public/avo-assets/avo.base.js +79 -79
  77. data/public/avo-assets/avo.base.js.map +3 -3
  78. metadata +8 -11
  79. data/app/components/avo/common_field_wrapper_component.html.erb +0 -26
  80. data/app/components/avo/common_field_wrapper_component.rb +0 -46
  81. data/app/components/avo/edit/field_wrapper_component.html.erb +0 -11
  82. data/app/components/avo/edit/field_wrapper_component.rb +0 -21
  83. data/app/components/avo/show/field_wrapper_component.html.erb +0 -9
  84. data/app/components/avo/show/field_wrapper_component.rb +0 -12
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= content_tag :div, data: {
3
3
  controller: "date-field",
4
4
  date_field_view_value: @view,
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= content_tag :div, data: {
3
3
  controller: "date-field",
4
4
  date_field_view_value: @view,
@@ -3,15 +3,21 @@
3
3
  class Avo::Fields::EditComponent < ViewComponent::Base
4
4
  include Avo::ResourcesHelper
5
5
 
6
+ attr_reader :compact
7
+ attr_reader :displayed_in_modal
6
8
  attr_reader :field
9
+ attr_reader :form
10
+ attr_reader :index
11
+ attr_reader :resource
7
12
  attr_reader :view
8
13
 
9
- def initialize(field: nil, resource: nil, index: 0, form: nil, displayed_in_modal: false)
14
+ def initialize(field: nil, resource: nil, index: 0, form: nil, displayed_in_modal: false, compact: false, **kwargs)
15
+ @compact = compact
16
+ @displayed_in_modal = displayed_in_modal
10
17
  @field = field
11
- @resource = resource
12
- @index = index
13
18
  @form = form
14
- @displayed_in_modal = displayed_in_modal
19
+ @index = index
20
+ @resource = resource
15
21
  @view = :edit
16
22
  end
17
23
 
@@ -22,4 +28,16 @@ class Avo::Fields::EditComponent < ViewComponent::Base
22
28
  def render?
23
29
  !field.computed
24
30
  end
31
+
32
+ def field_wrapper_args
33
+ {
34
+ compact: compact,
35
+ displayed_in_modal: displayed_in_modal,
36
+ field: field,
37
+ form: form,
38
+ index: index,
39
+ resource: resource,
40
+ view: view
41
+ }
42
+ end
25
43
  end
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @form.text_field @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, resource: @resource do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <% if @field.value.present? %>
3
3
  <%= image_tag @field.value, style: 'max-width: 340px;' %>
4
4
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <% if @field.value.present? %>
3
3
  <div class="mb-2">
4
4
  <%= render Avo::Fields::Common::SingleFileViewerComponent.new resource: @resource, field: @field %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= render Avo::Fields::Common::SingleFileViewerComponent.new resource: @resource, field: @field %>
3
3
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal, full_width: true do %>
1
+ <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
2
  <%= render Avo::Fields::Common::FilesListViewerComponent.new(field: @field, resource: @resource) if @field.value.present? %>
3
3
 
4
4
  <% if @resource.authorization.authorize_action(:upload_attachments?, raise_exception: false) %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, full_width: true do %>
1
+ <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
2
  <%= render Avo::Fields::Common::FilesListViewerComponent.new(field: @field, resource: @resource) if @field.value.present? %>
3
3
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= render Avo::Fields::Common::GravatarViewerComponent.new(
3
3
  md5: @field.md5,
4
4
  default: @field.default,
@@ -1,3 +1,3 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal, full_width: true do %>
2
- <%= render Avo::Fields::Common::KeyValueComponent.new field: @field, form: @form, view: @resource.view %>
1
+ <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
+ <%= render Avo::Fields::Common::KeyValueComponent.new field: @field, form: @form, view: view %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index, full_width: true do %>
1
+ <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
2
  <%= render Avo::Fields::Common::KeyValueComponent.new field: @field, view: :show %>
3
3
  <% end %>
@@ -1,9 +1,9 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal, full_width: true do %>
1
+ <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
2
  <div data-controller="simple-mde">
3
3
  <%= @form.text_area @field.id,
4
4
  class: classes("w-full js-has-simple-mde-editor"),
5
5
  data: {
6
- view: @resource.view,
6
+ view: view,
7
7
  'simple-mde-target': 'element',
8
8
  'component-options': @field.options.to_json,
9
9
  },
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index, full_width: true do %>
1
+ <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
2
  <div data-controller="simple-mde">
3
3
  <%= text_area_tag @field.id, @field.value,
4
4
  class: helpers.input_classes('w-full js-has-simple-mde-editor'),
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @form.number_field @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @form.password_field @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <% if @field.display_value %>
3
3
  <div class="text-center text-sm font-semibold w-full leading-none mb-1">
4
4
  <span class="js-progress-bar-value-<%= @field.id %>"><%= @field.value %></span><%= @field.value_suffix if @field.value_suffix.present? %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= render Avo::Fields::Common::ProgressBarComponent.new value: @field.value, display_value: @field.display_value, value_suffix: @field.value_suffix, max: @field.max, view: view %>
3
3
  <% end %>
@@ -1,6 +1,5 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @form.select @field.id, @field.options_for_select, {
3
- selected: @field.value,
4
3
  include_blank: @field.include_blank
5
4
  },
6
5
  aria: {
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @field.label %>
3
3
  <% end %>
@@ -3,12 +3,47 @@
3
3
  class Avo::Fields::ShowComponent < ViewComponent::Base
4
4
  include Avo::ResourcesHelper
5
5
 
6
+ attr_reader :field
7
+ attr_reader :index
8
+ attr_reader :resource
6
9
  attr_reader :view
7
10
 
8
11
  def initialize(field: nil, resource: nil, index: 0, form: nil)
9
12
  @field = field
10
- @resource = resource
11
13
  @index = index
14
+ @resource = resource
12
15
  @view = :show
13
16
  end
17
+
18
+ def wrapper_data
19
+ {
20
+ **stimulus_attributes
21
+ }
22
+ end
23
+
24
+ def stimulus_attributes
25
+ attributes = {}
26
+
27
+ if @resource.present?
28
+ @resource.get_stimulus_controllers.split(" ").each do |controller|
29
+ attributes["#{controller}-target"] = "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
30
+ end
31
+ end
32
+
33
+ wrapper_data_attributes = @field.get_html :data, view: view, element: :wrapper
34
+ if wrapper_data_attributes.present?
35
+ attributes.merge! wrapper_data_attributes
36
+ end
37
+
38
+ attributes
39
+ end
40
+
41
+ def field_wrapper_args
42
+ {
43
+ field: field,
44
+ index: index,
45
+ resource: resource,
46
+ view: view
47
+ }
48
+ end
14
49
  end
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @form.text_field @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= render Avo::Fields::Common::StatusViewerComponent.new label: @field.value, status: @field.status %>
3
3
  <% end %>
@@ -1,8 +1,4 @@
1
- <%= edit_field_wrapper field: @field,
2
- index: @index,
3
- form: @form,
4
- resource: @resource,
5
- displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
6
2
  <div data-controller="tags-field">
7
3
  <%# dummy field %>
8
4
  <%= text_field_tag "#{@field.id}-dummy", '',
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <div class="flex gap-1 items-center flex-wrap">
3
3
  <% @field.field_value.each do |item| %>
4
4
  <%= render Avo::Fields::TagsField::TagComponent.new(label: label_from_item(item)) %>
@@ -1,5 +1,5 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
- <%= @form.text_field @field.id,
1
+ <%= field_wrapper **field_wrapper_args do %>
2
+ <%= form.text_field @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
5
5
  disabled: @field.is_readonly?,
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <% if @field.as_html %>
3
3
  <%== @field.value %>
4
4
  <% elsif @field.protocol.present? %>
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @form.text_area @field.id,
3
3
  class: classes("w-full"),
4
4
  data: @field.get_html(:data, view: view, element: :input),
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -3,8 +3,8 @@
3
3
  data: {
4
4
  controller: "trix-field",
5
5
  trix_field_target: "controller",
6
- resource_name: @resource.model_key,
7
- resource_id: @resource.model.methods.include?(:id) ? @resource.model&.id : nil,
6
+ resource_name: resource_name,
7
+ resource_id: resource_id,
8
8
  attachments_disabled: @field.attachments_disabled,
9
9
  attachment_key: @field.attachment_key,
10
10
  hide_attachment_filename: @field.hide_attachment_filename,
@@ -1,7 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Avo::Fields::TrixField::EditComponent < Avo::Fields::EditComponent
4
+ attr_reader :resource
5
+
6
+ def initialize(**args)
7
+ @resource = args[:resource]
8
+ @resource_id = args[:resource_id]
9
+ @resource_name = args[:resource_name]
10
+
11
+ super(**args)
12
+ end
13
+
14
+ def resource_name
15
+ @resource_name || resource&.singular_route_key
16
+ end
17
+
18
+ def resource_id
19
+ @resource_id || resource&.model&.id
20
+ end
21
+
4
22
  def trix_id
5
- "trix_#{@resource.class_name_without_resource.underscore}_#{@field.id}"
23
+ "trix_#{resource_name}_#{@field.id}"
6
24
  end
7
25
  end
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%
3
3
  content_classes = 'trix-content py-2'
4
4
  content_classes << ' hidden' unless @field.always_show
@@ -67,6 +67,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
67
67
  end
68
68
 
69
69
  def parent_resource
70
+ return @parent_resource if @parent_resource.present?
70
71
  return nil if @parent_model.blank?
71
72
 
72
73
  ::Avo::App.get_resource_by_model_name @parent_model.class
@@ -15,9 +15,10 @@
15
15
  },
16
16
  multipart: true do |form| %>
17
17
  <%= render Avo::ReferrerParamsComponent.new back_path: back_path %>
18
- <%= render Avo::PanelComponent.new(name: title, description: @resource.resource_description, display_breadcrumbs: @reflection.blank?, index: 0, data: { panel_id: "main" }) do |c| %>
19
- <% c.tools do %>
20
- <%= a_link back_path,
18
+ <%= content_tag :div, class: 'space-y-12' do %>
19
+ <%= render Avo::PanelComponent.new(name: title, description: @resource.resource_description, display_breadcrumbs: @reflection.blank?, index: 0, data: { panel_id: "main" }) do |c| %>
20
+ <% c.tools do %>
21
+ <%= a_link back_path,
21
22
  style: :text,
22
23
  icon: 'arrow-left' do %>
23
24
  <%= t('avo.cancel').capitalize %>
@@ -44,10 +45,10 @@
44
45
  <% end %>
45
46
  <% if can_see_the_save_button? %>
46
47
  <%= a_button color: :primary,
47
- style: :primary,
48
- loading: true,
49
- type: :submit,
50
- icon: 'save' do %>
48
+ style: :primary,
49
+ loading: true,
50
+ type: :submit,
51
+ icon: 'save' do %>
51
52
  <%= t('avo.save').capitalize %>
52
53
  <% end %>
53
54
  <% end %>
@@ -62,35 +63,36 @@
62
63
  .component_for_view(view_for field)
63
64
  .new(field: field, resource: @resource, index: index, form: form)
64
65
  %>
65
- <% end %>
66
- </div>
66
+ <% end %>
67
+ </div>
68
+ <% end %>
67
69
  <% end %>
68
- <% end %>
69
- <% if Avo.configuration.buttons_on_form_footers %>
70
- <% c.footer_tools do %>
71
- <div class="mt-4">
72
- <%= a_link back_path,
70
+ <% if Avo.configuration.buttons_on_form_footers %>
71
+ <% c.footer_tools do %>
72
+ <div class="mt-4">
73
+ <%= a_link back_path,
73
74
  style: :text,
74
75
  icon: 'arrow-left' do %>
75
- <%= t('avo.cancel').capitalize %>
76
- <% end %>
77
- <% if can_see_the_save_button? %>
78
- <%= a_button color: :primary,
76
+ <%= t('avo.cancel').capitalize %>
77
+ <% end %>
78
+ <% if can_see_the_save_button? %>
79
+ <%= a_button color: :primary,
79
80
  style: :primary,
80
81
  loading: true,
81
82
  type: :submit,
82
83
  icon: 'save' do %>
83
- <%= t('avo.save').capitalize %>
84
+ <%= t('avo.save').capitalize %>
85
+ <% end %>
84
86
  <% end %>
85
- <% end %>
86
- </div>
87
+ </div>
88
+ <% end %>
87
89
  <% end %>
88
90
  <% end %>
89
- <% end %>
90
- <%= content_tag :div, class: 'space-y-12 mt-12' do %>
91
- <% @resource.get_items.each_with_index do |item, index| %>
92
- <% next if item.nil? %>
93
- <%= render Avo::ItemSwitcherComponent.new resource: @resource, item: item, index: index + 1, view: @view, form: form %>
91
+ <%= content_tag :div, class: 'space-y-12' do %>
92
+ <% @resource.get_items.each_with_index do |item, index| %>
93
+ <% next if item.nil? %>
94
+ <%= render Avo::ItemSwitcherComponent.new resource: @resource, item: item, index: index + 1, view: @view, form: form %>
95
+ <% end %>
94
96
  <% end %>
95
97
  <% end %>
96
98
  <% end %>
@@ -16,6 +16,7 @@ module Avo
16
16
  before_action :set_default_locale, if: -> { params[:set_locale].present? }
17
17
  before_action :init_app
18
18
  before_action :check_avo_license
19
+ before_action :set_resource_name
19
20
  before_action :set_authorization
20
21
  before_action :_authenticate!
21
22
  before_action :set_container_classes
@@ -269,7 +270,13 @@ module Avo
269
270
  end
270
271
 
271
272
  def set_authorization
272
- @authorization = Services::AuthorizationService.new _current_user
273
+ # We need to set @resource_name for the #resource method to work properly
274
+ set_resource_name
275
+ @authorization = if resource
276
+ resource.authorization(user: _current_user)
277
+ else
278
+ Services::AuthorizationService.new _current_user
279
+ end
273
280
  end
274
281
 
275
282
  def set_container_classes
@@ -84,7 +84,7 @@ module Avo
84
84
 
85
85
  # If we're accessing this resource via another resource add the parent to the breadcrumbs.
86
86
  if params[:via_resource_class].present? && params[:via_resource_id].present?
87
- via_resource = Avo::App.get_resource_by_model_name params[:via_resource_class]
87
+ via_resource = Avo::App.get_resource_by_model_name(params[:via_resource_class]).dup
88
88
  via_model = via_resource.class.find_scope.find params[:via_resource_id]
89
89
  via_resource.hydrate model: via_model
90
90
 
@@ -107,7 +107,7 @@ module Avo
107
107
  @page_title = @resource.default_panel_name.to_s
108
108
 
109
109
  if is_associated_record?
110
- via_resource = Avo::App.get_resource_by_model_name params[:via_relation_class]
110
+ via_resource = Avo::App.get_resource_by_model_name(params[:via_relation_class]).dup
111
111
  via_model = via_resource.class.find_scope.find params[:via_resource_id]
112
112
  via_resource.hydrate model: via_model
113
113
 
@@ -139,7 +139,7 @@ module Avo
139
139
  # For when working with has_one, has_one_through, has_many_through, has_and_belongs_to_many, polymorphic
140
140
  if @reflection.is_a? ActiveRecord::Reflection::ThroughReflection
141
141
  # find the record
142
- via_resource = ::Avo::App.get_resource_by_model_name params[:via_relation_class]
142
+ via_resource = ::Avo::App.get_resource_by_model_name(params[:via_relation_class]).dup
143
143
  @related_record = via_resource.model_class.find params[:via_resource_id]
144
144
 
145
145
  @model.send(params[:via_relation]) << @related_record
@@ -370,7 +370,7 @@ module Avo
370
370
  last_crumb_args = {}
371
371
  # If we're accessing this resource via another resource add the parent to the breadcrumbs.
372
372
  if params[:via_resource_class].present? && params[:via_resource_id].present?
373
- via_resource = Avo::App.get_resource_by_model_name params[:via_resource_class]
373
+ via_resource = Avo::App.get_resource_by_model_name(params[:via_resource_class]).dup
374
374
  via_model = via_resource.class.find_scope.find params[:via_resource_id]
375
375
  via_resource.hydrate model: via_model
376
376
 
@@ -413,7 +413,7 @@ module Avo
413
413
  def after_create_path
414
414
  # If this is an associated record return to the association show page
415
415
  if is_associated_record?
416
- parent_resource = ::Avo::App.get_resource_by_model_name params[:via_relation_class]
416
+ parent_resource = ::Avo::App.get_resource_by_model_name(params[:via_relation_class]).dup
417
417
 
418
418
  return resource_view_path(
419
419
  model: @model.send(params[:via_relation]),
@@ -17,18 +17,18 @@ module Avo
17
17
  end
18
18
 
19
19
  def empty_state(**args)
20
- render Avo::EmptyStateComponent.new **args
20
+ render Avo::EmptyStateComponent.new(**args)
21
21
  end
22
22
 
23
23
  def a_button(**args, &block)
24
24
  render Avo::ButtonComponent.new(is_link: false, **args) do
25
- capture(&block) if block_given?
25
+ capture(&block) if block
26
26
  end
27
27
  end
28
28
 
29
29
  def a_link(path = nil, **args, &block)
30
30
  render Avo::ButtonComponent.new(path, is_link: true, **args) do
31
- capture(&block) if block_given?
31
+ capture(&block) if block
32
32
  end
33
33
  end
34
34
 
@@ -114,5 +114,33 @@ module Avo
114
114
 
115
115
  output
116
116
  end
117
+
118
+ def avo_field(type = nil, id = nil, as: nil, view: :show, form: nil, component_options: {}, **args, &block)
119
+ if as.present?
120
+ id = type
121
+ type = as
122
+ end
123
+ field_klass = "Avo::Fields::#{type.to_s.camelize}Field".safe_constantize
124
+ field = field_klass.new id, form: form, view: view, **args, &block
125
+
126
+ # Add the form record to the field so all fields have access to it.
127
+ field.hydrate(model: form.object)
128
+
129
+ render field.component_for_view(view).new field: field, form: form, **component_options
130
+ end
131
+
132
+ def avo_show_field(id, type = nil, view: :show, **args, &block)
133
+ avo_field(id, type, **args, view: view, &block)
134
+ end
135
+
136
+ def avo_edit_field(id, type = nil, view: :edit, **args, &block)
137
+ avo_field(id, type, **args, view: view, &block)
138
+ end
139
+
140
+ def field_container(**args, &block)
141
+ classes = args[:class] || ""
142
+ classes << "flex flex-col divide-y"
143
+ content_tag :div, **args, class: classes, &block
144
+ end
117
145
  end
118
146
  end
@@ -20,17 +20,13 @@ module Avo
20
20
  end
21
21
  end
22
22
 
23
- def show_field_wrapper(**args, &block)
24
- render Show::FieldWrapperComponent.new(**args) do
25
- capture(&block)
26
- end
27
- end
28
-
29
- def edit_field_wrapper(**args, &block)
30
- render Edit::FieldWrapperComponent.new(**args) do
23
+ def field_wrapper(**args, &block)
24
+ render Avo::FieldWrapperComponent.new(**args) do
31
25
  capture(&block)
32
26
  end
33
27
  end
28
+ alias :edit_field_wrapper :field_wrapper
29
+ alias :show_field_wrapper :field_wrapper
34
30
 
35
31
  def filter_wrapper(name: nil, index: nil, **args, &block)
36
32
  render layout: "layouts/avo/filter_wrapper", locals: {
@@ -1,5 +1,5 @@
1
- import { Controller } from '@hotwired/stimulus'
2
1
  import { castBoolean } from '../helpers/cast_boolean'
2
+ import { Controller } from '@hotwired/stimulus'
3
3
 
4
4
  export default class extends Controller {
5
5
  static targets = ['controllerDiv', 'resourceIds', 'form', 'selectedAllQuery']
@@ -7,6 +7,8 @@ export default class extends Controller {
7
7
  connect() {
8
8
  this.resourceIdsTarget.value = this.resourceIds
9
9
 
10
+ console.log('something')
11
+
10
12
  // This value is picked up from the DOM so we check true/false as strings
11
13
  if (this.selectionOptions.itemSelectAllSelectedAllValue === 'true') {
12
14
  this.selectedAllQueryTarget.value = this.selectionOptions.itemSelectAllSelectedAllQueryValue