avo 2.45.0 → 3.0.2

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 (407) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +28 -26
  3. data/Gemfile.lock +231 -161
  4. data/README.md +19 -27
  5. data/Rakefile +2 -0
  6. data/app/assets/stylesheets/avo.base.css +1 -1
  7. data/app/assets/svgs/font.svg +1 -0
  8. data/app/assets/svgs/triangle-up.svg +1 -0
  9. data/app/components/avo/actions_component.html.erb +19 -5
  10. data/app/components/avo/actions_component.rb +39 -19
  11. data/app/components/avo/asset_manager/javascript_component.html.erb +3 -0
  12. data/app/components/avo/asset_manager/javascript_component.rb +13 -0
  13. data/app/components/avo/asset_manager/stylesheet_component.html.erb +3 -0
  14. data/app/components/avo/asset_manager/stylesheet_component.rb +13 -0
  15. data/app/components/avo/base_component.rb +15 -12
  16. data/app/components/avo/button_component.rb +20 -3
  17. data/app/components/avo/empty_state_component.rb +1 -1
  18. data/app/components/avo/field_wrapper_component.html.erb +1 -1
  19. data/app/components/avo/field_wrapper_component.rb +9 -15
  20. data/app/components/avo/fields/area_field/edit_component.html.erb +2 -2
  21. data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +75 -79
  22. data/app/components/avo/fields/belongs_to_field/edit_component.rb +7 -7
  23. data/app/components/avo/fields/belongs_to_field/index_component.html.erb +1 -1
  24. data/app/components/avo/fields/belongs_to_field/show_component.rb +2 -2
  25. data/app/components/avo/fields/boolean_field/edit_component.html.erb +1 -1
  26. data/app/components/avo/fields/boolean_field/index_component.html.erb +1 -1
  27. data/app/components/avo/fields/boolean_group_field/edit_component.html.erb +3 -3
  28. data/app/components/avo/fields/common/badge_viewer_component.rb +1 -1
  29. data/app/components/avo/fields/common/boolean_check_component.html.erb +1 -12
  30. data/app/components/avo/fields/common/boolean_check_component.rb +2 -1
  31. data/app/components/avo/fields/common/boolean_group_component.html.erb +2 -2
  32. data/app/components/avo/fields/common/files/view_type/grid_item_component.rb +2 -2
  33. data/app/components/avo/fields/common/gravatar_viewer_component.html.erb +1 -1
  34. data/app/components/avo/fields/common/gravatar_viewer_component.rb +2 -2
  35. data/app/components/avo/fields/common/heading_component.html.erb +3 -8
  36. data/app/components/avo/fields/common/heading_component.rb +1 -3
  37. data/app/components/avo/fields/common/key_value_component.html.erb +2 -2
  38. data/app/components/avo/fields/common/key_value_component.rb +2 -2
  39. data/app/components/avo/fields/common/progress_bar_component.rb +3 -9
  40. data/app/components/avo/fields/common/status_viewer_component.html.erb +3 -0
  41. data/app/components/avo/fields/edit_component.rb +2 -2
  42. data/app/components/avo/fields/external_image_field/index_component.html.erb +1 -1
  43. data/app/components/avo/fields/file_field/index_component.html.erb +2 -2
  44. data/app/components/avo/fields/gravatar_field/index_component.html.erb +1 -1
  45. data/app/components/avo/fields/has_one_field/index_component.html.erb +1 -1
  46. data/app/components/avo/fields/has_one_field/show_component.html.erb +3 -2
  47. data/app/components/avo/fields/has_one_field/show_component.rb +2 -2
  48. data/app/components/avo/fields/heading_field/edit_component.html.erb +1 -1
  49. data/app/components/avo/fields/heading_field/show_component.html.erb +1 -1
  50. data/app/components/avo/fields/id_field/index_component.html.erb +1 -1
  51. data/app/components/avo/fields/index_component.rb +6 -6
  52. data/app/components/avo/fields/location_field/edit_component.html.erb +12 -10
  53. data/app/components/avo/fields/preview_field/index_component.html.erb +10 -0
  54. data/app/components/avo/fields/preview_field/index_component.rb +4 -0
  55. data/app/components/avo/fields/select_field/edit_component.html.erb +1 -1
  56. data/app/components/avo/fields/show_component.rb +5 -2
  57. data/app/components/avo/fields/text_field/index_component.html.erb +1 -1
  58. data/app/components/avo/fields/trix_field/edit_component.html.erb +2 -2
  59. data/app/components/avo/fields/trix_field/edit_component.rb +1 -1
  60. data/app/components/avo/fields/trix_field/show_component.html.erb +1 -1
  61. data/app/components/avo/filters_component.html.erb +9 -3
  62. data/app/components/avo/filters_component.rb +4 -4
  63. data/app/components/avo/index/field_wrapper_component.rb +1 -13
  64. data/app/components/avo/index/grid_item_component.html.erb +13 -36
  65. data/app/components/avo/index/grid_item_component.rb +43 -16
  66. data/app/components/avo/index/resource_controls_component.html.erb +3 -81
  67. data/app/components/avo/index/resource_controls_component.rb +125 -18
  68. data/app/components/avo/index/resource_grid_component.html.erb +5 -3
  69. data/app/components/avo/index/resource_grid_component.rb +5 -2
  70. data/app/components/avo/index/resource_map_component.html.erb +1 -1
  71. data/app/components/avo/index/resource_map_component.rb +3 -3
  72. data/app/components/avo/index/resource_table_component.html.erb +3 -2
  73. data/app/components/avo/index/resource_table_component.rb +8 -7
  74. data/app/components/avo/index/table_row_component.html.erb +9 -5
  75. data/app/components/avo/index/table_row_component.rb +3 -2
  76. data/app/components/avo/items/panel_component.html.erb +25 -0
  77. data/app/components/avo/items/panel_component.rb +43 -0
  78. data/app/components/avo/items/switcher_component.html.erb +17 -0
  79. data/app/components/avo/items/switcher_component.rb +79 -0
  80. data/app/components/avo/items/visible_items_component.html.erb +10 -0
  81. data/app/components/avo/items/visible_items_component.rb +11 -0
  82. data/app/components/avo/modal_component.html.erb +3 -4
  83. data/app/components/avo/paginator_component.html.erb +1 -1
  84. data/app/components/avo/paginator_component.rb +6 -6
  85. data/app/components/avo/panel_component.html.erb +7 -5
  86. data/app/components/avo/referrer_params_component.html.erb +1 -1
  87. data/app/components/avo/resource_component.rb +205 -26
  88. data/app/components/avo/resource_sidebar_component.html.erb +15 -18
  89. data/app/components/avo/resource_sidebar_component.rb +5 -3
  90. data/app/components/avo/sidebar/link_component.rb +1 -1
  91. data/app/components/avo/sidebar_component.html.erb +10 -3
  92. data/app/components/avo/sidebar_component.rb +5 -3
  93. data/app/components/avo/sidebar_profile_component.html.erb +18 -12
  94. data/app/components/avo/tab_group_component.html.erb +14 -8
  95. data/app/components/avo/tab_group_component.rb +1 -6
  96. data/app/components/avo/tab_switcher_component.html.erb +17 -40
  97. data/app/components/avo/tab_switcher_component.rb +6 -41
  98. data/app/components/avo/views/resource_edit_component.html.erb +23 -86
  99. data/app/components/avo/views/resource_edit_component.rb +20 -19
  100. data/app/components/avo/views/resource_index_component.html.erb +42 -47
  101. data/app/components/avo/views/resource_index_component.rb +76 -13
  102. data/app/components/avo/views/resource_show_component.html.erb +16 -177
  103. data/app/components/avo/views/resource_show_component.rb +16 -10
  104. data/app/controllers/avo/actions_controller.rb +29 -31
  105. data/app/controllers/avo/application_controller.rb +119 -180
  106. data/app/controllers/avo/associations_controller.rb +34 -43
  107. data/app/controllers/avo/attachments_controller.rb +4 -4
  108. data/app/controllers/avo/base_controller.rb +139 -91
  109. data/app/controllers/avo/debug_controller.rb +17 -5
  110. data/app/controllers/avo/home_controller.rb +1 -1
  111. data/app/controllers/avo/search_controller.rb +56 -50
  112. data/app/controllers/concerns/avo/initializes_avo.rb +22 -0
  113. data/app/helpers/avo/application_helper.rb +18 -8
  114. data/app/helpers/avo/resources_helper.rb +1 -1
  115. data/app/helpers/avo/url_helpers.rb +28 -12
  116. data/app/javascript/avo.base.js +1 -0
  117. data/app/javascript/js/controllers/action_controller.js +5 -3
  118. data/app/javascript/js/controllers/actions_overflow_controller.js +62 -0
  119. data/app/javascript/js/controllers/fields/reload_belongs_to_field_controller.js +7 -7
  120. data/app/javascript/js/controllers/filter_controller.js +1 -1
  121. data/app/javascript/js/controllers/input_autofocus_controller.js +12 -0
  122. data/app/javascript/js/controllers/preview_controller.js +24 -0
  123. data/app/javascript/js/controllers/search_controller.js +4 -2
  124. data/app/javascript/js/controllers/self_destroy_controller.js +7 -0
  125. data/app/javascript/js/controllers/toggle_controller.js +48 -0
  126. data/app/javascript/js/controllers.js +11 -5
  127. data/app/javascript/js/custom-stream-actions.js +15 -0
  128. data/app/views/avo/actions/show.html.erb +9 -5
  129. data/app/views/avo/associations/new.html.erb +2 -2
  130. data/app/views/avo/base/_new_via_belongs_to.html.erb +1 -1
  131. data/app/views/avo/base/close_modal_and_reload_field.turbo_stream.erb +3 -3
  132. data/app/views/avo/base/create_fail_action.turbo_stream.erb +2 -2
  133. data/app/views/avo/base/edit.html.erb +1 -1
  134. data/app/views/avo/base/index.html.erb +4 -3
  135. data/app/views/avo/base/new.html.erb +2 -1
  136. data/app/views/avo/base/preview.html.erb +19 -0
  137. data/app/views/avo/base/show.html.erb +2 -2
  138. data/app/views/avo/debug/_valid_indicator.html.erb +9 -0
  139. data/app/views/avo/debug/report.html.erb +32 -17
  140. data/app/views/avo/debug/{index.html.erb → status.html.erb} +31 -14
  141. data/app/views/avo/partials/_custom_tools_alert.html.erb +2 -2
  142. data/app/views/avo/partials/_footer.html.erb +1 -1
  143. data/app/views/avo/partials/_javascript.html.erb +5 -0
  144. data/app/views/avo/partials/_logo.html.erb +1 -1
  145. data/app/views/avo/partials/_navbar.html.erb +3 -5
  146. data/app/views/avo/partials/_resource_search.html.erb +1 -0
  147. data/app/views/avo/partials/_table_header.html.erb +5 -11
  148. data/app/views/layouts/avo/application.html.erb +5 -4
  149. data/avo.gemspec +10 -8
  150. data/bin/dev +3 -1
  151. data/bin/prod +0 -0
  152. data/config/master.key +1 -0
  153. data/config/routes.rb +7 -10
  154. data/db/factories.rb +6 -0
  155. data/lib/avo/asset_manager.rb +30 -0
  156. data/lib/avo/base_action.rb +82 -66
  157. data/lib/avo/base_resource.rb +285 -225
  158. data/lib/avo/base_resource_tool.rb +9 -16
  159. data/lib/avo/concerns/borrow_items_holder.rb +35 -0
  160. data/lib/avo/concerns/breadcrumbs.rb +2 -2
  161. data/lib/avo/concerns/{can_replace_fields.rb → can_replace_items.rb} +5 -9
  162. data/lib/avo/concerns/filters_session_handler.rb +7 -5
  163. data/lib/avo/concerns/has_controls.rb +37 -0
  164. data/lib/avo/concerns/has_description.rb +23 -0
  165. data/lib/avo/concerns/has_helpers.rb +18 -0
  166. data/lib/avo/concerns/has_item_type.rb +42 -0
  167. data/lib/avo/concerns/has_items.rb +339 -0
  168. data/lib/avo/concerns/hydration.rb +17 -0
  169. data/lib/avo/concerns/is_resource_item.rb +16 -36
  170. data/lib/avo/concerns/is_visible.rb +15 -0
  171. data/lib/avo/concerns/model_class_constantized.rb +0 -2
  172. data/lib/avo/concerns/visible_in_different_views.rb +132 -0
  173. data/lib/avo/concerns/visible_items.rb +7 -38
  174. data/lib/avo/configuration/branding.rb +0 -12
  175. data/lib/avo/configuration.rb +28 -11
  176. data/lib/avo/current.rb +39 -0
  177. data/lib/avo/dsl/field_parser.rb +3 -3
  178. data/lib/avo/dynamic_router.rb +18 -3
  179. data/lib/avo/engine.rb +35 -30
  180. data/lib/avo/error_manager.rb +25 -0
  181. data/lib/avo/execution_context.rb +14 -15
  182. data/lib/avo/fields/base_field.rb +84 -121
  183. data/lib/avo/fields/belongs_to_field.rb +19 -23
  184. data/lib/avo/fields/concerns/file_authorization.rb +2 -2
  185. data/lib/avo/fields/concerns/handles_field_args.rb +49 -0
  186. data/lib/avo/fields/concerns/has_default.rb +1 -5
  187. data/lib/avo/fields/concerns/has_field_name.rb +22 -0
  188. data/lib/avo/fields/concerns/has_html_attributes.rb +112 -0
  189. data/lib/avo/fields/concerns/is_disabled.rb +1 -5
  190. data/lib/avo/fields/concerns/is_readonly.rb +1 -5
  191. data/lib/avo/fields/concerns/is_required.rb +5 -7
  192. data/lib/avo/fields/concerns/is_searchable.rb +15 -0
  193. data/lib/avo/fields/concerns/use_resource.rb +5 -1
  194. data/lib/avo/fields/concerns/use_view_components.rb +45 -0
  195. data/lib/avo/fields/country_field.rb +4 -0
  196. data/lib/avo/fields/date_time_field.rb +1 -5
  197. data/lib/avo/fields/external_image_field.rb +2 -2
  198. data/lib/avo/fields/field_manager.rb +55 -0
  199. data/lib/avo/fields/file_field.rb +2 -2
  200. data/lib/avo/fields/gravatar_field.rb +2 -2
  201. data/lib/avo/fields/has_and_belongs_to_many_field.rb +1 -2
  202. data/lib/avo/fields/has_base_field.rb +21 -17
  203. data/lib/avo/fields/has_many_field.rb +5 -2
  204. data/lib/avo/fields/has_one_field.rb +8 -12
  205. data/lib/avo/fields/heading_field.rb +9 -14
  206. data/lib/avo/fields/hidden_field.rb +1 -1
  207. data/lib/avo/fields/id_field.rb +3 -3
  208. data/lib/avo/fields/location_field.rb +10 -10
  209. data/lib/avo/fields/password_field.rb +1 -1
  210. data/lib/avo/fields/preview_field.rb +14 -0
  211. data/lib/avo/fields/select_field.rb +12 -8
  212. data/lib/avo/fields/status_field.rb +7 -1
  213. data/lib/avo/fields/text_field.rb +2 -2
  214. data/lib/avo/filters/base_filter.rb +9 -4
  215. data/lib/avo/html/builder.rb +8 -8
  216. data/lib/avo/item_grapher.rb +78 -0
  217. data/lib/avo/licensing/h_q.rb +11 -73
  218. data/lib/avo/licensing/license.rb +5 -1
  219. data/lib/avo/licensing/license_manager.rb +1 -1
  220. data/lib/avo/licensing/pro_license.rb +1 -7
  221. data/lib/avo/loaders/fields_loader.rb +7 -1
  222. data/lib/avo/plugin.rb +36 -0
  223. data/lib/avo/plugin_manager.rb +56 -0
  224. data/lib/avo/prefixed_test_helpers.rb +20 -0
  225. data/lib/avo/reloader.rb +3 -0
  226. data/lib/avo/resources/controls/actions_list.rb +7 -12
  227. data/lib/avo/resources/controls/attach_button.rb +15 -0
  228. data/lib/avo/resources/controls/back_button.rb +1 -1
  229. data/lib/avo/resources/controls/base_control.rb +15 -49
  230. data/lib/avo/resources/controls/create_button.rb +15 -0
  231. data/lib/avo/resources/controls/delete_button.rb +5 -1
  232. data/lib/avo/resources/controls/detach_button.rb +4 -1
  233. data/lib/avo/resources/controls/edit_button.rb +4 -1
  234. data/lib/avo/resources/controls/order_controls.rb +8 -0
  235. data/lib/avo/resources/controls/save_button.rb +13 -0
  236. data/lib/avo/resources/controls/show_button.rb +15 -0
  237. data/lib/avo/resources/items/holder.rb +96 -0
  238. data/lib/avo/resources/items/item_group.rb +44 -0
  239. data/lib/avo/resources/items/main_panel.rb +12 -0
  240. data/lib/avo/resources/items/panel.rb +2 -0
  241. data/lib/avo/resources/items/row.rb +42 -0
  242. data/lib/avo/resources/items/sidebar.rb +46 -0
  243. data/lib/avo/resources/items/tab.rb +54 -0
  244. data/lib/avo/resources/items/tab_group.rb +62 -0
  245. data/lib/avo/resources/resource_manager.rb +179 -0
  246. data/lib/avo/services/authorization_service.rb +11 -110
  247. data/lib/avo/services/debug_service.rb +93 -0
  248. data/lib/avo/services/encryption_service.rb +8 -12
  249. data/lib/avo/services/telemetry_service.rb +85 -0
  250. data/lib/avo/test_helpers.rb +362 -0
  251. data/lib/avo/tools/tool_manager.rb +30 -0
  252. data/lib/avo/version.rb +1 -1
  253. data/lib/avo/view_inquirer.rb +36 -0
  254. data/lib/avo.rb +109 -24
  255. data/lib/generators/avo/action_generator.rb +8 -8
  256. data/lib/generators/avo/card_generator.rb +27 -0
  257. data/lib/generators/avo/concerns/parent_controller.rb +20 -0
  258. data/lib/generators/avo/controller_generator.rb +3 -0
  259. data/lib/generators/avo/eject_generator.rb +180 -15
  260. data/lib/generators/avo/field_generator.rb +49 -2
  261. data/lib/generators/avo/filter_generator.rb +8 -8
  262. data/lib/generators/avo/js/install_generator.rb +2 -2
  263. data/lib/generators/avo/resource_generator.rb +12 -9
  264. data/lib/generators/avo/scope_generator.rb +15 -0
  265. data/lib/generators/avo/tailwindcss/install_generator.rb +70 -26
  266. data/lib/generators/avo/templates/action.tt +8 -6
  267. data/lib/generators/avo/templates/cards/chartkick_card.tt +1 -1
  268. data/lib/generators/avo/templates/cards/chartkick_card_sample.tt +1 -1
  269. data/lib/generators/avo/templates/cards/metric_card.tt +1 -1
  270. data/lib/generators/avo/templates/cards/metric_card_sample.tt +1 -1
  271. data/lib/generators/avo/templates/cards/partial_card.tt +1 -1
  272. data/lib/generators/avo/templates/cards/partial_card_sample.tt +1 -1
  273. data/lib/generators/avo/templates/dashboards/dashboard.tt +5 -3
  274. data/lib/generators/avo/templates/field/%singular_name%_field.rb.tt +1 -1
  275. data/lib/generators/avo/templates/filters/boolean_filter.tt +1 -1
  276. data/lib/generators/avo/templates/filters/multiple_select_filter.tt +1 -1
  277. data/lib/generators/avo/templates/filters/select_filter.tt +1 -1
  278. data/lib/generators/avo/templates/filters/text_filter.tt +1 -1
  279. data/lib/generators/avo/templates/initializer/avo.tt +7 -3
  280. data/lib/generators/avo/templates/locales/avo.ar.yml +2 -1
  281. data/lib/generators/avo/templates/locales/avo.en.yml +4 -3
  282. data/lib/generators/avo/templates/locales/avo.es.yml +1 -0
  283. data/lib/generators/avo/templates/locales/avo.fr.yml +1 -0
  284. data/lib/generators/avo/templates/locales/avo.nb.yml +1 -0
  285. data/lib/generators/avo/templates/locales/avo.nn.yml +1 -0
  286. data/lib/generators/avo/templates/locales/avo.pt-BR.yml +1 -0
  287. data/lib/generators/avo/templates/locales/avo.pt.yml +1 -0
  288. data/lib/generators/avo/templates/locales/avo.ro.yml +6 -5
  289. data/lib/generators/avo/templates/locales/avo.tr.yml +1 -0
  290. data/lib/generators/avo/templates/resource/controller.tt +1 -1
  291. data/lib/generators/avo/templates/resource/resource.tt +7 -7
  292. data/lib/generators/avo/templates/resource_tools/partial.tt +2 -2
  293. data/lib/generators/avo/templates/resource_tools/resource_tool.tt +1 -1
  294. data/lib/generators/avo/templates/scope.tt +6 -0
  295. data/lib/generators/avo/templates/tailwindcss/Procfile.dev +1 -1
  296. data/lib/generators/avo/templates/tailwindcss/avo.tailwind.css +5 -3
  297. data/lib/generators/avo/templates/tailwindcss/tailwind.config.js +11 -0
  298. data/lib/tasks/avo_tasks.rake +72 -4
  299. data/public/avo-assets/avo.base.css +1893 -1187
  300. data/public/avo-assets/avo.base.js +217 -305
  301. data/public/avo-assets/avo.base.js.map +3 -3
  302. data/public/avo-assets/avo.css +9744 -0
  303. data/public/avo-assets/avo.js +513 -0
  304. data/public/avo-assets/avo.js.map +7 -0
  305. data/tailwind.custom.js +47 -0
  306. data/tailwind.preset.js +152 -0
  307. metadata +104 -113
  308. data/app/components/avo/card_component.html.erb +0 -46
  309. data/app/components/avo/card_component.rb +0 -25
  310. data/app/components/avo/dashboards/divider_component.html.erb +0 -9
  311. data/app/components/avo/dashboards/divider_component.rb +0 -19
  312. data/app/components/avo/fields/belongs_to_field/autocomplete_component.html.erb +0 -47
  313. data/app/components/avo/fields/belongs_to_field/autocomplete_component.rb +0 -95
  314. data/app/components/avo/fields/tags_field/edit_component.html.erb +0 -35
  315. data/app/components/avo/fields/tags_field/edit_component.rb +0 -4
  316. data/app/components/avo/fields/tags_field/index_component.html.erb +0 -10
  317. data/app/components/avo/fields/tags_field/index_component.rb +0 -9
  318. data/app/components/avo/fields/tags_field/show_component.html.erb +0 -7
  319. data/app/components/avo/fields/tags_field/show_component.rb +0 -5
  320. data/app/components/avo/fields/tags_field/tag_component.html.erb +0 -9
  321. data/app/components/avo/fields/tags_field/tag_component.rb +0 -11
  322. data/app/components/avo/index/ordering/base_component.rb +0 -9
  323. data/app/components/avo/index/ordering/button_component.html.erb +0 -11
  324. data/app/components/avo/index/ordering/button_component.rb +0 -23
  325. data/app/components/avo/index/ordering/buttons_component.html.erb +0 -32
  326. data/app/components/avo/index/ordering/buttons_component.rb +0 -47
  327. data/app/components/avo/item_switcher_component.html.erb +0 -27
  328. data/app/components/avo/item_switcher_component.rb +0 -48
  329. data/app/components/avo/sidebar/item_switcher_component.html.erb +0 -16
  330. data/app/components/avo/sidebar/item_switcher_component.rb +0 -15
  331. data/app/controllers/avo/dashboards/cards_controller.rb +0 -37
  332. data/app/controllers/avo/dashboards_controller.rb +0 -22
  333. data/app/controllers/avo/reorder_controller.rb +0 -25
  334. data/app/javascript/js/controllers/base_controller.js +0 -22
  335. data/app/javascript/js/controllers/fields/tags_field_controller.js +0 -127
  336. data/app/javascript/js/controllers/toggle_panel_controller.js +0 -18
  337. data/app/views/avo/dashboards/cards/_chartkick_card.html.erb +0 -3
  338. data/app/views/avo/dashboards/cards/_metric_card.html.erb +0 -5
  339. data/app/views/avo/dashboards/cards/chartkick_missing.html.erb +0 -14
  340. data/app/views/avo/dashboards/cards/show.html.erb +0 -3
  341. data/app/views/avo/dashboards/show.html.erb +0 -38
  342. data/app/views/avo/partials/_global_search.html.erb +0 -19
  343. data/app/views/avo/sidebar/_license_warnings.html.erb +0 -6
  344. data/lib/avo/app.rb +0 -237
  345. data/lib/avo/base_card.rb +0 -161
  346. data/lib/avo/concerns/fetches_things.rb +0 -150
  347. data/lib/avo/concerns/handles_field_args.rb +0 -47
  348. data/lib/avo/concerns/has_editable_controls.rb +0 -34
  349. data/lib/avo/concerns/has_fields.rb +0 -334
  350. data/lib/avo/concerns/has_html_attributes.rb +0 -108
  351. data/lib/avo/concerns/policy_helpers.rb +0 -31
  352. data/lib/avo/concerns/visible_in_dashboard.rb +0 -31
  353. data/lib/avo/dashboards/base_dashboard.rb +0 -89
  354. data/lib/avo/dashboards/base_divider.rb +0 -35
  355. data/lib/avo/dashboards/chartkick_card.rb +0 -77
  356. data/lib/avo/dashboards/dashboard_card.rb +0 -6
  357. data/lib/avo/dashboards/metric_card.rb +0 -9
  358. data/lib/avo/dashboards/partial_card.rb +0 -7
  359. data/lib/avo/fields/field_extensions/has_field_name.rb +0 -19
  360. data/lib/avo/fields/field_extensions/visible_in_different_views.rb +0 -111
  361. data/lib/avo/fields/tags_field.rb +0 -102
  362. data/lib/avo/grid_collector.rb +0 -42
  363. data/lib/avo/hosts/association_scope_host.rb +0 -8
  364. data/lib/avo/hosts/base_host.rb +0 -25
  365. data/lib/avo/hosts/card_visibility.rb +0 -20
  366. data/lib/avo/hosts/dashboard_card.rb +0 -22
  367. data/lib/avo/hosts/dashboard_visibility.rb +0 -19
  368. data/lib/avo/hosts/ordering.rb +0 -22
  369. data/lib/avo/hosts/record_host.rb +0 -7
  370. data/lib/avo/hosts/resource_record_host.rb +0 -7
  371. data/lib/avo/hosts/resource_view_record_host.rb +0 -7
  372. data/lib/avo/hosts/search_scope_host.rb +0 -7
  373. data/lib/avo/hosts/view_record_host.rb +0 -7
  374. data/lib/avo/hosts/visibility_host.rb +0 -12
  375. data/lib/avo/items_holder.rb +0 -96
  376. data/lib/avo/main_panel.rb +0 -3
  377. data/lib/avo/menu/base_item.rb +0 -25
  378. data/lib/avo/menu/builder.rb +0 -82
  379. data/lib/avo/menu/dashboard.rb +0 -22
  380. data/lib/avo/menu/group.rb +0 -2
  381. data/lib/avo/menu/link.rb +0 -6
  382. data/lib/avo/menu/menu.rb +0 -2
  383. data/lib/avo/menu/resource.rb +0 -22
  384. data/lib/avo/menu/section.rb +0 -2
  385. data/lib/avo/panel.rb +0 -24
  386. data/lib/avo/panel_builder.rb +0 -25
  387. data/lib/avo/resources/controls/action.rb +0 -38
  388. data/lib/avo/resources/controls/execution_context.rb +0 -58
  389. data/lib/avo/resources/controls/items_holder.rb +0 -19
  390. data/lib/avo/resources/controls/link_to.rb +0 -27
  391. data/lib/avo/row.rb +0 -26
  392. data/lib/avo/row_builder.rb +0 -24
  393. data/lib/avo/services/authorization_clients/nil_client.rb +0 -37
  394. data/lib/avo/services/authorization_clients/pundit_client.rb +0 -51
  395. data/lib/avo/sidebar.rb +0 -30
  396. data/lib/avo/sidebar_builder.rb +0 -24
  397. data/lib/avo/tab.rb +0 -72
  398. data/lib/avo/tab_builder.rb +0 -25
  399. data/lib/avo/tab_group.rb +0 -42
  400. data/lib/avo/tab_group_builder.rb +0 -43
  401. data/lib/avo/tools_manager.rb +0 -11
  402. data/lib/generators/avo/card/chartkick_generator.rb +0 -18
  403. data/lib/generators/avo/card/metric_generator.rb +0 -18
  404. data/lib/generators/avo/card/partial_generator.rb +0 -19
  405. data/lib/generators/avo/templates/js/avo.custom.js +0 -2
  406. data/lib/generators/avo/templates/standalone_action.tt +0 -8
  407. /data/app/assets/stylesheets/css/{tags.css → fields/tags.css} +0 -0
@@ -3,53 +3,64 @@ module Avo
3
3
  extend ActiveSupport::DescendantsTracker
4
4
 
5
5
  include ActionView::Helpers::UrlHelper
6
- include Avo::Concerns::HasFields
7
- include Avo::Concerns::CanReplaceFields
8
- include Avo::Concerns::HasEditableControls
6
+ include Avo::Concerns::HasItems
7
+ include Avo::Concerns::CanReplaceItems
8
+ include Avo::Concerns::HasControls
9
9
  include Avo::Concerns::HasStimulusControllers
10
10
  include Avo::Concerns::ModelClassConstantized
11
+ include Avo::Concerns::HasDescription
12
+ include Avo::Concerns::HasHelpers
13
+ include Avo::Concerns::Hydration
11
14
  include Avo::Concerns::Pagination
12
15
 
13
- delegate :view_context, to: ::Avo::App
14
- delegate :current_user, to: ::Avo::App
15
- delegate :params, to: ::Avo::App
16
+ # Avo::Current methods
17
+ delegate :context, to: Avo::Current
18
+ def current_user
19
+ Avo::Current.user
20
+ end
21
+ delegate :params, to: Avo::Current
22
+ delegate :request, to: Avo::Current
23
+ delegate :view_context, to: Avo::Current
24
+
25
+ # view_context methods
16
26
  delegate :simple_format, :content_tag, to: :view_context
17
27
  delegate :main_app, to: :view_context
18
28
  delegate :avo, to: :view_context
19
29
  delegate :resource_path, to: :view_context
20
30
  delegate :resources_path, to: :view_context
31
+
32
+ # I18n methods
21
33
  delegate :t, to: ::I18n
22
- delegate :context, to: ::Avo::App
34
+
35
+ # class methods
36
+ delegate :class_name, to: :class
37
+ delegate :route_key, to: :class
38
+ delegate :singular_route_key, to: :class
23
39
 
24
40
  attr_accessor :view
25
41
  attr_accessor :reflection
26
42
  attr_accessor :user
27
- attr_accessor :params
43
+ attr_accessor :record
28
44
 
29
45
  class_attribute :id, default: :id
30
- class_attribute :title, default: :id
31
- class_attribute :description, default: :id
32
- class_attribute :search_query, default: nil
33
- class_attribute :search_query_help, default: ""
34
- class_attribute :search_result_path
46
+ class_attribute :title
47
+ class_attribute :search, default: {}
35
48
  class_attribute :includes, default: []
36
49
  class_attribute :authorization_policy
37
50
  class_attribute :translation_key
38
51
  class_attribute :default_view_type, default: :table
39
52
  class_attribute :devise_password_optional, default: false
40
- class_attribute :actions_loader
53
+ class_attribute :scopes_loader
41
54
  class_attribute :filters_loader
42
- class_attribute :grid_loader
55
+ class_attribute :view_types
56
+ class_attribute :grid_view
43
57
  class_attribute :visible_on_sidebar, default: true
44
- class_attribute :unscoped_queries_on_index, default: false
45
- class_attribute :resolve_query_scope
46
- class_attribute :resolve_find_scope
47
- # TODO: refactor this into a Host without args
48
- class_attribute :find_record_method, default: ->(model_class:, id:, params:) {
49
- model_class.find id
58
+ class_attribute :index_query, default: -> {
59
+ query
60
+ }
61
+ class_attribute :find_record_method, default: -> {
62
+ query.find id
50
63
  }
51
- class_attribute :ordering
52
- class_attribute :hide_from_global_search, default: false
53
64
  class_attribute :after_create_path, default: :show
54
65
  class_attribute :after_update_path, default: :show
55
66
  class_attribute :record_selector, default: true
@@ -57,60 +68,46 @@ module Avo
57
68
  class_attribute :extra_params
58
69
  class_attribute :link_to_child_resource, default: false
59
70
  class_attribute :map_view
71
+ class_attribute :components, default: {}
72
+
73
+ # EXTRACT:
74
+ class_attribute :ordering
60
75
 
61
76
  class << self
62
77
  delegate :t, to: ::I18n
63
- delegate :context, to: ::Avo::App
64
-
65
- def grid(&block)
66
- grid_collector = GridCollector.new
67
- grid_collector.instance_eval(&block)
68
-
69
- self.grid_loader = grid_collector
70
- end
78
+ delegate :context, to: ::Avo::Current
71
79
 
72
80
  def action(action_class, arguments: {})
73
- self.actions_loader ||= Avo::Loaders::Loader.new
74
-
75
- action = { class: action_class, arguments: arguments }
76
- self.actions_loader.use action
81
+ deprecated_dsl_api __method__, "actions"
77
82
  end
78
83
 
79
84
  def filter(filter_class, arguments: {})
80
- self.filters_loader ||= Avo::Loaders::Loader.new
81
-
82
- filter = { class: filter_class , arguments: arguments }
83
- self.filters_loader.use filter
85
+ deprecated_dsl_api __method__, "filters"
84
86
  end
85
87
 
86
- # This is the search_query scope
87
- # This should be removed and passed to the search block
88
- def scope
89
- query_scope
88
+ def scope(scope_class)
89
+ deprecated_dsl_api __method__, "scopes"
90
90
  end
91
91
 
92
92
  # This resolves the scope when doing "where" queries (not find queries)
93
+ #
94
+ # It's used to apply the authorization feature.
93
95
  def query_scope
94
- final_scope = resolve_query_scope.present? ? resolve_query_scope.call(model_class: model_class) : model_class
95
-
96
- authorization.apply_policy final_scope
96
+ authorization.apply_policy Avo::ExecutionContext.new(
97
+ target: index_query,
98
+ query: model_class
99
+ ).handle
97
100
  end
98
101
 
99
102
  # This resolves the scope when finding records (not "where" queries)
103
+ #
104
+ # It's used to apply the authorization feature.
100
105
  def find_scope
101
- final_scope = resolve_find_scope.present? ? resolve_find_scope.call(model_class: model_class) : model_class
102
-
103
- authorization.apply_policy final_scope
106
+ authorization.apply_policy model_class
104
107
  end
105
108
 
106
109
  def authorization
107
- Avo::Services::AuthorizationService.new Avo::App.current_user, model_class, policy_class: authorization_policy
108
- end
109
-
110
- def order_actions
111
- return {} if ordering.blank?
112
-
113
- ordering.dig(:actions) || {}
110
+ Avo::Services::AuthorizationService.new Avo::Current.user, model_class, policy_class: authorization_policy
114
111
  end
115
112
 
116
113
  def get_record_associations(record)
@@ -134,170 +131,261 @@ module Avo
134
131
  ApplicationRecord.descendants
135
132
  end
136
133
 
137
- def valid_model_class(model_class)
134
+ def get_model_by_name(model_name)
138
135
  get_available_models.find do |m|
139
- m.to_s == model_class.to_s
136
+ m.to_s == model_name.to_s
140
137
  end
141
138
  end
142
- end
143
139
 
144
- def initialize
145
- unless self.class.model_class.present?
146
- if model_class.present? && model_class.respond_to?(:base_class)
147
- self.class.model_class = model_class.base_class
148
- end
140
+ # Returns the model class being used for this resource.
141
+ #
142
+ # The Resource instance has a model_class method too so it can support the STI use cases
143
+ # where we figure out the model class from the record
144
+ def model_class(record_class: nil)
145
+ # get the model class off of the static property
146
+ return @model_class if @model_class.present?
147
+
148
+ # get the model class off of the record for STI models
149
+ return record_class if record_class.present?
150
+
151
+ # generate a model class
152
+ class_name.safe_constantize
149
153
  end
150
- end
151
154
 
152
- def record
153
- @model
154
- end
155
- alias_method :model, :record
155
+ # This is used as the model class ID
156
+ # We use this instead of the route_key to maintain compatibility with uncountable models
157
+ # With uncountable models route key appends an _index suffix (Fish->fish_index)
158
+ # Example: User->users, MediaItem->media_items, Fish->fish
159
+ def model_key
160
+ model_class.model_name.plural
161
+ end
156
162
 
163
+ def class_name
164
+ to_s.demodulize
165
+ end
157
166
 
158
- def hydrate(model: nil, view: nil, user: nil, params: nil)
159
- @view = view if view.present?
160
- @user = user if user.present?
161
- @params = params if params.present?
167
+ def route_key
168
+ class_name.underscore.pluralize
169
+ end
162
170
 
163
- if model.present?
164
- @model = model
171
+ def singular_route_key
172
+ route_key.singularize
173
+ end
165
174
 
166
- hydrate_model_with_default_values if @view == :new
175
+ def translation_key
176
+ @translation_key || "avo.resource_translations.#{class_name.underscore}"
167
177
  end
168
178
 
169
- self
170
- end
179
+ def name
180
+ default = class_name.underscore.humanize
171
181
 
172
- def get_grid_fields
173
- return if self.class.grid_loader.blank?
182
+ if translation_key
183
+ t(translation_key, count: 1, default: default).humanize
184
+ else
185
+ default
186
+ end
187
+ end
188
+ alias_method :singular_name, :name
174
189
 
175
- self.class.grid_loader.hydrate(model: @model, view: @view, resource: self)
176
- end
190
+ def plural_name
191
+ default = name.pluralize
177
192
 
178
- def get_filters
179
- return [] if self.class.filters_loader.blank?
193
+ if translation_key
194
+ t(translation_key, count: 2, default: default).humanize
195
+ else
196
+ default
197
+ end
198
+ end
180
199
 
181
- self.class.filters_loader.bag
182
- end
200
+ def underscore_name
201
+ return @name if @name.present?
183
202
 
184
- def get_filter_arguments(filter_class)
185
- filter = get_filters.find { |filter| filter[:class] == filter_class.constantize }
203
+ name.demodulize.underscore
204
+ end
186
205
 
187
- filter[:arguments]
188
- end
206
+ def navigation_label
207
+ plural_name.humanize
208
+ end
189
209
 
190
- def get_actions
191
- return [] if self.class.actions_loader.blank?
210
+ def find_record(id, query: nil, params: nil)
211
+ Avo::ExecutionContext.new(
212
+ target: find_record_method,
213
+ query: query || find_scope, # If no record is given we'll use the default
214
+ id: id,
215
+ params: params
216
+ ).handle
217
+ end
218
+
219
+ def search_query
220
+ search.dig(:query)
221
+ end
192
222
 
193
- self.class.actions_loader.bag
223
+ def fetch_search(key, record: nil)
224
+ # self.class.fetch_search
225
+ Avo::ExecutionContext.new(target: search[key], resource: self, record: record).handle
226
+ end
194
227
  end
195
228
 
196
- def get_action_arguments(action_class)
197
- action = get_actions.find { |action| action[:class].to_s == action_class.to_s }
229
+ delegate :context, to: ::Avo::Current
230
+ delegate :name, to: :class
231
+ delegate :singular_name, to: :class
232
+ delegate :plural_name, to: :class
233
+ delegate :underscore_name, to: :class
234
+ delegate :underscore_name, to: :class
235
+ delegate :find_record, to: :class
236
+ delegate :model_key, to: :class
237
+ delegate :tab, to: :items_holder
198
238
 
199
- action[:arguments]
200
- end
239
+ def initialize(record: nil, view: nil, user: nil, params: nil)
240
+ @view = Avo::ViewInquirer.new(view) if view.present?
241
+ @user = user if user.present?
242
+ @params = params if params.present?
201
243
 
202
- def default_panel_name
203
- return @params[:related_name].capitalize if @params.present? && @params[:related_name].present?
244
+ if record.present?
245
+ @record = record
204
246
 
205
- case @view
206
- when :show
207
- model_title
208
- when :edit
209
- model_title
210
- when :new
211
- t("avo.create_new_item", item: name.downcase).upcase_first
247
+ hydrate_model_with_default_values if @view&.new?
212
248
  end
213
- end
214
249
 
215
- def class_name_without_resource
216
- self.class.name.demodulize.delete_suffix("Resource")
250
+ unless self.class.model_class.present?
251
+ if model_class.present? && model_class.respond_to?(:base_class)
252
+ self.class.model_class = model_class.base_class
253
+ end
254
+ end
217
255
  end
218
256
 
219
- def model_class
220
- # get the model class off of the static property
221
- return self.class.model_class if self.class.model_class.present?
257
+ def detect_fields
258
+ self.items_holder = Avo::Resources::Items::Holder.new(parent: self)
222
259
 
223
- # get the model class off of the model for STI models
224
- return @model.base_class if @model.present?
260
+ # Used in testing to replace items
261
+ if temporary_items.present?
262
+ instance_eval(&temporary_items)
263
+ else
264
+ fetch_fields
265
+ end
225
266
 
226
- # generate a model class
227
- class_name_without_resource.safe_constantize
267
+ self
228
268
  end
229
269
 
230
- def model_id
231
- @model.send id
232
- end
270
+ VIEW_METHODS_MAPPING = {
271
+ index: [:index_fields, :display_fields],
272
+ show: [:show_fields, :display_fields],
273
+ edit: [:edit_fields, :form_fields],
274
+ update: [:edit_fields, :form_fields],
275
+ new: [:new_fields, :form_fields],
276
+ create: [:new_fields, :form_fields]
277
+ } unless defined? VIEW_METHODS_MAPPING
233
278
 
234
- def model_title
235
- return name if @model.nil?
279
+ def fetch_fields
280
+ possible_methods_for_view = VIEW_METHODS_MAPPING[view.to_sym]
236
281
 
237
- the_title = @model.send title
238
- return the_title if the_title.present?
282
+ # Safe navigation operator is used because the view can be "destroy" or "preview"
283
+ possible_methods_for_view&.each do |method_for_view|
284
+ return send(method_for_view) if respond_to?(method_for_view)
285
+ end
239
286
 
240
- model_id
241
- rescue
242
- name
287
+ fields
243
288
  end
244
289
 
245
- def resource_description
246
- return instance_exec(&self.class.description) if self.class.description.respond_to? :call
290
+ def fields
291
+ # blank fields method
292
+ end
247
293
 
248
- # Show the description only on the resource index view.
249
- # If the user wants to conditionally it on all pages, they should use a block.
250
- if view == :index
251
- return self.class.description if self.class.description.is_a? String
294
+ [:action, :filter, :scope].each do |entity|
295
+ plural_entity = entity.to_s.pluralize
296
+
297
+ # def actions / def filters / def scopes
298
+ define_method plural_entity do
299
+ # blank entity method
252
300
  end
253
- end
254
301
 
255
- def translation_key
256
- return "avo.resource_translations.#{class_name_without_resource.underscore}" if ::Avo::App.translation_enabled
302
+ # def action / def filter / def scope
303
+ define_method entity do |entity_class, arguments: {}|
304
+ entity_loader(entity).use({class: entity_class, arguments: arguments})
305
+ end
257
306
 
258
- self.class.translation_key
259
- end
307
+ # def get_actions / def get_filters / def get_scopes
308
+ define_method "get_#{plural_entity}" do
309
+ return entity_loader(entity).bag if entity_loader(entity).present?
310
+
311
+ instance_variable_set("@#{plural_entity}_loader", Avo::Loaders::Loader.new)
312
+ send plural_entity
260
313
 
261
- def name
262
- default = class_name_without_resource.to_s.gsub('::', ' ').underscore.humanize
314
+ entity_loader(entity).bag
315
+ end
263
316
 
264
- return @name if @name.present?
317
+ # def get_action_arguments / def get_filter_arguments / def get_scope_arguments
318
+ define_method "get_#{entity}_arguments" do |entity_class|
319
+ klass = send("get_#{plural_entity}").find { |entity| entity[:class].to_s == entity_class.to_s }
265
320
 
266
- if translation_key && ::Avo::App.translation_enabled
267
- t(translation_key, count: 1, default: default).humanize
268
- else
269
- default
321
+ raise "Couldn't find '#{entity_class}' in the 'def #{plural_entity}' method on your '#{self.class}' resource." if klass.nil?
322
+
323
+ klass[:arguments]
270
324
  end
271
325
  end
272
326
 
273
- def singular_name
274
- name
327
+ def hydrate(...)
328
+ super(...)
329
+
330
+ if @record.present?
331
+ hydrate_model_with_default_values if @view&.new?
332
+ end
333
+
334
+ self
275
335
  end
276
336
 
277
- def plural_name
278
- default = name.pluralize
337
+ def default_panel_name
338
+ return @params[:related_name].capitalize if @params.present? && @params[:related_name].present?
279
339
 
280
- if translation_key && ::Avo::App.translation_enabled
281
- t(translation_key, count: 2, default: default).humanize
282
- else
283
- default
340
+ case @view.to_sym
341
+ when :show
342
+ record_title
343
+ when :edit
344
+ record_title
345
+ when :new
346
+ t("avo.create_new_item", item: name.humanize(capitalize: false)).upcase_first
284
347
  end
285
348
  end
286
349
 
287
- def underscore_name
288
- return @name if @name.present?
350
+ # Returns the model class being used for this resource.
351
+ #
352
+ # We use the class method as a fallback but we pass it the record too so it can support the STI use cases
353
+ # where we figure out the model class from that record.
354
+ def model_class
355
+ record_class = @record&.class
289
356
 
290
- self.class.name.demodulize.underscore
357
+ self.class.model_class record_class: record_class
291
358
  end
292
359
 
293
- def navigation_label
294
- plural_name.humanize
360
+ def record_title
361
+ return name if @record.nil?
362
+
363
+ # Get the title from the record if title is not set, try to get the name, title or label, or fallback to the id
364
+ return @record.try(:name) || @record.try(:title) || @record.try(:label) || @record.id if title.nil?
365
+
366
+ # If the title is a symbol, get the value from the record else execute the block/string
367
+ case title
368
+ when Symbol
369
+ @record.send title
370
+ when Proc
371
+ Avo::ExecutionContext.new(target: title, resource: self, record: @record).handle
372
+ end
295
373
  end
296
374
 
297
375
  def available_view_types
376
+ if self.class.view_types.present?
377
+ return Array(
378
+ Avo::ExecutionContext.new(
379
+ target: self.class.view_types,
380
+ resource: self,
381
+ record: record
382
+ ).handle
383
+ )
384
+ end
385
+
298
386
  view_types = [:table]
299
387
 
300
- view_types << :grid if get_grid_fields.present?
388
+ view_types << :grid if self.class.grid_view.present?
301
389
  view_types << :map if map_view.present?
302
390
 
303
391
  view_types
@@ -309,7 +397,7 @@ module Avo
309
397
  end
310
398
  end
311
399
 
312
- # Map the received params to their actual fields.
400
+ # Map the received params to their actual fields
313
401
  def fields_by_database_id
314
402
  get_field_definitions
315
403
  .reject do |field|
@@ -321,28 +409,28 @@ module Avo
321
409
  .to_h
322
410
  end
323
411
 
324
- def fill_model(model, params, extra_params: [])
412
+ def fill_record(record, params, extra_params: [])
325
413
  # Write the field values
326
414
  params.each do |key, value|
327
415
  field = fields_by_database_id[key]
328
416
 
329
417
  next unless field.present?
330
418
 
331
- model = field.fill_field model, key, value, params
419
+ record = field.fill_field record, key, value, params
332
420
  end
333
421
 
334
- # Write the user configured extra params to the model
422
+ # Write the user configured extra params to the record
335
423
  if extra_params.present?
336
424
  # Let Rails fill in the rest of the params
337
- model.assign_attributes params.permit(extra_params)
425
+ record.assign_attributes params.permit(extra_params)
338
426
  end
339
427
 
340
- model
428
+ record
341
429
  end
342
430
 
343
431
  def authorization(user: nil)
344
- current_user = user || Avo::App.current_user
345
- Avo::Services::AuthorizationService.new(current_user, model || model_class, policy_class: authorization_policy)
432
+ current_user = user || Avo::Current.user
433
+ Avo::Services::AuthorizationService.new(current_user, record || model_class, policy_class: authorization_policy)
346
434
  end
347
435
 
348
436
  def file_hash
@@ -363,37 +451,37 @@ module Avo
363
451
  Digest::MD5.hexdigest(content_to_be_hashed)
364
452
  end
365
453
 
366
- def cache_hash(parent_model)
367
- if parent_model.present?
368
- [model, file_hash, parent_model]
454
+ def cache_hash(parent_record)
455
+ if parent_record.present?
456
+ [record, file_hash, parent_record]
369
457
  else
370
- [model, file_hash]
458
+ [record, file_hash]
371
459
  end
372
460
  end
373
461
 
374
- # We will not overwrite any attributes that come pre-filled in the model.
462
+ # We will not overwrite any attributes that come pre-filled in the record.
375
463
  def hydrate_model_with_default_values
376
464
  default_values = get_fields
377
465
  .select do |field|
378
- !field.computed
466
+ !field.computed && !field.is_a?(Avo::Fields::HeadingField)
379
467
  end
380
468
  .map do |field|
381
469
  value = field.value
382
470
 
383
471
  if field.type == "belongs_to"
384
472
 
385
- reflection = @model._reflections[@params[:via_relation]]
473
+ reflection = @record._reflections[@params[:via_relation]]
386
474
 
387
475
  if field.polymorphic_as.present? && field.types.map(&:to_s).include?(@params[:via_relation_class])
388
476
  # set the value to the actual record
389
- via_resource = ::Avo::App.get_resource_by_model_name(@params[:via_relation_class])
390
- value = via_resource.find_record(@params[:via_resource_id])
477
+ via_resource = Avo.resource_manager.get_resource_by_model_class(@params[:via_relation_class])
478
+ value = via_resource.find_record(@params[:via_record_id])
391
479
  elsif reflection.present? && reflection.foreign_key.present? && field.id.to_s == @params[:via_relation].to_s
392
- resource = Avo::App.get_resource_by_model_name params[:via_relation_class]
393
- model = resource.find_record @params[:via_resource_id], params: params
480
+ resource = Avo.resource_manager.get_resource_by_model_class params[:via_relation_class]
481
+ record = resource.find_record @params[:via_record_id], params: params
394
482
  id_param = reflection.options[:primary_key] || :id
395
483
 
396
- value = model.send(id_param)
484
+ value = record.send(id_param)
397
485
  end
398
486
  end
399
487
 
@@ -405,26 +493,10 @@ module Avo
405
493
  end
406
494
 
407
495
  default_values.each do |field, value|
408
- field.assign_value record: @model, value: value
496
+ field.assign_value record: @record, value: value
409
497
  end
410
498
  end
411
499
 
412
- def route_key
413
- class_name_without_resource.underscore.pluralize
414
- end
415
-
416
- def singular_route_key
417
- route_key.singularize
418
- end
419
-
420
- # This is used as the model class ID
421
- # We use this instead of the route_key to maintain compatibility with uncountable models
422
- # With uncountable models route key appends an _index suffix (Fish->fish_index)
423
- # Example: User->users, MediaItem->media_items, Fish->fish
424
- def model_key
425
- model_class.model_name.plural
426
- end
427
-
428
500
  def model_name
429
501
  model_class.model_name
430
502
  end
@@ -434,25 +506,13 @@ module Avo
434
506
  end
435
507
 
436
508
  def record_path
437
- resource_path(model: model, resource: self)
509
+ resource_path(record: record, resource: self)
438
510
  end
439
511
 
440
512
  def records_path
441
513
  resources_path(resource: self)
442
514
  end
443
515
 
444
- def label_field
445
- get_field_definitions.find do |field|
446
- field.as_label.present?
447
- end
448
- rescue
449
- nil
450
- end
451
-
452
- def label
453
- label_field&.value || model_title
454
- end
455
-
456
516
  def avatar_field
457
517
  get_field_definitions.find do |field|
458
518
  field.as_avatar.present?
@@ -477,34 +537,34 @@ module Avo
477
537
  nil
478
538
  end
479
539
 
480
- def description_field
481
- get_field_definitions.find do |field|
482
- field.as_description.present?
483
- end
484
- rescue
485
- nil
540
+ def form_scope
541
+ model_class.base_class.to_s.underscore.downcase
486
542
  end
487
543
 
488
- def description
489
- description_field&.value
544
+ def has_record_id?
545
+ record.present? && record_id.present?
490
546
  end
491
547
 
492
- def form_scope
493
- model_class.base_class.to_s.underscore.downcase
548
+ def id_attribute
549
+ :id
494
550
  end
495
551
 
496
- def ordering_host(**args)
497
- Avo::Hosts::Ordering.new resource: self, options: self.class.ordering, **args
552
+ def record_id
553
+ record.send(id_attribute)
498
554
  end
499
555
 
500
- def has_model_id?
501
- model.present? && model.id.present?
556
+ def description_attributes
557
+ {
558
+ view: view,
559
+ resource: self,
560
+ record: record
561
+ }
502
562
  end
503
563
 
504
- def find_record(id, query: nil, params: nil)
505
- query ||= self.class.find_scope
564
+ private
506
565
 
507
- self.class.find_record_method.call(model_class: query, id: id, params: params)
566
+ def entity_loader(entity)
567
+ instance_variable_get("@#{entity.to_s.pluralize}_loader")
508
568
  end
509
569
  end
510
570
  end