avo 2.7.0 → 2.9.0

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 (174) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +6 -4
  4. data/README.md +11 -0
  5. data/app/assets/stylesheets/avo.css +4 -4
  6. data/app/assets/stylesheets/css/{components → fields}/code.css +0 -0
  7. data/app/assets/stylesheets/css/{components → fields}/progress.css +0 -0
  8. data/app/assets/stylesheets/css/{components → fields}/status.css +0 -0
  9. data/app/assets/stylesheets/css/fields/trix.css +17 -0
  10. data/app/assets/svgs/download-solid-reversed.svg +2 -2
  11. data/app/components/avo/actions_component.html.erb +5 -13
  12. data/app/components/avo/actions_component.rb +39 -1
  13. data/app/components/avo/alert_component.rb +6 -0
  14. data/app/components/avo/card_component.html.erb +2 -2
  15. data/app/components/avo/common_field_wrapper_component.html.erb +11 -4
  16. data/app/components/avo/common_field_wrapper_component.rb +27 -1
  17. data/app/components/avo/edit/field_wrapper_component.html.erb +1 -1
  18. data/app/components/avo/fields/badge_field/index_component.html.erb +1 -1
  19. data/app/components/avo/fields/badge_field/show_component.html.erb +1 -1
  20. data/app/components/avo/fields/belongs_to_field/autocomplete_component.html.erb +21 -10
  21. data/app/components/avo/fields/belongs_to_field/autocomplete_component.rb +7 -1
  22. data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +27 -15
  23. data/app/components/avo/fields/belongs_to_field/edit_component.rb +4 -0
  24. data/app/components/avo/fields/belongs_to_field/index_component.html.erb +1 -1
  25. data/app/components/avo/fields/belongs_to_field/show_component.html.erb +1 -1
  26. data/app/components/avo/fields/boolean_field/edit_component.html.erb +4 -2
  27. data/app/components/avo/fields/boolean_field/index_component.html.erb +1 -1
  28. data/app/components/avo/fields/boolean_field/show_component.html.erb +1 -1
  29. data/app/components/avo/fields/boolean_group_field/edit_component.html.erb +7 -1
  30. data/app/components/avo/fields/boolean_group_field/index_component.html.erb +1 -1
  31. data/app/components/avo/fields/boolean_group_field/show_component.html.erb +1 -1
  32. data/app/components/avo/fields/code_field/edit_component.html.erb +7 -5
  33. data/app/components/avo/fields/code_field/show_component.html.erb +2 -2
  34. data/app/components/avo/fields/common/key_value_component.html.erb +10 -4
  35. data/app/components/avo/fields/common/key_value_component.rb +2 -0
  36. data/app/components/avo/fields/country_field/edit_component.html.erb +4 -2
  37. data/app/components/avo/fields/country_field/index_component.html.erb +1 -1
  38. data/app/components/avo/fields/country_field/show_component.html.erb +1 -1
  39. data/app/components/avo/fields/date_field/edit_component.html.erb +6 -4
  40. data/app/components/avo/fields/date_field/index_component.html.erb +1 -1
  41. data/app/components/avo/fields/date_field/show_component.html.erb +1 -1
  42. data/app/components/avo/fields/date_time_field/edit_component.html.erb +6 -4
  43. data/app/components/avo/fields/date_time_field/index_component.html.erb +1 -1
  44. data/app/components/avo/fields/date_time_field/show_component.html.erb +1 -1
  45. data/app/components/avo/fields/edit_component.rb +7 -0
  46. data/app/components/avo/fields/external_image_field/edit_component.html.erb +5 -2
  47. data/app/components/avo/fields/external_image_field/index_component.html.erb +6 -4
  48. data/app/components/avo/fields/external_image_field/show_component.html.erb +1 -1
  49. data/app/components/avo/fields/file_field/edit_component.html.erb +6 -1
  50. data/app/components/avo/fields/file_field/index_component.html.erb +1 -1
  51. data/app/components/avo/fields/file_field/show_component.html.erb +1 -1
  52. data/app/components/avo/fields/files_field/edit_component.html.erb +7 -1
  53. data/app/components/avo/fields/files_field/index_component.html.erb +1 -1
  54. data/app/components/avo/fields/files_field/show_component.html.erb +1 -1
  55. data/app/components/avo/fields/gravatar_field/index_component.html.erb +1 -1
  56. data/app/components/avo/fields/gravatar_field/show_component.html.erb +1 -1
  57. data/app/components/avo/fields/has_one_field/index_component.html.erb +1 -1
  58. data/app/components/avo/fields/hidden_field/edit_component.html.erb +5 -1
  59. data/app/components/avo/fields/id_field/edit_component.html.erb +1 -1
  60. data/app/components/avo/fields/id_field/index_component.html.erb +1 -1
  61. data/app/components/avo/fields/id_field/show_component.html.erb +1 -1
  62. data/app/components/avo/fields/index_component.rb +3 -0
  63. data/app/components/avo/fields/key_value_field/edit_component.html.erb +1 -1
  64. data/app/components/avo/fields/key_value_field/show_component.html.erb +1 -1
  65. data/app/components/avo/fields/markdown_field/edit_component.html.erb +8 -5
  66. data/app/components/avo/fields/markdown_field/show_component.html.erb +1 -1
  67. data/app/components/avo/fields/number_field/edit_component.html.erb +7 -4
  68. data/app/components/avo/fields/number_field/index_component.html.erb +1 -1
  69. data/app/components/avo/fields/number_field/show_component.html.erb +1 -1
  70. data/app/components/avo/fields/password_field/edit_component.html.erb +4 -2
  71. data/app/components/avo/fields/progress_bar_field/edit_component.html.erb +7 -4
  72. data/app/components/avo/fields/progress_bar_field/index_component.html.erb +1 -1
  73. data/app/components/avo/fields/progress_bar_field/show_component.html.erb +1 -1
  74. data/app/components/avo/fields/select_field/edit_component.html.erb +9 -3
  75. data/app/components/avo/fields/select_field/index_component.html.erb +1 -1
  76. data/app/components/avo/fields/select_field/show_component.html.erb +1 -1
  77. data/app/components/avo/fields/show_component.rb +3 -0
  78. data/app/components/avo/fields/status_field/edit_component.html.erb +6 -3
  79. data/app/components/avo/fields/status_field/index_component.html.erb +1 -1
  80. data/app/components/avo/fields/status_field/show_component.html.erb +1 -1
  81. data/app/components/avo/fields/tags_field/edit_component.html.erb +19 -11
  82. data/app/components/avo/fields/tags_field/index_component.html.erb +1 -1
  83. data/app/components/avo/fields/tags_field/show_component.html.erb +1 -1
  84. data/app/components/avo/fields/text_field/edit_component.html.erb +5 -2
  85. data/app/components/avo/fields/text_field/index_component.html.erb +1 -1
  86. data/app/components/avo/fields/text_field/show_component.html.erb +1 -1
  87. data/app/components/avo/fields/textarea_field/edit_component.html.erb +6 -3
  88. data/app/components/avo/fields/textarea_field/show_component.html.erb +1 -1
  89. data/app/components/avo/fields/trix_field/edit_component.html.erb +14 -4
  90. data/app/components/avo/fields/trix_field/edit_component.rb +3 -0
  91. data/app/components/avo/fields/trix_field/show_component.html.erb +2 -2
  92. data/app/components/avo/index/field_wrapper_component.html.erb +12 -5
  93. data/app/components/avo/index/field_wrapper_component.rb +27 -3
  94. data/app/components/avo/panel_component.rb +4 -3
  95. data/app/components/avo/resource_component.rb +1 -0
  96. data/app/components/avo/show/field_wrapper_component.html.erb +1 -1
  97. data/app/components/avo/show/field_wrapper_component.rb +2 -1
  98. data/app/components/avo/sidebar/item_switcher_component.html.erb +2 -2
  99. data/app/components/avo/views/resource_edit_component.html.erb +13 -8
  100. data/app/components/avo/views/resource_edit_component.rb +32 -3
  101. data/app/components/avo/views/resource_index_component.html.erb +7 -4
  102. data/app/components/avo/views/resource_index_component.rb +7 -1
  103. data/app/components/avo/views/resource_show_component.html.erb +11 -9
  104. data/app/components/avo/views/resource_show_component.rb +1 -0
  105. data/app/controllers/avo/actions_controller.rb +4 -1
  106. data/app/controllers/avo/base_controller.rb +24 -13
  107. data/app/controllers/avo/cards_controller.rb +25 -0
  108. data/app/controllers/avo/dashboards_controller.rb +2 -8
  109. data/app/controllers/avo/home_controller.rb +8 -1
  110. data/app/controllers/avo/search_controller.rb +7 -1
  111. data/app/helpers/avo/url_helpers.rb +8 -9
  112. data/app/javascript/js/controllers/fields/code_field_controller.js +7 -1
  113. data/app/javascript/js/controllers/fields/key_value_controller.js +1 -0
  114. data/app/javascript/js/controllers/fields/tags_field_controller.js +0 -1
  115. data/app/javascript/js/controllers/menu_controller.js +4 -3
  116. data/app/javascript/js/controllers/resource_edit_controller.js +72 -0
  117. data/app/javascript/js/controllers/resource_index_controller.js +4 -0
  118. data/app/javascript/js/controllers/resource_show_controller.js +4 -0
  119. data/app/javascript/js/controllers/search_controller.js +28 -5
  120. data/app/javascript/js/controllers.js +8 -0
  121. data/app/views/avo/associations/new.html.erb +2 -1
  122. data/app/views/avo/base/_select_filter.html.erb +1 -1
  123. data/app/views/avo/base/_text_filter.html.erb +1 -0
  124. data/app/views/avo/base/edit.html.erb +2 -1
  125. data/app/views/avo/base/new.html.erb +1 -1
  126. data/app/views/avo/{dashboards → cards}/_chartkick_card.html.erb +0 -0
  127. data/app/views/avo/{dashboards → cards}/_metric_card.html.erb +0 -0
  128. data/app/views/avo/{dashboards/card.html.erb → cards/show.html.erb} +0 -0
  129. data/app/views/avo/partials/_custom_tools_alert.html.erb +21 -7
  130. data/app/views/avo/partials/_logo.html.erb +3 -2
  131. data/app/views/avo/partials/_navbar.html.erb +1 -1
  132. data/app/views/avo/partials/_table_header.html.erb +9 -1
  133. data/bin/test +1 -0
  134. data/config/routes.rb +7 -4
  135. data/db/factories.rb +1 -0
  136. data/lib/avo/app.rb +18 -1
  137. data/lib/avo/base_action.rb +16 -4
  138. data/lib/avo/base_card.rb +0 -23
  139. data/lib/avo/base_resource.rb +23 -16
  140. data/lib/avo/concerns/fetches_things.rb +19 -12
  141. data/lib/avo/concerns/has_fields.rb +93 -0
  142. data/lib/avo/concerns/has_html_attributes.rb +110 -0
  143. data/lib/avo/concerns/has_model.rb +11 -0
  144. data/lib/avo/concerns/has_stimulus_controllers.rb +42 -0
  145. data/lib/avo/dynamic_router.rb +1 -1
  146. data/lib/avo/engine.rb +1 -3
  147. data/lib/avo/fields/base_field.rb +24 -13
  148. data/lib/avo/fields/concerns/is_required.rb +17 -0
  149. data/lib/avo/fields/select_field.rb +1 -1
  150. data/lib/avo/grid_collector.rb +4 -4
  151. data/lib/avo/hosts/view_record_host.rb +7 -0
  152. data/lib/avo/html/builder.rb +117 -0
  153. data/lib/avo/licensing/pro_license.rb +1 -0
  154. data/lib/avo/menu/base_item.rb +4 -0
  155. data/lib/avo/menu/dashboard.rb +5 -0
  156. data/lib/avo/menu/resource.rb +5 -0
  157. data/lib/avo/version.rb +1 -1
  158. data/lib/avo.rb +5 -0
  159. data/lib/generators/avo/install_generator.rb +1 -4
  160. data/lib/generators/avo/templates/cards/chartkick_card_sample.tt +11 -1
  161. data/lib/generators/avo/templates/cards/metric_card_sample.tt +11 -1
  162. data/lib/generators/avo/templates/field/components/edit_component.html.erb.tt +1 -1
  163. data/lib/generators/avo/templates/field/components/index_component.html.erb.tt +1 -1
  164. data/lib/generators/avo/templates/field/components/show_component.html.erb.tt +1 -1
  165. data/lib/generators/avo/templates/initializer/avo.tt +1 -1
  166. data/lib/generators/avo/templates/locales/avo.en.yml +3 -3
  167. data/public/avo-assets/avo.css +473 -1055
  168. data/public/avo-assets/avo.js +147 -147
  169. data/public/avo-assets/avo.js.map +3 -3
  170. data/public/avo-assets/logomark.png +0 -0
  171. metadata +21 -11
  172. data/app/components/avo/views/resource_new_component.html.erb +0 -55
  173. data/app/components/avo/views/resource_new_component.rb +0 -38
  174. data/lib/avo/fields_collector.rb +0 -70
@@ -38,16 +38,22 @@
38
38
  value: @field.parsed_value,
39
39
  class: 'hidden',
40
40
  placeholder: @field.placeholder,
41
- 'data-key-value-target': 'input',
42
- 'data-view': :edit
41
+ data: {
42
+ "key-value-target": 'input',
43
+ view: @view,
44
+ **@field.get_html(:data, view: view, element: :input)
45
+ }
43
46
  %>
44
47
  <% else %>
45
48
  <%= text_area_tag @field.id,
46
49
  @field.parsed_value,
47
50
  class: 'hidden',
48
51
  placeholder: @field.placeholder,
49
- 'data-key-value-target': 'input',
50
- 'data-view': :edit
52
+ data: {
53
+ "key-value-target": 'input',
54
+ view: @view,
55
+ **@field.get_html(:data, view: view, element: :input)
56
+ }
51
57
  %>
52
58
  <% end %>
53
59
  </div>
@@ -3,6 +3,8 @@
3
3
  class Avo::Fields::Common::KeyValueComponent < ViewComponent::Base
4
4
  include Avo::ApplicationHelper
5
5
 
6
+ attr_reader :view
7
+
6
8
  def initialize(field:, form: nil, view: :show)
7
9
  @field = field
8
10
  @form = form
@@ -1,7 +1,9 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.select @field.id, @field.select_options, { selected: @field.value, prompt: @field.placeholder },
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
+ disabled: @field.readonly,
4
6
  placeholder: @field.placeholder,
5
- disabled: @field.readonly
7
+ style: @field.get_html(:style, view: view, element: :input)
6
8
  %>
7
9
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <% if @field.display_code %>
3
3
  <%= @field.value %>
4
4
  <% else %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <% if @field.display_code %>
3
3
  <%= @field.value %>
4
4
  <% else %>
@@ -1,9 +1,7 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <div data-controller="date-field">
3
3
  <%= @form.date_field @field.id,
4
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
5
- placeholder: @field.placeholder,
6
- disabled: @field.readonly,
4
+ class: classes("w-full"),
7
5
  data: {
8
6
  'date-field-target': 'input',
9
7
  'first-day-of-week': @field.first_day_of_week,
@@ -12,7 +10,11 @@
12
10
  format: @field.format,
13
11
  placeholder: @field.placeholder,
14
12
  relative: @field.relative,
15
- }
13
+ **@field.get_html(:data, view: view, element: :input)
14
+ },
15
+ disabled: @field.readonly,
16
+ placeholder: @field.placeholder,
17
+ style: @field.get_html(:style, view: view, element: :input)
16
18
  %>
17
19
  </div>
18
20
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= @field.formatted_value %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= @field.formatted_value %>
3
3
  <% end %>
@@ -1,9 +1,7 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <div data-controller="date-field">
3
3
  <%= @form.datetime_field @field.id,
4
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
5
- placeholder: @field.placeholder,
6
- disabled: @field.readonly,
4
+ class: classes("w-full"),
7
5
  data: {
8
6
  'date-field-target': 'input',
9
7
  'first-day-of-week': @field.first_day_of_week,
@@ -14,7 +12,11 @@
14
12
  format: @field.format,
15
13
  placeholder: @field.placeholder,
16
14
  relative: @field.relative,
17
- }
15
+ **@field.get_html(:data, view: view, element: :input)
16
+ },
17
+ disabled: @field.readonly,
18
+ placeholder: @field.placeholder,
19
+ style: @field.get_html(:style, view: view, element: :input)
18
20
  %>
19
21
  </div>
20
22
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= @field.formatted_value %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= @field.formatted_value %>
3
3
  <% end %>
@@ -3,11 +3,18 @@
3
3
  class Avo::Fields::EditComponent < ViewComponent::Base
4
4
  include Avo::ResourcesHelper
5
5
 
6
+ attr_reader :view
7
+
6
8
  def initialize(field: nil, resource: nil, index: 0, form: nil, displayed_in_modal: false)
7
9
  @field = field
8
10
  @resource = resource
9
11
  @index = index
10
12
  @form = form
11
13
  @displayed_in_modal = displayed_in_modal
14
+ @view = :edit
15
+ end
16
+
17
+ def classes(extra_classes = "")
18
+ helpers.input_classes("#{@field.get_html(:classes, view: view, element: :input)} #{extra_classes}", has_error: @field.model_errors.include?(@field.id))
12
19
  end
13
20
  end
@@ -1,6 +1,9 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.text_field @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
+ disabled: @field.readonly,
4
6
  placeholder: @field.placeholder,
5
- disabled: @field.readonly %>
7
+ style: @field.get_html(:style, view: view, element: :input)
8
+ %>
6
9
  <% end %>
@@ -1,8 +1,10 @@
1
- <%= index_field_wrapper field: @field, flush: true do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, flush: true do %>
2
2
  <% if @field.value.present? %>
3
- <%= image_tag @field.value,
4
- height: @field.height,
5
- style: "border-radius: #{@field.radius}px; max-height: #{@field.height}#{@field.height.to_s&.ends_with?('px') ? '' : 'px'};"
3
+ <%= link_to_if @field.link_to_resource.present?,
4
+ image_tag(@field.value,
5
+ height: @field.height,
6
+ style: "border-radius: #{@field.radius}px; max-height: #{@field.height}#{@field.height.to_s&.ends_with?('px') ? '' : 'px'};"),
7
+ resource_path
6
8
  %>
7
9
  <% end %>
8
10
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource do %>
2
2
  <% if @field.value.present? %>
3
3
  <%= image_tag @field.value, style: 'max-width: 340px;' %>
4
4
  <% end %>
@@ -6,6 +6,11 @@
6
6
  <% end %>
7
7
 
8
8
  <% if @resource.authorization.authorize_action(:upload_attachments?, raise_exception: false) %>
9
- <%= @form.file_field @field.id, disabled: @field.readonly, direct_upload: @field.direct_upload %>
9
+ <%= @form.file_field @field.id,
10
+ data: @field.get_html(:data, view: view, element: :input),
11
+ direct_upload: @field.direct_upload,
12
+ disabled: @field.readonly,
13
+ style: @field.get_html(:style, view: view, element: :input)
14
+ %>
10
15
  <% end %>
11
16
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= index_field_wrapper field: @field, flush: flush? do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, flush: flush? do %>
2
2
  <% if @field.value.present? %>
3
3
  <% if @field.value.attached? && @field.value.representable? && @field.is_image %>
4
4
  <%= link_to_if @field.link_to_resource, image_tag(helpers.main_app.url_for(@field.value), class: 'h-10'), resource_path, class: 'block' %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= render Avo::Fields::Common::SingleFileViewerComponent.new resource: @resource, field: @field %>
3
3
  <% end %>
@@ -3,7 +3,13 @@
3
3
 
4
4
  <% if @resource.authorization.authorize_action(:upload_attachments?, raise_exception: false) %>
5
5
  <div class="mt-2">
6
- <%= @form.file_field @field.id, disabled: @field.readonly, multiple: true, direct_upload: @field.direct_upload %>
6
+ <%= @form.file_field @field.id,
7
+ data: @field.get_html(:data, view: view, element: :input),
8
+ direct_upload: @field.direct_upload,
9
+ disabled: @field.readonly,
10
+ multiple: true,
11
+ style: @field.get_html(:style, view: view, element: :input)
12
+ %>
7
13
  </div>
8
14
  <% end %>
9
15
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= @field.value.attachments.length %> files
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, full_width: true do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, 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
- <%= index_field_wrapper field: @field, flush: true do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, flush: true do %>
2
2
  <%= render Avo::Fields::Common::GravatarViewerComponent.new(
3
3
  md5: @field.md5,
4
4
  default: @field.default,
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= render Avo::Fields::Common::GravatarViewerComponent.new(
3
3
  md5: @field.md5,
4
4
  default: @field.default,
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= link_to @field.label, helpers.resource_path(model: @field.value, resource: @field.target_resource) %>
3
3
  <% end %>
@@ -1 +1,5 @@
1
- <%= @form.hidden_field @field.id %>
1
+ <%= @form.hidden_field @field.id,
2
+ class: @field.get_html(:classes, view: view, element: :input),
3
+ data: @field.get_html(:data, view: view, element: :input),
4
+ style: @field.get_html(:style, view: view, element: :input)
5
+ %>
@@ -1,3 +1,3 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
- <%= field.value %>
2
+ <%= @field.value %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field, class: 'whitespace-no-wrap w-[1%]' do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, class: 'whitespace-no-wrap w-[1%]' do %>
2
2
  <% link_to_if (@field.link_to_resource or Avo.configuration.id_links_to_resource), @field.value, resource_path, title: t('avo.view_item', item: @resource.name).humanize %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -3,11 +3,14 @@
3
3
  class Avo::Fields::IndexComponent < ViewComponent::Base
4
4
  include Avo::ResourcesHelper
5
5
 
6
+ attr_reader :view
7
+
6
8
  def initialize(field: nil, resource: nil, index: 0, parent_model: nil)
7
9
  @field = field
8
10
  @resource = resource
9
11
  @index = index
10
12
  @parent_model = parent_model
13
+ @view = :index
11
14
  end
12
15
 
13
16
  def resource_path
@@ -1,3 +1,3 @@
1
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: :edit %>
2
+ <%= render Avo::Fields::Common::KeyValueComponent.new field: @field, form: @form, view: @resource.view %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index, full_width: true do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index, full_width: true do %>
2
2
  <%= render Avo::Fields::Common::KeyValueComponent.new field: @field, view: :show %>
3
3
  <% end %>
@@ -1,12 +1,15 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal, full_width: true do %>
2
2
  <div data-controller="simple-mde">
3
3
  <%= @form.text_area @field.id,
4
- class: helpers.input_classes('w-full js-has-simple-mde-editor', has_error: @field.model_errors.include?(@field.id)),
5
- placeholder: @field.placeholder,
4
+ class: classes("w-full js-has-simple-mde-editor"),
5
+ data: {
6
+ view: @resource.view,
7
+ 'simple-mde-target': 'element',
8
+ 'component-options': @field.options.to_json,
9
+ },
6
10
  disabled: @field.readonly,
7
- 'data-simple-mde-target': 'element',
8
- 'data-component-options': @field.options.to_json,
9
- 'data-view': :edit
11
+ placeholder: @field.placeholder,
12
+ style: @field.get_html(:style, view: view, element: :input)
10
13
  %>
11
14
  </div>
12
15
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index, full_width: true do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index, 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,9 +1,12 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.number_field @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
4
- placeholder: @field.placeholder,
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
5
  disabled: @field.readonly,
6
- min: @field.min,
7
6
  max: @field.max,
8
- step: @field.step %>
7
+ min: @field.min,
8
+ placeholder: @field.placeholder,
9
+ step: @field.step,
10
+ style: @field.get_html(:style, view: view, element: :input)
11
+ %>
9
12
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= @field.value %>
3
3
  <% end %>
@@ -1,7 +1,9 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.password_field @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
+ disabled: @field.readonly,
4
6
  placeholder: @field.placeholder,
5
- disabled: @field.readonly
7
+ style: @field.get_html(:style, view: view, element: :input)
6
8
  %>
7
9
  <% end %>
@@ -5,12 +5,15 @@
5
5
  </div>
6
6
  <% end %>
7
7
  <%= @form.range_field @field.id,
8
- min: 0,
8
+ class: "w-full #{@field.get_html(:classes, view: view, element: :input)}",
9
+ data: @field.get_html(:data, view: view, element: :input),
10
+ disabled: @field.readonly,
9
11
  max: @field.max,
10
- step: @field.step,
11
- class: 'w-full',
12
+ min: 0,
12
13
  placeholder: @field.placeholder,
13
- disabled: @field.readonly %>
14
+ step: @field.step,
15
+ style: @field.get_html(:style, view: view, element: :input)
16
+ %>
14
17
  <% end %>
15
18
 
16
19
 
@@ -1,4 +1,4 @@
1
- <%= index_field_wrapper field: @field, flush: true do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, flush: true 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
  <%= @field.value %><%= @field.value_suffix if @field.value_suffix.present? %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index 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
  <%= @field.value %><%= @field.value_suffix if @field.value_suffix.present? %>
@@ -1,6 +1,12 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.select @field.id, @field.options_for_select, { selected: @field.value, prompt: @field.placeholder }, {
3
- class: helpers.input_classes(' w-full', has_error: @field.model_errors.include?(@field.id)),
4
- disabled: @field.readonly,
5
- value: @field.model.present? ? @field.model[@field.id] : @field.value } %>
3
+ aria: {
4
+ placeholder: @field.placeholder
5
+ },
6
+ class: classes("w-full"),
7
+ data: @field.get_html(:data, view: view, element: :input),
8
+ disabled: @field.readonly,
9
+ style: @field.get_html(:style, view: view, element: :input),
10
+ value: @field.model.present? ? @field.model[@field.id] : @field.value
11
+ } %>
6
12
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= @field.label %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= @field.label %>
3
3
  <% end %>
@@ -3,9 +3,12 @@
3
3
  class Avo::Fields::ShowComponent < ViewComponent::Base
4
4
  include Avo::ResourcesHelper
5
5
 
6
+ attr_reader :view
7
+
6
8
  def initialize(field: nil, resource: nil, index: 0)
7
9
  @field = field
8
10
  @resource = resource
9
11
  @index = index
12
+ @view = :show
10
13
  end
11
14
  end
@@ -1,7 +1,10 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.text_field @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
4
- placeholder: @field.placeholder,
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
5
  disabled: @field.readonly,
6
- value: @resource.model.present? ? @resource.model[@field.id] : @field.value %>
6
+ placeholder: @field.placeholder,
7
+ style: @field.get_html(:style, view: view, element: :input),
8
+ value: @resource.model.present? ? @resource.model[@field.id] : @field.value
9
+ %>
7
10
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <%= render Avo::Fields::Common::StatusViewerComponent.new label: @field.value, status: @field.status %>
3
3
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= render Avo::Fields::Common::StatusViewerComponent.new label: @field.value, status: @field.status %>
3
3
  <% end %>
@@ -1,20 +1,23 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= edit_field_wrapper field: @field,
2
+ index: @index,
3
+ form: @form,
4
+ resource: @resource,
5
+ displayed_in_modal: @displayed_in_modal do %>
2
6
  <div data-controller="tags-field">
3
7
  <%# dummy field %>
4
8
  <%= text_field_tag "#{@field.id}-dummy", '',
5
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
6
- placeholder: @field.placeholder,
7
- disabled: @field.readonly,
8
- value: '',
9
+ class: classes("w-full"),
9
10
  data: {
10
11
  'tags-field-target': 'fakeInput',
11
- } %>
12
+ },
13
+ disabled: @field.readonly,
14
+ placeholder: @field.placeholder,
15
+ style: @field.get_html(:style, view: view, element: :input),
16
+ value: ''
17
+ %>
12
18
  <%# real field %>
13
19
  <%= @form.text_field @field.id,
14
- class: helpers.input_classes('hidden w-full', has_error: @field.model_errors.include?(@field.id)),
15
- placeholder: @field.placeholder,
16
- disabled: @field.readonly,
17
- value: @field.field_value.to_json,
20
+ class: classes("hidden w-full"),
18
21
  data: {
19
22
  'tags-field-target': 'input',
20
23
  'whitelist-items': @field.suggestions.to_json,
@@ -22,6 +25,11 @@
22
25
  'enforce-suggestions': @field.enforce_suggestions ? 1 : 0,
23
26
  'delimiters': @field.delimiters,
24
27
  'close-on-select': @field.close_on_select ? 1 : 0,
25
- } %>
28
+ },
29
+ disabled: @field.readonly,
30
+ placeholder: @field.placeholder,
31
+ style: @field.get_html(:style, view: view, element: :input),
32
+ value: @field.field_value.to_json
33
+ %>
26
34
  </div>
27
35
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= index_field_wrapper field: @field, flush: true do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource, flush: true do %>
2
2
  <div class="flex gap-1 items-center flex-nowrap">
3
3
  <% value.take(3).each do |item| %>
4
4
  <%= render Avo::Fields::TagsField::TagComponent.new(label: label_from_item(item)) %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index 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,6 +1,9 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.text_field @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
+ disabled: @field.readonly,
4
6
  placeholder: @field.placeholder,
5
- disabled: @field.readonly %>
7
+ style: @field.get_html(:style, view: view, element: :input)
8
+ %>
6
9
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= index_field_wrapper field: @field do %>
1
+ <%= index_field_wrapper field: @field, resource: @resource do %>
2
2
  <% if @field.as_html %>
3
3
  <%== @field.value %>
4
4
  <% else %>
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <% if @field.as_html %>
3
3
  <%== @field.value %>
4
4
  <% else %>
@@ -1,7 +1,10 @@
1
1
  <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
2
2
  <%= @form.text_area @field.id,
3
- class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
4
- placeholder: @field.placeholder,
3
+ class: classes("w-full"),
4
+ data: @field.get_html(:data, view: view, element: :input),
5
5
  disabled: @field.readonly,
6
- rows: @field.rows %>
6
+ placeholder: @field.placeholder,
7
+ rows: @field.rows,
8
+ style: @field.get_html(:style, view: view, element: :input)
9
+ %>
7
10
  <% end %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, index: @index do %>
1
+ <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
2
2
  <%= @field.value %>
3
3
  <% end %>