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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +6 -4
- data/README.md +11 -0
- data/app/assets/stylesheets/avo.css +4 -4
- data/app/assets/stylesheets/css/{components → fields}/code.css +0 -0
- data/app/assets/stylesheets/css/{components → fields}/progress.css +0 -0
- data/app/assets/stylesheets/css/{components → fields}/status.css +0 -0
- data/app/assets/stylesheets/css/fields/trix.css +17 -0
- data/app/assets/svgs/download-solid-reversed.svg +2 -2
- data/app/components/avo/actions_component.html.erb +5 -13
- data/app/components/avo/actions_component.rb +39 -1
- data/app/components/avo/alert_component.rb +6 -0
- data/app/components/avo/card_component.html.erb +2 -2
- data/app/components/avo/common_field_wrapper_component.html.erb +11 -4
- data/app/components/avo/common_field_wrapper_component.rb +27 -1
- data/app/components/avo/edit/field_wrapper_component.html.erb +1 -1
- data/app/components/avo/fields/badge_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/badge_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/belongs_to_field/autocomplete_component.html.erb +21 -10
- data/app/components/avo/fields/belongs_to_field/autocomplete_component.rb +7 -1
- data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +27 -15
- data/app/components/avo/fields/belongs_to_field/edit_component.rb +4 -0
- data/app/components/avo/fields/belongs_to_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/belongs_to_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/boolean_field/edit_component.html.erb +4 -2
- data/app/components/avo/fields/boolean_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/boolean_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/boolean_group_field/edit_component.html.erb +7 -1
- data/app/components/avo/fields/boolean_group_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/boolean_group_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/code_field/edit_component.html.erb +7 -5
- data/app/components/avo/fields/code_field/show_component.html.erb +2 -2
- data/app/components/avo/fields/common/key_value_component.html.erb +10 -4
- data/app/components/avo/fields/common/key_value_component.rb +2 -0
- data/app/components/avo/fields/country_field/edit_component.html.erb +4 -2
- data/app/components/avo/fields/country_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/country_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/date_field/edit_component.html.erb +6 -4
- data/app/components/avo/fields/date_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/date_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/date_time_field/edit_component.html.erb +6 -4
- data/app/components/avo/fields/date_time_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/date_time_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/edit_component.rb +7 -0
- data/app/components/avo/fields/external_image_field/edit_component.html.erb +5 -2
- data/app/components/avo/fields/external_image_field/index_component.html.erb +6 -4
- data/app/components/avo/fields/external_image_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/file_field/edit_component.html.erb +6 -1
- data/app/components/avo/fields/file_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/file_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/files_field/edit_component.html.erb +7 -1
- data/app/components/avo/fields/files_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/files_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/gravatar_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/gravatar_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/has_one_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/hidden_field/edit_component.html.erb +5 -1
- data/app/components/avo/fields/id_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/id_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/id_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/index_component.rb +3 -0
- data/app/components/avo/fields/key_value_field/edit_component.html.erb +1 -1
- data/app/components/avo/fields/key_value_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/markdown_field/edit_component.html.erb +8 -5
- data/app/components/avo/fields/markdown_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/number_field/edit_component.html.erb +7 -4
- data/app/components/avo/fields/number_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/number_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/password_field/edit_component.html.erb +4 -2
- data/app/components/avo/fields/progress_bar_field/edit_component.html.erb +7 -4
- data/app/components/avo/fields/progress_bar_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/progress_bar_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/select_field/edit_component.html.erb +9 -3
- data/app/components/avo/fields/select_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/select_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/show_component.rb +3 -0
- data/app/components/avo/fields/status_field/edit_component.html.erb +6 -3
- data/app/components/avo/fields/status_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/status_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/tags_field/edit_component.html.erb +19 -11
- data/app/components/avo/fields/tags_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/tags_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/text_field/edit_component.html.erb +5 -2
- data/app/components/avo/fields/text_field/index_component.html.erb +1 -1
- data/app/components/avo/fields/text_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/textarea_field/edit_component.html.erb +6 -3
- data/app/components/avo/fields/textarea_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/trix_field/edit_component.html.erb +14 -4
- data/app/components/avo/fields/trix_field/edit_component.rb +3 -0
- data/app/components/avo/fields/trix_field/show_component.html.erb +2 -2
- data/app/components/avo/index/field_wrapper_component.html.erb +12 -5
- data/app/components/avo/index/field_wrapper_component.rb +27 -3
- data/app/components/avo/panel_component.rb +4 -3
- data/app/components/avo/resource_component.rb +1 -0
- data/app/components/avo/show/field_wrapper_component.html.erb +1 -1
- data/app/components/avo/show/field_wrapper_component.rb +2 -1
- data/app/components/avo/sidebar/item_switcher_component.html.erb +2 -2
- data/app/components/avo/views/resource_edit_component.html.erb +13 -8
- data/app/components/avo/views/resource_edit_component.rb +32 -3
- data/app/components/avo/views/resource_index_component.html.erb +7 -4
- data/app/components/avo/views/resource_index_component.rb +7 -1
- data/app/components/avo/views/resource_show_component.html.erb +11 -9
- data/app/components/avo/views/resource_show_component.rb +1 -0
- data/app/controllers/avo/actions_controller.rb +4 -1
- data/app/controllers/avo/base_controller.rb +24 -13
- data/app/controllers/avo/cards_controller.rb +25 -0
- data/app/controllers/avo/dashboards_controller.rb +2 -8
- data/app/controllers/avo/home_controller.rb +8 -1
- data/app/controllers/avo/search_controller.rb +7 -1
- data/app/helpers/avo/url_helpers.rb +8 -9
- data/app/javascript/js/controllers/fields/code_field_controller.js +7 -1
- data/app/javascript/js/controllers/fields/key_value_controller.js +1 -0
- data/app/javascript/js/controllers/fields/tags_field_controller.js +0 -1
- data/app/javascript/js/controllers/menu_controller.js +4 -3
- data/app/javascript/js/controllers/resource_edit_controller.js +72 -0
- data/app/javascript/js/controllers/resource_index_controller.js +4 -0
- data/app/javascript/js/controllers/resource_show_controller.js +4 -0
- data/app/javascript/js/controllers/search_controller.js +28 -5
- data/app/javascript/js/controllers.js +8 -0
- data/app/views/avo/associations/new.html.erb +2 -1
- data/app/views/avo/base/_select_filter.html.erb +1 -1
- data/app/views/avo/base/_text_filter.html.erb +1 -0
- data/app/views/avo/base/edit.html.erb +2 -1
- data/app/views/avo/base/new.html.erb +1 -1
- data/app/views/avo/{dashboards → cards}/_chartkick_card.html.erb +0 -0
- data/app/views/avo/{dashboards → cards}/_metric_card.html.erb +0 -0
- data/app/views/avo/{dashboards/card.html.erb → cards/show.html.erb} +0 -0
- data/app/views/avo/partials/_custom_tools_alert.html.erb +21 -7
- data/app/views/avo/partials/_logo.html.erb +3 -2
- data/app/views/avo/partials/_navbar.html.erb +1 -1
- data/app/views/avo/partials/_table_header.html.erb +9 -1
- data/bin/test +1 -0
- data/config/routes.rb +7 -4
- data/db/factories.rb +1 -0
- data/lib/avo/app.rb +18 -1
- data/lib/avo/base_action.rb +16 -4
- data/lib/avo/base_card.rb +0 -23
- data/lib/avo/base_resource.rb +23 -16
- data/lib/avo/concerns/fetches_things.rb +19 -12
- data/lib/avo/concerns/has_fields.rb +93 -0
- data/lib/avo/concerns/has_html_attributes.rb +110 -0
- data/lib/avo/concerns/has_model.rb +11 -0
- data/lib/avo/concerns/has_stimulus_controllers.rb +42 -0
- data/lib/avo/dynamic_router.rb +1 -1
- data/lib/avo/engine.rb +1 -3
- data/lib/avo/fields/base_field.rb +24 -13
- data/lib/avo/fields/concerns/is_required.rb +17 -0
- data/lib/avo/fields/select_field.rb +1 -1
- data/lib/avo/grid_collector.rb +4 -4
- data/lib/avo/hosts/view_record_host.rb +7 -0
- data/lib/avo/html/builder.rb +117 -0
- data/lib/avo/licensing/pro_license.rb +1 -0
- data/lib/avo/menu/base_item.rb +4 -0
- data/lib/avo/menu/dashboard.rb +5 -0
- data/lib/avo/menu/resource.rb +5 -0
- data/lib/avo/version.rb +1 -1
- data/lib/avo.rb +5 -0
- data/lib/generators/avo/install_generator.rb +1 -4
- data/lib/generators/avo/templates/cards/chartkick_card_sample.tt +11 -1
- data/lib/generators/avo/templates/cards/metric_card_sample.tt +11 -1
- data/lib/generators/avo/templates/field/components/edit_component.html.erb.tt +1 -1
- data/lib/generators/avo/templates/field/components/index_component.html.erb.tt +1 -1
- data/lib/generators/avo/templates/field/components/show_component.html.erb.tt +1 -1
- data/lib/generators/avo/templates/initializer/avo.tt +1 -1
- data/lib/generators/avo/templates/locales/avo.en.yml +3 -3
- data/public/avo-assets/avo.css +473 -1055
- data/public/avo-assets/avo.js +147 -147
- data/public/avo-assets/avo.js.map +3 -3
- data/public/avo-assets/logomark.png +0 -0
- metadata +21 -11
- data/app/components/avo/views/resource_new_component.html.erb +0 -55
- data/app/components/avo/views/resource_new_component.rb +0 -38
- data/lib/avo/fields_collector.rb +0 -70
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Marin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -253,9 +253,10 @@ files:
|
|
253
253
|
- app/assets/stylesheets/css/active-storage.css
|
254
254
|
- app/assets/stylesheets/css/breadcrumbs.css
|
255
255
|
- app/assets/stylesheets/css/buttons.css
|
256
|
-
- app/assets/stylesheets/css/
|
257
|
-
- app/assets/stylesheets/css/
|
258
|
-
- app/assets/stylesheets/css/
|
256
|
+
- app/assets/stylesheets/css/fields/code.css
|
257
|
+
- app/assets/stylesheets/css/fields/progress.css
|
258
|
+
- app/assets/stylesheets/css/fields/status.css
|
259
|
+
- app/assets/stylesheets/css/fields/trix.css
|
259
260
|
- app/assets/stylesheets/css/fonts.css
|
260
261
|
- app/assets/stylesheets/css/loader.css
|
261
262
|
- app/assets/stylesheets/css/pagination.css
|
@@ -1032,8 +1033,6 @@ files:
|
|
1032
1033
|
- app/components/avo/views/resource_edit_component.rb
|
1033
1034
|
- app/components/avo/views/resource_index_component.html.erb
|
1034
1035
|
- app/components/avo/views/resource_index_component.rb
|
1035
|
-
- app/components/avo/views/resource_new_component.html.erb
|
1036
|
-
- app/components/avo/views/resource_new_component.rb
|
1037
1036
|
- app/components/avo/views/resource_show_component.html.erb
|
1038
1037
|
- app/components/avo/views/resource_show_component.rb
|
1039
1038
|
- app/controllers/avo/actions_controller.rb
|
@@ -1041,6 +1040,7 @@ files:
|
|
1041
1040
|
- app/controllers/avo/associations_controller.rb
|
1042
1041
|
- app/controllers/avo/attachments_controller.rb
|
1043
1042
|
- app/controllers/avo/base_controller.rb
|
1043
|
+
- app/controllers/avo/cards_controller.rb
|
1044
1044
|
- app/controllers/avo/dashboards_controller.rb
|
1045
1045
|
- app/controllers/avo/debug_controller.rb
|
1046
1046
|
- app/controllers/avo/home_controller.rb
|
@@ -1081,6 +1081,9 @@ files:
|
|
1081
1081
|
- app/javascript/js/controllers/modal_controller.js
|
1082
1082
|
- app/javascript/js/controllers/multiple_select_filter_controller.js
|
1083
1083
|
- app/javascript/js/controllers/per_page_controller.js
|
1084
|
+
- app/javascript/js/controllers/resource_edit_controller.js
|
1085
|
+
- app/javascript/js/controllers/resource_index_controller.js
|
1086
|
+
- app/javascript/js/controllers/resource_show_controller.js
|
1084
1087
|
- app/javascript/js/controllers/search_controller.js
|
1085
1088
|
- app/javascript/js/controllers/select_controller.js
|
1086
1089
|
- app/javascript/js/controllers/select_filter_controller.js
|
@@ -1099,9 +1102,9 @@ files:
|
|
1099
1102
|
- app/views/avo/base/index.html.erb
|
1100
1103
|
- app/views/avo/base/new.html.erb
|
1101
1104
|
- app/views/avo/base/show.html.erb
|
1102
|
-
- app/views/avo/
|
1103
|
-
- app/views/avo/
|
1104
|
-
- app/views/avo/
|
1105
|
+
- app/views/avo/cards/_chartkick_card.html.erb
|
1106
|
+
- app/views/avo/cards/_metric_card.html.erb
|
1107
|
+
- app/views/avo/cards/show.html.erb
|
1105
1108
|
- app/views/avo/dashboards/show.html.erb
|
1106
1109
|
- app/views/avo/debug/index.html.erb
|
1107
1110
|
- app/views/avo/debug/report.html.erb
|
@@ -1162,6 +1165,10 @@ files:
|
|
1162
1165
|
- lib/avo/base_resource_tool.rb
|
1163
1166
|
- lib/avo/concerns/fetches_things.rb
|
1164
1167
|
- lib/avo/concerns/handles_field_args.rb
|
1168
|
+
- lib/avo/concerns/has_fields.rb
|
1169
|
+
- lib/avo/concerns/has_html_attributes.rb
|
1170
|
+
- lib/avo/concerns/has_model.rb
|
1171
|
+
- lib/avo/concerns/has_stimulus_controllers.rb
|
1165
1172
|
- lib/avo/concerns/has_tools.rb
|
1166
1173
|
- lib/avo/configuration.rb
|
1167
1174
|
- lib/avo/dashboards/base_dashboard.rb
|
@@ -1178,6 +1185,7 @@ files:
|
|
1178
1185
|
- lib/avo/fields/boolean_field.rb
|
1179
1186
|
- lib/avo/fields/boolean_group_field.rb
|
1180
1187
|
- lib/avo/fields/code_field.rb
|
1188
|
+
- lib/avo/fields/concerns/is_required.rb
|
1181
1189
|
- lib/avo/fields/country_field.rb
|
1182
1190
|
- lib/avo/fields/currency_field.rb
|
1183
1191
|
- lib/avo/fields/date_field.rb
|
@@ -1206,7 +1214,6 @@ files:
|
|
1206
1214
|
- lib/avo/fields/text_field.rb
|
1207
1215
|
- lib/avo/fields/textarea_field.rb
|
1208
1216
|
- lib/avo/fields/trix_field.rb
|
1209
|
-
- lib/avo/fields_collector.rb
|
1210
1217
|
- lib/avo/filters/base_filter.rb
|
1211
1218
|
- lib/avo/filters/boolean_filter.rb
|
1212
1219
|
- lib/avo/filters/multiple_select_filter.rb
|
@@ -1224,6 +1231,8 @@ files:
|
|
1224
1231
|
- lib/avo/hosts/dashboard_visibility.rb
|
1225
1232
|
- lib/avo/hosts/ordering.rb
|
1226
1233
|
- lib/avo/hosts/record_host.rb
|
1234
|
+
- lib/avo/hosts/view_record_host.rb
|
1235
|
+
- lib/avo/html/builder.rb
|
1227
1236
|
- lib/avo/licensing/community_license.rb
|
1228
1237
|
- lib/avo/licensing/h_q.rb
|
1229
1238
|
- lib/avo/licensing/license.rb
|
@@ -1319,6 +1328,7 @@ files:
|
|
1319
1328
|
- public/avo-assets/fonts/inter-v7-latin-regular.woff2
|
1320
1329
|
- public/avo-assets/logo-on-white.png
|
1321
1330
|
- public/avo-assets/logo.png
|
1331
|
+
- public/avo-assets/logomark.png
|
1322
1332
|
homepage: https://avohq.io
|
1323
1333
|
licenses:
|
1324
1334
|
- Commercial
|
@@ -1,55 +0,0 @@
|
|
1
|
-
<div>
|
2
|
-
<% @resource.panels.each do |resource_panel| %>
|
3
|
-
<%= form_with model: @resource.model,
|
4
|
-
scope: @resource.form_scope,
|
5
|
-
url: helpers.resources_path(
|
6
|
-
resource: @resource,
|
7
|
-
via_relation_class: params[:via_relation_class],
|
8
|
-
via_relation: params[:via_relation],
|
9
|
-
via_resource_id: params[:via_resource_id]
|
10
|
-
),
|
11
|
-
local: true,
|
12
|
-
multipart: true do |form| %>
|
13
|
-
<%= render Avo::ReferrerParamsComponent.new back_path: back_path %>
|
14
|
-
<%= render Avo::PanelComponent.new(title: resource_panel[:name], description: @resource.resource_description, display_breadcrumbs: true) do |c| %>
|
15
|
-
<% c.tools do %>
|
16
|
-
<div class="flex justify-end space-x-2">
|
17
|
-
<%= a_link back_path,
|
18
|
-
style: :text,
|
19
|
-
icon: 'arrow-left' do %>
|
20
|
-
<%= t('avo.cancel').capitalize %>
|
21
|
-
<% end %>
|
22
|
-
<% if can_see_the_save_button? %>
|
23
|
-
<%= a_button color: :primary,
|
24
|
-
style: :primary,
|
25
|
-
loading: true,
|
26
|
-
type: :submit,
|
27
|
-
icon: 'save' do %>
|
28
|
-
<%= t('avo.save').capitalize %>
|
29
|
-
<% end %>
|
30
|
-
<% end %>
|
31
|
-
</div>
|
32
|
-
<% end %>
|
33
|
-
<% if Avo.configuration.buttons_on_form_footers %>
|
34
|
-
<% c.footer_tools do %>
|
35
|
-
<%= a_link back_path, icon: 'arrow-left' do %>
|
36
|
-
<%= t('avo.cancel').capitalize %>
|
37
|
-
<% end %>
|
38
|
-
<% if can_see_the_save_button? %>
|
39
|
-
<%= a_button color: :green, loading: true, type: :submit, icon: 'save' do %>
|
40
|
-
<%= t('avo.save').capitalize %>
|
41
|
-
<% end %>
|
42
|
-
<% end %>
|
43
|
-
<% end %>
|
44
|
-
<% end %>
|
45
|
-
<% c.body do %>
|
46
|
-
<div class="divide-y">
|
47
|
-
<% @resource.get_fields.each_with_index do |field, index| %>
|
48
|
-
<%= render field.component_for_view(:edit).new(field: field, resource: @resource, index: index, form: form) unless field.computed %>
|
49
|
-
<% end %>
|
50
|
-
</div>
|
51
|
-
<% end %>
|
52
|
-
<% end %>
|
53
|
-
<% end %>
|
54
|
-
<% end %>
|
55
|
-
</div>
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Avo::Views::ResourceNewComponent < ViewComponent::Base
|
4
|
-
include Avo::ResourcesHelper
|
5
|
-
include Avo::ApplicationHelper
|
6
|
-
|
7
|
-
def initialize(
|
8
|
-
resource: nil,
|
9
|
-
model: nil
|
10
|
-
)
|
11
|
-
@resource = resource
|
12
|
-
@model = model
|
13
|
-
end
|
14
|
-
|
15
|
-
def back_path
|
16
|
-
if via_resource?
|
17
|
-
helpers.resource_path(model: params[:via_relation_class].safe_constantize, resource: relation_resource, resource_id: params[:via_resource_id])
|
18
|
-
else
|
19
|
-
helpers.resources_path(resource: @resource)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# The create button is dependent on the new? policy method.
|
24
|
-
# The create? should be called only when the user clicks the Save button so the developers gets access to the params from the form.
|
25
|
-
def can_see_the_save_button?
|
26
|
-
@resource.authorization.authorize_action :new, raise_exception: false
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def via_resource?
|
32
|
-
params[:via_relation_class].present? && params[:via_resource_id].present?
|
33
|
-
end
|
34
|
-
|
35
|
-
def relation_resource
|
36
|
-
::Avo::App.get_resource_by_model_name params[:via_relation_class].safe_constantize
|
37
|
-
end
|
38
|
-
end
|
data/lib/avo/fields_collector.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
module Avo
|
2
|
-
module FieldsCollector
|
3
|
-
def field(field_name, as:, **args, &block)
|
4
|
-
self.fields ||= []
|
5
|
-
self.invalid_fields ||= []
|
6
|
-
|
7
|
-
field_instance = parse_field(field_name, as: as, **args, &block)
|
8
|
-
|
9
|
-
if field_instance.present?
|
10
|
-
self.fields << field_instance
|
11
|
-
else
|
12
|
-
self.invalid_fields << ({
|
13
|
-
name: field_name,
|
14
|
-
as: as,
|
15
|
-
resource: name,
|
16
|
-
message: "There's an invalid field configuration for this resource. <br/> <code class='px-1 py-px rounded bg-red-600'>field :#{field_name}, as: #{as}</code>"
|
17
|
-
})
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def parse_field(field_name, as:, **args, &block)
|
22
|
-
# The field is passed as a symbol eg: :text, :color_picker, :trix
|
23
|
-
if as.is_a? Symbol
|
24
|
-
field_class = field_class_from_symbol(as)
|
25
|
-
|
26
|
-
if field_class.present?
|
27
|
-
# The field has been registered before.
|
28
|
-
instantiate_field(field_name, klass: field_class, **args, &block)
|
29
|
-
else
|
30
|
-
# The symbol can be transformed to a class and found.
|
31
|
-
class_name = as.to_s.camelize
|
32
|
-
field_class = "#{class_name}Field"
|
33
|
-
|
34
|
-
# Discover & load custom field classes
|
35
|
-
if Object.const_defined? field_class
|
36
|
-
instantiate_field(field_name, klass: field_class.safe_constantize, **args, &block)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
elsif as.is_a? Class
|
40
|
-
# The field has been passed as a class.
|
41
|
-
if Object.const_defined? as.to_s
|
42
|
-
instantiate_field(field_name, klass: as, **args, &block)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def heading(body, **args)
|
48
|
-
self.fields ||= []
|
49
|
-
self.fields << Avo::Fields::HeadingField.new(body, **args)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def instantiate_field(field_name, klass:, **args, &block)
|
55
|
-
if block
|
56
|
-
klass.new(field_name, **args || {}, &block)
|
57
|
-
else
|
58
|
-
klass.new(field_name, **args || {})
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def field_class_from_symbol(symbol)
|
63
|
-
matched_field = Avo::App.fields.find do |field|
|
64
|
-
field[:name].to_s == symbol.to_s
|
65
|
-
end
|
66
|
-
|
67
|
-
return matched_field[:class] if matched_field.present? && matched_field[:class].present?
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|