activeadmin 3.4.0 → 4.0.0.beta18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (357) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -102
  3. data/CONTRIBUTING.md +32 -117
  4. data/README.md +17 -30
  5. data/UPGRADING.md +241 -0
  6. data/app/assets/config/active_admin_manifest.js +2 -0
  7. data/{lib → app/controllers}/active_admin/base_controller/authorization.rb +1 -1
  8. data/app/controllers/active_admin/base_controller/menu.rb +39 -0
  9. data/{lib → app/controllers}/active_admin/base_controller.rb +46 -18
  10. data/{lib → app/controllers}/active_admin/page_controller.rb +0 -4
  11. data/{lib → app/controllers}/active_admin/resource_controller/action_builder.rb +1 -1
  12. data/{lib → app/controllers}/active_admin/resource_controller/data_access.rb +11 -6
  13. data/{lib → app/controllers}/active_admin/resource_controller/scoping.rb +1 -1
  14. data/{lib → app/controllers}/active_admin/resource_controller/streaming.rb +4 -4
  15. data/app/controllers/active_admin/resource_controller.rb +102 -0
  16. data/app/helpers/active_admin/auto_link_helper.rb +66 -0
  17. data/app/helpers/active_admin/breadcrumb_helper.rb +41 -0
  18. data/app/helpers/active_admin/display_helper.rb +117 -0
  19. data/app/helpers/active_admin/form_helper.rb +95 -0
  20. data/app/helpers/active_admin/index_helper.rb +40 -0
  21. data/app/helpers/active_admin/layout_helper.rb +63 -0
  22. data/app/javascript/active_admin/features/batch_actions.js +95 -0
  23. data/app/javascript/active_admin/features/dark_mode_toggle.js +37 -0
  24. data/app/javascript/active_admin/features/filters.js +34 -0
  25. data/app/javascript/active_admin/features/has_many.js +28 -0
  26. data/app/javascript/active_admin/features/main_menu.js +12 -0
  27. data/app/javascript/active_admin/features/per_page.js +9 -0
  28. data/app/javascript/active_admin/utils/dom.js +17 -0
  29. data/app/javascript/active_admin.js +10 -0
  30. data/app/views/active_admin/_flash_messages.html.erb +22 -0
  31. data/app/views/active_admin/_html_head.html.erb +13 -0
  32. data/app/views/active_admin/_main_navigation.html.erb +28 -0
  33. data/app/views/active_admin/_page_header.html.erb +27 -0
  34. data/app/views/active_admin/_sidebar.html.erb +5 -0
  35. data/app/views/active_admin/_site_footer.html.erb +7 -0
  36. data/app/views/active_admin/_site_header.html.erb +30 -0
  37. data/app/views/active_admin/devise/confirmations/new.html.erb +5 -3
  38. data/app/views/active_admin/devise/passwords/edit.html.erb +5 -3
  39. data/app/views/active_admin/devise/passwords/new.html.erb +5 -4
  40. data/app/views/active_admin/devise/registrations/new.html.erb +6 -4
  41. data/app/views/active_admin/devise/sessions/new.html.erb +6 -4
  42. data/app/views/active_admin/devise/shared/_links.erb +3 -1
  43. data/app/views/active_admin/devise/unlocks/new.html.erb +6 -4
  44. data/app/views/{kaminari/active_admin_countless → active_admin/kaminari}/_gap.html.erb +3 -1
  45. data/app/views/active_admin/kaminari/_next_page.html.erb +16 -0
  46. data/app/views/active_admin/kaminari/_page.html.erb +14 -0
  47. data/app/views/{kaminari/active_admin_countless → active_admin/kaminari}/_paginator.html.erb +1 -2
  48. data/app/views/active_admin/kaminari/_prev_page.html.erb +16 -0
  49. data/app/views/active_admin/page/index.html.arb +5 -2
  50. data/app/views/active_admin/resource/_active_filters.html.erb +32 -0
  51. data/app/views/active_admin/resource/_batch_actions_dropdown.html.erb +19 -0
  52. data/app/views/active_admin/resource/_form.html.arb +15 -0
  53. data/app/views/active_admin/resource/_form_default.html.arb +11 -0
  54. data/app/views/active_admin/resource/_index_as_table_default.html.arb +8 -0
  55. data/app/views/active_admin/resource/_index_blank_slate.html.erb +14 -0
  56. data/app/views/active_admin/resource/_index_empty_results.html.erb +5 -0
  57. data/app/views/active_admin/resource/_index_table_actions_default.html.erb +9 -0
  58. data/app/views/active_admin/resource/_show_default.html.arb +2 -0
  59. data/app/views/active_admin/resource/edit.html.arb +1 -2
  60. data/app/views/active_admin/resource/index.html.arb +94 -2
  61. data/app/views/active_admin/resource/new.html.arb +1 -2
  62. data/app/views/active_admin/resource/show.html.arb +12 -2
  63. data/app/views/active_admin/shared/_action_items.html.erb +3 -0
  64. data/app/views/active_admin/shared/_download_format_links.html.erb +7 -0
  65. data/app/views/active_admin/shared/_resource_comments.html.erb +51 -0
  66. data/app/views/active_admin/shared/_sidebar_section.html.arb +6 -0
  67. data/app/views/active_admin/shared/_sidebar_sections.html.erb +5 -0
  68. data/app/views/layouts/active_admin.html.erb +20 -0
  69. data/app/views/layouts/active_admin_logged_out.html.erb +8 -45
  70. data/config/importmap.rb +5 -0
  71. data/config/locales/ar.yml +136 -116
  72. data/config/locales/az.yml +103 -118
  73. data/config/locales/bg.yml +91 -99
  74. data/config/locales/bs.yml +95 -101
  75. data/config/locales/ca.yml +131 -86
  76. data/config/locales/cs.yml +82 -90
  77. data/config/locales/da.yml +102 -117
  78. data/config/locales/de.yml +130 -141
  79. data/config/locales/el.yml +94 -106
  80. data/config/locales/en-CA.yml +104 -119
  81. data/config/locales/en-GB.yml +104 -119
  82. data/config/locales/en.yml +134 -140
  83. data/config/locales/eo.yml +107 -123
  84. data/config/locales/es-MX.yml +70 -78
  85. data/config/locales/es.yml +129 -138
  86. data/config/locales/fa.yml +91 -99
  87. data/config/locales/fi.yml +84 -92
  88. data/config/locales/fr.yml +135 -120
  89. data/config/locales/he.yml +103 -118
  90. data/config/locales/hr.yml +95 -103
  91. data/config/locales/hu.yml +76 -81
  92. data/config/locales/id.yml +97 -112
  93. data/config/locales/it.yml +134 -140
  94. data/config/locales/ja.yml +109 -120
  95. data/config/locales/ko.yml +136 -101
  96. data/config/locales/lt.yml +106 -121
  97. data/config/locales/lv.yml +70 -75
  98. data/config/locales/mk.yml +100 -114
  99. data/config/locales/nb.yml +98 -109
  100. data/config/locales/nl.yml +113 -122
  101. data/config/locales/pl.yml +137 -146
  102. data/config/locales/pt-BR.yml +134 -121
  103. data/config/locales/pt-PT.yml +71 -76
  104. data/config/locales/ro.yml +74 -79
  105. data/config/locales/ru.yml +142 -122
  106. data/config/locales/sk.yml +131 -146
  107. data/config/locales/sv-SE.yml +126 -141
  108. data/config/locales/tr.yml +105 -120
  109. data/config/locales/uk.yml +140 -119
  110. data/config/locales/vi.yml +125 -140
  111. data/config/locales/zh-CN.yml +135 -141
  112. data/config/locales/zh-TW.yml +136 -116
  113. data/lib/active_admin/application.rb +6 -14
  114. data/lib/active_admin/application_settings.rb +1 -1
  115. data/lib/active_admin/async_count.rb +23 -0
  116. data/lib/active_admin/batch_actions/controller.rb +1 -4
  117. data/lib/active_admin/batch_actions/resource_extension.rb +8 -15
  118. data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -7
  119. data/lib/active_admin/batch_actions/views/selection_cells.rb +3 -3
  120. data/lib/active_admin/batch_actions.rb +4 -9
  121. data/lib/active_admin/callbacks.rb +6 -4
  122. data/lib/active_admin/collection_decorator.rb +1 -1
  123. data/lib/active_admin/component.rb +0 -1
  124. data/lib/active_admin/csv_builder.rb +2 -2
  125. data/lib/active_admin/devise.rb +3 -3
  126. data/lib/active_admin/dsl.rb +3 -3
  127. data/lib/active_admin/dynamic_settings_node.rb +6 -6
  128. data/lib/active_admin/engine.rb +23 -7
  129. data/lib/active_admin/filters/active.rb +8 -6
  130. data/lib/active_admin/filters/active_filter.rb +2 -10
  131. data/lib/active_admin/filters/forms.rb +1 -45
  132. data/lib/active_admin/filters/resource_extension.rb +18 -10
  133. data/lib/active_admin/filters.rb +5 -7
  134. data/lib/active_admin/form_builder.rb +14 -17
  135. data/lib/active_admin/helpers/optional_display.rb +1 -1
  136. data/lib/active_admin/inputs/filters/base/search_method_select.rb +10 -12
  137. data/lib/active_admin/inputs/filters/base.rb +1 -1
  138. data/lib/active_admin/inputs/filters/check_boxes_input.rb +1 -6
  139. data/lib/active_admin/inputs/filters/date_range_input.rb +4 -2
  140. data/lib/active_admin/inputs.rb +0 -3
  141. data/lib/active_admin/localizers.rb +1 -1
  142. data/lib/active_admin/menu.rb +10 -7
  143. data/lib/active_admin/menu_collection.rb +1 -1
  144. data/lib/active_admin/menu_item.rb +24 -3
  145. data/lib/active_admin/namespace.rb +3 -45
  146. data/lib/active_admin/namespace_settings.rb +3 -36
  147. data/lib/active_admin/order_clause.rb +4 -1
  148. data/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb +4 -76
  149. data/lib/active_admin/orm/active_record/comments/views.rb +2 -2
  150. data/lib/active_admin/orm/active_record/comments.rb +13 -8
  151. data/lib/active_admin/orm/active_record.rb +1 -1
  152. data/lib/active_admin/pundit_adapter.rb +3 -3
  153. data/lib/active_admin/resource/action_items.rb +18 -23
  154. data/lib/active_admin/resource/naming.rb +2 -3
  155. data/lib/active_admin/resource/page_presenters.rb +2 -2
  156. data/lib/active_admin/resource/sidebars.rb +1 -1
  157. data/lib/active_admin/resource.rb +17 -16
  158. data/lib/active_admin/resource_collection.rb +1 -1
  159. data/lib/active_admin/resource_dsl.rb +3 -3
  160. data/lib/active_admin/scope.rb +11 -1
  161. data/lib/active_admin/settings_node.rb +1 -1
  162. data/lib/active_admin/sidebar_section.rb +0 -5
  163. data/lib/active_admin/version.rb +1 -1
  164. data/lib/active_admin/view_helpers/method_or_proc_helper.rb +1 -1
  165. data/lib/active_admin/view_helpers.rb +0 -12
  166. data/lib/active_admin/views/components/active_admin_form.rb +21 -29
  167. data/lib/active_admin/views/components/attributes_table.rb +14 -16
  168. data/lib/active_admin/views/components/index_list.rb +10 -23
  169. data/lib/active_admin/views/components/paginated_collection.rb +34 -39
  170. data/lib/active_admin/views/components/panel.rb +3 -11
  171. data/lib/active_admin/views/components/scopes.rb +39 -26
  172. data/lib/active_admin/views/components/status_tag.rb +22 -19
  173. data/lib/active_admin/views/components/table_for.rb +25 -25
  174. data/lib/active_admin/views/index_as_table.rb +39 -101
  175. data/lib/active_admin.rb +16 -15
  176. data/lib/activeadmin.rb +1 -1
  177. data/lib/generators/active_admin/assets/assets_generator.rb +4 -4
  178. data/lib/generators/active_admin/assets/templates/active_admin.css +3 -0
  179. data/lib/generators/active_admin/assets/templates/tailwind.config.js +21 -0
  180. data/lib/generators/active_admin/devise/devise_generator.rb +2 -2
  181. data/lib/generators/active_admin/install/install_generator.rb +2 -8
  182. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +10 -87
  183. data/lib/generators/active_admin/install/templates/dashboard.rb +8 -25
  184. data/lib/generators/active_admin/page/page_generator.rb +0 -1
  185. data/lib/generators/active_admin/resource/resource_generator.rb +50 -7
  186. data/lib/generators/active_admin/resource/templates/resource.rb.erb +42 -0
  187. data/lib/generators/active_admin/views_generator.rb +18 -0
  188. data/plugin.js +414 -0
  189. data/vendor/bundle/offense.rb +1 -0
  190. data/vendor/javascript/flowbite.js +1 -0
  191. data/vendor/javascript/rails_ujs_esm.js +1 -0
  192. metadata +80 -207
  193. data/app/assets/javascripts/active_admin/base.js +0 -517
  194. data/app/assets/stylesheets/active_admin/_base.scss +0 -57
  195. data/app/assets/stylesheets/active_admin/_forms.scss +0 -315
  196. data/app/assets/stylesheets/active_admin/_header.scss +0 -188
  197. data/app/assets/stylesheets/active_admin/_mixins.scss +0 -1
  198. data/app/assets/stylesheets/active_admin/_normalize.scss +0 -349
  199. data/app/assets/stylesheets/active_admin/_print.scss +0 -287
  200. data/app/assets/stylesheets/active_admin/_typography.scss +0 -100
  201. data/app/assets/stylesheets/active_admin/components/_batch_actions.scss +0 -6
  202. data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +0 -30
  203. data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +0 -20
  204. data/app/assets/stylesheets/active_admin/components/_buttons.scss +0 -6
  205. data/app/assets/stylesheets/active_admin/components/_columns.scss +0 -3
  206. data/app/assets/stylesheets/active_admin/components/_comments.scss +0 -41
  207. data/app/assets/stylesheets/active_admin/components/_date_picker.scss +0 -148
  208. data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +0 -154
  209. data/app/assets/stylesheets/active_admin/components/_flash_messages.scss +0 -37
  210. data/app/assets/stylesheets/active_admin/components/_grid.scss +0 -9
  211. data/app/assets/stylesheets/active_admin/components/_index_list.scss +0 -12
  212. data/app/assets/stylesheets/active_admin/components/_links.scss +0 -5
  213. data/app/assets/stylesheets/active_admin/components/_modal_dialog.scss +0 -34
  214. data/app/assets/stylesheets/active_admin/components/_pagination.scss +0 -58
  215. data/app/assets/stylesheets/active_admin/components/_panels.scss +0 -6
  216. data/app/assets/stylesheets/active_admin/components/_scopes.scss +0 -13
  217. data/app/assets/stylesheets/active_admin/components/_status_tags.scss +0 -12
  218. data/app/assets/stylesheets/active_admin/components/_table_tools.scss +0 -70
  219. data/app/assets/stylesheets/active_admin/components/_tables.scss +0 -112
  220. data/app/assets/stylesheets/active_admin/components/_tabs.scss +0 -68
  221. data/app/assets/stylesheets/active_admin/components/_unsupported_browser.scss +0 -16
  222. data/app/assets/stylesheets/active_admin/mixins/_all.scss +0 -8
  223. data/app/assets/stylesheets/active_admin/mixins/_buttons.scss +0 -65
  224. data/app/assets/stylesheets/active_admin/mixins/_gradients.scss +0 -28
  225. data/app/assets/stylesheets/active_admin/mixins/_rounded.scss +0 -22
  226. data/app/assets/stylesheets/active_admin/mixins/_sections.scss +0 -41
  227. data/app/assets/stylesheets/active_admin/mixins/_shadows.scss +0 -15
  228. data/app/assets/stylesheets/active_admin/mixins/_typography.scss +0 -3
  229. data/app/assets/stylesheets/active_admin/mixins/_utilities.scss +0 -17
  230. data/app/assets/stylesheets/active_admin/mixins/_variables.scss +0 -51
  231. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +0 -44
  232. data/app/assets/stylesheets/active_admin/structure/_footer.scss +0 -19
  233. data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +0 -29
  234. data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +0 -43
  235. data/app/javascript/active_admin/base.js +0 -28
  236. data/app/javascript/active_admin/ext/jquery-ui.js +0 -7
  237. data/app/javascript/active_admin/ext/jquery.js +0 -9
  238. data/app/javascript/active_admin/initializers/batch-actions.js +0 -61
  239. data/app/javascript/active_admin/initializers/checkbox-toggler.js +0 -3
  240. data/app/javascript/active_admin/initializers/datepicker.js +0 -16
  241. data/app/javascript/active_admin/initializers/dropdown-menu.js +0 -9
  242. data/app/javascript/active_admin/initializers/filters.js +0 -10
  243. data/app/javascript/active_admin/initializers/has-many.js +0 -98
  244. data/app/javascript/active_admin/initializers/per-page.js +0 -13
  245. data/app/javascript/active_admin/initializers/table-checkbox-toggler.js +0 -3
  246. data/app/javascript/active_admin/initializers/tabs.js +0 -6
  247. data/app/javascript/active_admin/lib/checkbox-toggler.js +0 -49
  248. data/app/javascript/active_admin/lib/dropdown-menu.js +0 -116
  249. data/app/javascript/active_admin/lib/filters.js +0 -39
  250. data/app/javascript/active_admin/lib/modal-dialog.js +0 -63
  251. data/app/javascript/active_admin/lib/per-page.js +0 -38
  252. data/app/javascript/active_admin/lib/table-checkbox-toggler.js +0 -38
  253. data/app/javascript/active_admin/lib/utils.js +0 -40
  254. data/app/views/kaminari/active_admin/_first_page.html.erb +0 -11
  255. data/app/views/kaminari/active_admin/_gap.html.erb +0 -8
  256. data/app/views/kaminari/active_admin/_last_page.html.erb +0 -11
  257. data/app/views/kaminari/active_admin/_next_page.html.erb +0 -11
  258. data/app/views/kaminari/active_admin/_page.html.erb +0 -12
  259. data/app/views/kaminari/active_admin/_paginator.html.erb +0 -25
  260. data/app/views/kaminari/active_admin/_prev_page.html.erb +0 -11
  261. data/app/views/kaminari/active_admin_countless/_first_page.html.erb +0 -11
  262. data/app/views/kaminari/active_admin_countless/_next_page.html.erb +0 -11
  263. data/app/views/kaminari/active_admin_countless/_page.html.erb +0 -12
  264. data/app/views/kaminari/active_admin_countless/_prev_page.html.erb +0 -11
  265. data/app/views/layouts/active_admin.html.arb +0 -2
  266. data/config/locales/de-CH.yml +0 -94
  267. data/lib/active_admin/abstract_view_factory.rb +0 -48
  268. data/lib/active_admin/asset_registration.rb +0 -30
  269. data/lib/active_admin/base_controller/menu.rb +0 -35
  270. data/lib/active_admin/batch_actions/views/batch_action_selector.rb +0 -59
  271. data/lib/active_admin/filters/active_sidebar.rb +0 -28
  272. data/lib/active_admin/generators/boilerplate.rb +0 -54
  273. data/lib/active_admin/helpers/collection.rb +0 -21
  274. data/lib/active_admin/helpers/i18n.rb +0 -8
  275. data/lib/active_admin/inputs/datepicker_input.rb +0 -28
  276. data/lib/active_admin/inputs/filters/date_picker_input.rb +0 -14
  277. data/lib/active_admin/orm/active_record/comments/show_page_helper.rb +0 -24
  278. data/lib/active_admin/orm/mongoid.rb +0 -2
  279. data/lib/active_admin/resource_controller/sidebars.rb +0 -19
  280. data/lib/active_admin/resource_controller.rb +0 -68
  281. data/lib/active_admin/view_factory.rb +0 -28
  282. data/lib/active_admin/view_helpers/active_admin_application_helper.rb +0 -13
  283. data/lib/active_admin/view_helpers/auto_link_helper.rb +0 -46
  284. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +0 -34
  285. data/lib/active_admin/view_helpers/display_helper.rb +0 -119
  286. data/lib/active_admin/view_helpers/download_format_links_helper.rb +0 -60
  287. data/lib/active_admin/view_helpers/fields_for.rb +0 -51
  288. data/lib/active_admin/view_helpers/flash_helper.rb +0 -15
  289. data/lib/active_admin/view_helpers/form_helper.rb +0 -21
  290. data/lib/active_admin/view_helpers/scope_name_helper.rb +0 -17
  291. data/lib/active_admin/view_helpers/sidebar_helper.rb +0 -16
  292. data/lib/active_admin/view_helpers/title_helper.rb +0 -12
  293. data/lib/active_admin/view_helpers/view_factory_helper.rb +0 -12
  294. data/lib/active_admin/views/action_items.rb +0 -18
  295. data/lib/active_admin/views/components/active_filters_sidebar_content.rb +0 -59
  296. data/lib/active_admin/views/components/blank_slate.rb +0 -18
  297. data/lib/active_admin/views/components/columns.rb +0 -162
  298. data/lib/active_admin/views/components/dropdown_menu.rb +0 -69
  299. data/lib/active_admin/views/components/menu.rb +0 -33
  300. data/lib/active_admin/views/components/menu_item.rb +0 -59
  301. data/lib/active_admin/views/components/sidebar.rb +0 -14
  302. data/lib/active_admin/views/components/sidebar_section.rb +0 -35
  303. data/lib/active_admin/views/components/site_title.rb +0 -55
  304. data/lib/active_admin/views/components/tabs.rb +0 -41
  305. data/lib/active_admin/views/components/unsupported_browser.rb +0 -12
  306. data/lib/active_admin/views/footer.rb +0 -32
  307. data/lib/active_admin/views/header.rb +0 -20
  308. data/lib/active_admin/views/index_as_block.rb +0 -37
  309. data/lib/active_admin/views/index_as_blog.rb +0 -156
  310. data/lib/active_admin/views/index_as_grid.rb +0 -81
  311. data/lib/active_admin/views/pages/base.rb +0 -134
  312. data/lib/active_admin/views/pages/form.rb +0 -65
  313. data/lib/active_admin/views/pages/index.rb +0 -166
  314. data/lib/active_admin/views/pages/layout.rb +0 -27
  315. data/lib/active_admin/views/pages/page.rb +0 -31
  316. data/lib/active_admin/views/pages/show.rb +0 -60
  317. data/lib/active_admin/views/tabbed_navigation.rb +0 -12
  318. data/lib/active_admin/views/title_bar.rb +0 -56
  319. data/lib/generators/active_admin/assets/templates/active_admin.js +0 -1
  320. data/lib/generators/active_admin/assets/templates/active_admin.scss +0 -17
  321. data/lib/generators/active_admin/resource/templates/admin.rb.erb +0 -46
  322. data/lib/generators/active_admin/webpacker/plugins/jquery.js +0 -7
  323. data/lib/generators/active_admin/webpacker/templates/active_admin.js +0 -5
  324. data/lib/generators/active_admin/webpacker/templates/active_admin.scss +0 -17
  325. data/lib/generators/active_admin/webpacker/templates/print.scss +0 -2
  326. data/lib/generators/active_admin/webpacker/webpacker_generator.rb +0 -27
  327. data/vendor/assets/javascripts/jquery-ui/data.js +0 -45
  328. data/vendor/assets/javascripts/jquery-ui/disable-selection.js +0 -51
  329. data/vendor/assets/javascripts/jquery-ui/focusable.js +0 -89
  330. data/vendor/assets/javascripts/jquery-ui/form-reset-mixin.js +0 -83
  331. data/vendor/assets/javascripts/jquery-ui/form.js +0 -25
  332. data/vendor/assets/javascripts/jquery-ui/ie.js +0 -20
  333. data/vendor/assets/javascripts/jquery-ui/keycode.js +0 -51
  334. data/vendor/assets/javascripts/jquery-ui/labels.js +0 -71
  335. data/vendor/assets/javascripts/jquery-ui/plugin.js +0 -49
  336. data/vendor/assets/javascripts/jquery-ui/position.js +0 -513
  337. data/vendor/assets/javascripts/jquery-ui/safe-active-element.js +0 -46
  338. data/vendor/assets/javascripts/jquery-ui/safe-blur.js +0 -27
  339. data/vendor/assets/javascripts/jquery-ui/scroll-parent.js +0 -50
  340. data/vendor/assets/javascripts/jquery-ui/tabbable.js +0 -41
  341. data/vendor/assets/javascripts/jquery-ui/unique-id.js +0 -54
  342. data/vendor/assets/javascripts/jquery-ui/version.js +0 -20
  343. data/vendor/assets/javascripts/jquery-ui/widget.js +0 -758
  344. data/vendor/assets/javascripts/jquery-ui/widgets/button.js +0 -454
  345. data/vendor/assets/javascripts/jquery-ui/widgets/checkboxradio.js +0 -294
  346. data/vendor/assets/javascripts/jquery-ui/widgets/controlgroup.js +0 -304
  347. data/vendor/assets/javascripts/jquery-ui/widgets/datepicker.js +0 -2243
  348. data/vendor/assets/javascripts/jquery-ui/widgets/dialog.js +0 -971
  349. data/vendor/assets/javascripts/jquery-ui/widgets/draggable.js +0 -1268
  350. data/vendor/assets/javascripts/jquery-ui/widgets/mouse.js +0 -241
  351. data/vendor/assets/javascripts/jquery-ui/widgets/resizable.js +0 -1228
  352. data/vendor/assets/javascripts/jquery-ui/widgets/sortable.js +0 -1622
  353. data/vendor/assets/javascripts/jquery-ui/widgets/tabs.js +0 -931
  354. /data/{lib → app/controllers}/active_admin/resource_controller/decorators.rb +0 -0
  355. /data/{lib → app/controllers}/active_admin/resource_controller/polymorphic_routes.rb +0 -0
  356. /data/{lib → app/controllers}/active_admin/resource_controller/resource_class_methods.rb +0 -0
  357. /data/lib/{active_admin/orm/mongoid/.gitkeep → generators/active_admin/assets/templates/builds/.keep} +0 -0
data/UPGRADING.md ADDED
@@ -0,0 +1,241 @@
1
+ # Upgrading Guide
2
+
3
+ ## From v3 to v4 (beta)
4
+
5
+ ActiveAdmin v4 uses Tailwind CSS v3 (with an upgrade to v4 coming soon). It has **mobile web, dark mode and RTL support** with a default theme that can be customized through partials and CSS. This release assumes `cssbundling-rails` and `importmap-rails` is installed and configured in the host app. Partials can be modified to include a different asset library, e.g. shakapacker.
6
+ **IMPORTANT**: there is **no sortable functionality for has-many forms** in this release so if needed, **do not upgrade**. We are [open to community proposals](https://github.com/activeadmin/activeadmin/discussions/new?category=ideas). The add/remove functionality for has-many forms remains supported.
7
+
8
+ These instructions assume the `cssbundling-rails` and `importmap-rails` gems are already installed and you have run their install commands in your app. If you haven't done so, please do before continuing.
9
+
10
+ Update your `Gemfile` with `gem "activeadmin", "4.0.0.beta18"` and then run `gem install activeadmin --pre`.
11
+
12
+ Now, run `rails generate active_admin:assets` to replace the old assets with the new files.
13
+
14
+ Then add the npm package and update the `build:css` script.
15
+
16
+ ```
17
+ yarn add @activeadmin/activeadmin@4.0.0-beta17
18
+ npm pkg set scripts.build:css="tailwindcss -i ./app/assets/stylesheets/active_admin.css -o ./app/assets/builds/active_admin.css --minify -c tailwind-active_admin.config.js"
19
+ ```
20
+
21
+ If you are already using Tailwind in your app, then update the `build:css` script to chain the above command to your existing one, e.g. `"tailwindcss ... && tailwindcss ..."`, so both stylesheets are generated.
22
+
23
+ Many configs have been removed (meta tags, asset registration, utility nav, etc.) that can now be modified more naturally through partials.
24
+
25
+ Open the `config/initializers/active_admin.rb` file and remove these deleted configs.
26
+
27
+ ```
28
+ site_title_link
29
+ site_title_image
30
+ logout_link_method
31
+ favicon
32
+ meta_tags
33
+ meta_tags_for_logged_out_pages
34
+ register_stylesheet
35
+ register_javascript
36
+ head
37
+ footer
38
+ use_webpacker
39
+ ```
40
+
41
+ Now, run `rails g active_admin:views` which will copy the partials to your app so you can customize if needed.
42
+
43
+ Note that the templates can and will change across releases. There are additional partials that can be copied but they are considered private so you do so at your own risk. You will have to keep those up to date per release.
44
+
45
+ **IMPORTANT**: if your project has copied any ActiveAdmin, Devise, or Kaminari templates from earlier releases, those templates must be updated from this release to avoid potential errors. Path helpers in Devise templates may require using the `main_app` proxy. The Kaminari templates have moved to `app/views/active_admin/kaminari`.
46
+
47
+ With the setup complete, please review the Breaking Changes section and resolve any that may or may not impact your integration.
48
+
49
+ **Important template change in 4.0.0.beta16:**
50
+
51
+ - The `_site_header.html.erb` partial has changed its main container class from `sticky` to `fixed`.
52
+ - The main layout for `active_admin.html.erb` now includes the `pt-16` utility class.
53
+
54
+ See [PR #8727](https://github.com/activeadmin/activeadmin/pull/8727) for more details.
55
+
56
+ ### Breaking Changes
57
+ - jQuery and jQuery UI have been removed.
58
+ - The `columns` component has been removed. Use `div`'s with Tailwind classes for modern, responsive layout.
59
+
60
+ <details>
61
+ <summary>Columns Component Migration Alternative</summary>
62
+
63
+ If you did not specify any parameters for `column` and if all you need is equal width columns, then this single component will restore that functionality for any number of columns.
64
+
65
+ ```ruby
66
+ # app/admin/components/columns.rb
67
+ class Columns < ActiveAdmin::Component
68
+ builder_method :columns
69
+
70
+ def build(*args)
71
+ super
72
+ add_class "grid auto-cols-fr grid-flow-col gap-4 mb-4"
73
+ end
74
+
75
+ def column(*args, &block)
76
+ insert_tag Arbre::HTML::Div, *args, &block
77
+ end
78
+ end
79
+ ```
80
+
81
+ Using Tailwind modifiers you can further customize the number of columns for responsive/mobile support.
82
+ </details>
83
+
84
+ - The `tabs` component has been removed. Use a CSS based or third party alternative.
85
+ - Replace `default_main_content` with `render "show_default"`.
86
+
87
+ <details>
88
+ <summary>Show Default Alternative</summary>
89
+
90
+ If block form `default_main_content do ... end` was used or looking for a partial file
91
+ alternative, then replace with existing, public methods.
92
+
93
+ ```ruby
94
+ attributes_table_for(resource) do
95
+ rows *active_admin_config.resource_columns
96
+ row :a
97
+ row :b
98
+ # ...
99
+ end
100
+ active_admin_comments_for(resource) if active_admin_config.comments?
101
+ ```
102
+ </details>
103
+
104
+ - Replace `as: :datepicker` with Formtastic's `as: :date_picker` for native HTML date input.
105
+ - Replace `active_admin_comments` with `active_admin_comments_for(resource)`.
106
+ - In a sidebar section, replace `attributes_table` with `attributes_table_for(resource)`.
107
+ - The `IndexAsBlog`, `IndexAsBlock` and `IndexAsGrid` components have been removed. Please create your own custom index-as components which remain supported.
108
+ - Batch Actions Form DSL has been replaced with Rails partial support so you can supply your own custom form and modal.
109
+
110
+ <details>
111
+ <summary>Batch Action Partial Example</summary>
112
+
113
+ Assuming a Post resource (in the default namespace) with a `mark_published` batch action, we set the partial name and a set of HTML data attributes to trigger a modal using Flowbite which is included by default.
114
+
115
+ Note that you can use any modal JS library you want as long as it can be triggered to open using data attributes. Flowbite usage is not a requirement.
116
+
117
+ ```ruby
118
+ batch_action(
119
+ :mark_published,
120
+ partial: "mark_published_batch_action",
121
+ link_html_options: {
122
+ "data-modal-target": "mark-published-modal",
123
+ "data-modal-show": "mark-published-modal"
124
+ }
125
+ ) do |ids, inputs|
126
+ # ...
127
+ end
128
+ ```
129
+
130
+ In the `app/views/admin/posts` directory, create a `_mark_published_batch_action.html.erb` partial file which will be rendered and included automatically in the posts index admin page.
131
+
132
+ Now add the modal HTML where the `id` attribute must match the data attributes supplied in the `batch_action` example. The form must have an empty `data-batch-action-form` attribute.
133
+
134
+ ```
135
+ <div id="mark-published-modal" class="hidden fixed top-0 ..." aria-hidden="true" ...>
136
+ <!-- ... other modal content --->
137
+ <%= form_tag false, "data-batch-action-form": "" do %>
138
+ <!-- Declare your form inputs. You can use a different form builder too. -->
139
+ <% end %>
140
+ </div>
141
+ ```
142
+
143
+ The `data-batch-action-form` attribute is a hook for a delegated JS event so when you submit the form, it will post and run your batch action block with the supplied form data, functioning as it did before.
144
+ </details>
145
+
146
+ - Deeply nested submenus has been reverted. Only one level nested menu, e.g. `menu parent: "Administrative"`, is supported.
147
+ - Removed `Panel#header_action` method.
148
+ - Removed `index_column` method from index table.
149
+
150
+ <details>
151
+ <summary>Implementation Example</summary>
152
+
153
+ You can re-implement this column with the following:
154
+
155
+ ```ruby
156
+ column "Number", sortable: false do |item|
157
+ @collection.offset_value + @collection.index(item) + 1
158
+ end
159
+ ```
160
+ </details>
161
+ - Using `row 'name'` in an `attributes_table` block, now prints the header text as is. For a localized lookup of the header with titlized fallback, use `row :name` instead. This matches the `column 'name'` behavior of index tables (`TableFor`).
162
+
163
+ #### Resource named methods
164
+
165
+ With the extraction to partials, resource named methods, e.g. `post` or `posts`, used in blocks for `action_item` and `sidebar` will raise an error. You must use the `resource` or `collection` public helper method instead. For example:
166
+
167
+ ```ruby
168
+ action_item :view, if: ->{ post.published? } do link_to(resource) end
169
+ sidebar :author, if: ->{ post.published? }
170
+ # The above must now change to the following:
171
+ action_item :view, if: ->{ resource.published? } do link_to(resource) end
172
+ sidebar :author, if: ->{ resource.published? }
173
+ ```
174
+
175
+ Note that `@post` can also be used here but make sure to call `authorize!` on it if using the authorization feature. The `post` usage would continue to work for `sidebar :name do ... end` content blocks because they can include Arbre but we advise using `resource` or `collection` instead where possible. This may impact other DSL's.
176
+
177
+ ### Visual Related Changes
178
+ - The `sidebar do ... end` contents and the show resource `attributes_table`, are no longer wrapped in a panel so they can be customized.
179
+ - Links in custom `action_item`'s have no default styles. Apply your own or use the library's default `action-item-button` class.
180
+ - The index table `actions dropdown: true` option will be ignored, reverting to original output.
181
+ - An `Arbre::Component` will no longer add a CSS class using the component class name by default.
182
+ - Typographic elements (other than links in main content) [are not styled by default](https://tailwindcss.com/docs/preflight). Use the `@tailwindcss/typography` plugin or apply your own CSS alternative.
183
+
184
+ ### Enhancements
185
+ - Dark mode support.
186
+ - Mobile web support. For responsive `table_for`'s, wrap them in a div with overflow for horizontal scrolling.
187
+ - Customizable admin theme, including main menu and user menu, all through partials.
188
+ - RTL support improved. Now using CSS Logical Properties.
189
+ - Kaminari templates now consolidated into a single set you can customize.
190
+ - Datepicker's now use the native HTML date input. Apply a custom datepicker of your choosing.
191
+ - Batch Actions Form DSL has been replaced with partials and form builder for more customization. Please refer to earlier example.
192
+ - The `status_tag` component now uses unique labels for `false` and `nil` values.
193
+ - Several components: `table_for`, `status_tag`, etc. now use data attributes instead of classes for metadata: status, sort direction, column, etc.
194
+ - Arbre builder methods have been reduced to the minimum so you can use elements or DSLs without clashing e.g. `header`, `footer`, `columns`, etc.
195
+ - The [app-helpers-not-reloading bug has been fixed](https://github.com/activeadmin/activeadmin/pull/8180) and the engine namespace is now isolated.
196
+
197
+ ### Localization Updates
198
+
199
+ This release includes several locale changes. Please [review the en.yml locale](https://github.com/activeadmin/activeadmin/blob/master/config/locales/en.yml) for the latest translations.
200
+
201
+ - Removed keys: `dashboard_welcome`, `dropdown_actions`, `main_content` and `unsupported_browser`.
202
+ - New keys: `toggle_dark_mode`, `toggle_main_navigation_menu`, `toggle_section`, and `toggle_user_menu` have been added.
203
+ - The `active_admin.pagination` keys have been rewritten to be less verbose and include new entries: next and previous.
204
+
205
+ ```diff
206
+ - one: "Displaying <b>1</b> %{model}"
207
+ + one: "Showing <b>1</b> of <b>1</b>"
208
+ - one_page: "Displaying <b>all %{n}</b> %{model}"
209
+ + one_page: "Showing <b>all %{n}</b>"
210
+ - multiple: "Displaying %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> of <b>%{total}</b> in total"
211
+ + multiple: "Showing <b>%{from}-%{to}</b> of <b>%{total}</b>"
212
+ - multiple_without_total: "Displaying %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
213
+ + multiple_without_total: "Showing <b>%{from}-%{to}</b>"
214
+ - per_page: "Per page: "
215
+ + per_page: "Per page "
216
+ + previous: "Previous"
217
+ + next: "Next"
218
+ ```
219
+
220
+ - The `search_status` key contents has multiple, breaking changes:
221
+
222
+ ```diff
223
+ - headline: "Search status:"
224
+ - current_scope: "Scope:"
225
+ - current_filters: "Current filters:"
226
+ + title: "Active Search"
227
+ + title_with_scope: "Active Search for %{name}"
228
+ - no_current_filters: "None"
229
+ + no_current_filters: "No filters applied"
230
+ ```
231
+
232
+ - The value for the `status_tag.unset` key has changed from "No" to "Unknown".
233
+ - The `comments.title_content` text has been updated with an "All " prefix.
234
+ - The `comments.delete_confirmation` text has been fixed to use singular form.
235
+ - The `batch_actions.succesfully_destroyed` key has been renamed to fix a typo.
236
+
237
+ ```diff
238
+ - succesfully_destroyed:
239
+ + successfully_destroyed:
240
+ ```
241
+ - Inconsistent use of login/sign-in related terms so text now uses "Sign in", Sign out", and "Sign up" throughout.
@@ -0,0 +1,2 @@
1
+ //= link_tree ../../javascript .js
2
+ //= link_tree ../../../vendor/javascript .js
@@ -40,7 +40,7 @@ module ActiveAdmin
40
40
  end
41
41
 
42
42
  # Authorize the action and subject. Available in the controller
43
- # as well as all the views. If the action is not allowd, it raises
43
+ # as well as all the views. If the action is not allowed, it raises
44
44
  # an ActiveAdmin::AccessDenied exception.
45
45
  #
46
46
  # @param [Symbol] action The action to check if the user has permission
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module ActiveAdmin
3
+ class BaseController < ::InheritedResources::Base
4
+ module Menu
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ before_action :set_current_menu_item
9
+
10
+ helper_method :current_menu
11
+ helper_method :current_menu_item?
12
+ end
13
+
14
+ protected
15
+
16
+ def current_menu
17
+ active_admin_config.navigation_menu
18
+ end
19
+
20
+ def current_menu_item?(item)
21
+ item.current?(@current_menu_item)
22
+ end
23
+
24
+ def set_current_menu_item
25
+ @current_menu_item = if current_menu && active_admin_config.belongs_to? && parent?
26
+ parent_item = active_admin_config.belongs_to_config.target.menu_item
27
+ if current_menu.include? parent_item
28
+ parent_item
29
+ else
30
+ active_admin_config.menu_item
31
+ end
32
+ else
33
+ active_admin_config.menu_item
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -1,14 +1,17 @@
1
1
  # frozen_string_literal: true
2
- require "active_admin/base_controller/authorization"
3
- require "active_admin/base_controller/menu"
4
-
5
2
  module ActiveAdmin
6
3
  # BaseController for ActiveAdmin.
7
4
  # It implements ActiveAdmin controllers core features.
8
5
  class BaseController < ::InheritedResources::Base
9
- helper ::ActiveAdmin::ViewHelpers
6
+ helper MethodOrProcHelper
7
+ helper LayoutHelper
8
+ helper FormHelper
9
+ helper BreadcrumbHelper
10
+ helper AutoLinkHelper
11
+ helper DisplayHelper
12
+ helper IndexHelper
10
13
 
11
- layout :determine_active_admin_layout
14
+ layout "active_admin"
12
15
 
13
16
  before_action :only_render_implemented_actions
14
17
  before_action :authenticate_active_admin_user
@@ -22,8 +25,8 @@ module ActiveAdmin
22
25
  attr_accessor :active_admin_config
23
26
  end
24
27
 
25
- include Authorization
26
- include Menu
28
+ include BaseController::Authorization
29
+ include BaseController::Menu
27
30
 
28
31
  private
29
32
 
@@ -61,22 +64,47 @@ module ActiveAdmin
61
64
 
62
65
  ACTIVE_ADMIN_ACTIONS = [:index, :show, :new, :create, :edit, :update, :destroy]
63
66
 
64
- # Determine which layout to use.
65
- #
66
- # 1. If we're rendering a standard Active Admin action, we want layout(false)
67
- # because these actions are subclasses of the Base page (which implements
68
- # all the required layout code)
69
- # 2. If we're rendering a custom action, we'll use the active_admin layout so
70
- # that users can render any template inside Active Admin.
71
- def determine_active_admin_layout
72
- ACTIVE_ADMIN_ACTIONS.include?(params[:action].to_sym) ? false : "active_admin"
73
- end
74
-
75
67
  def active_admin_root
76
68
  controller, action = active_admin_namespace.root_to.split "#"
77
69
  { controller: controller, action: action }
78
70
  end
79
71
 
72
+ def page_presenter
73
+ active_admin_config.get_page_presenter(params[:action].to_sym) || default_page_presenter
74
+ end
75
+ helper_method :page_presenter
76
+
77
+ def default_page_presenter
78
+ PagePresenter.new
79
+ end
80
+
81
+ def page_title
82
+ if page_presenter[:title]
83
+ helpers.render_or_call_method_or_proc_on(self, page_presenter[:title])
84
+ else
85
+ default_page_title
86
+ end
87
+ end
88
+ helper_method :page_title
89
+
90
+ def default_page_title
91
+ active_admin_config.name
92
+ end
93
+
94
+ DEFAULT_DOWNLOAD_FORMATS = [:csv, :xml, :json]
95
+
96
+ def build_download_formats(download_links)
97
+ download_links = instance_exec(&download_links) if download_links.is_a?(Proc)
98
+ if download_links.is_a?(Array) && !download_links.empty?
99
+ download_links
100
+ elsif download_links == false
101
+ []
102
+ else
103
+ DEFAULT_DOWNLOAD_FORMATS
104
+ end
105
+ end
106
+ helper_method :build_download_formats
107
+
80
108
  ActiveSupport.run_load_hooks(:active_admin_controller, self)
81
109
  end
82
110
  end
@@ -15,10 +15,6 @@ module ActiveAdmin
15
15
  render "active_admin/page/index"
16
16
  end
17
17
 
18
- def clear_page_actions!
19
- active_admin_config.clear_page_actions!
20
- end
21
-
22
18
  private
23
19
 
24
20
  def authorize_access!
@@ -20,7 +20,7 @@ module ActiveAdmin
20
20
  private
21
21
 
22
22
  def remove_action_methods(actions_type)
23
- active_admin_config.public_send("#{actions_type}_actions").each do |action|
23
+ active_admin_config.public_send(:"#{actions_type}_actions").each do |action|
24
24
  remove_method action.name
25
25
  end
26
26
  end
@@ -57,7 +57,7 @@ module ActiveAdmin
57
57
  def find_collection(options = {})
58
58
  collection = scoped_collection
59
59
  collection_applies(options).each do |applyer|
60
- collection = send("apply_#{applyer}", collection)
60
+ collection = send(:"apply_#{applyer}", collection)
61
61
  end
62
62
  collection
63
63
  end
@@ -168,11 +168,16 @@ module ActiveAdmin
168
168
  #
169
169
  # @return [void]
170
170
  def update_resource(object, attributes)
171
- object = assign_attributes(object, attributes)
171
+ status = nil
172
+ ActiveRecord::Base.transaction do
173
+ object = assign_attributes(object, attributes)
172
174
 
173
- run_update_callbacks object do
174
- save_resource(object)
175
+ run_update_callbacks object do
176
+ status = save_resource(object)
177
+ raise ActiveRecord::Rollback unless status
178
+ end
175
179
  end
180
+ status
176
181
  end
177
182
 
178
183
  # Destroys an object from the database and calls appropriate callbacks.
@@ -215,7 +220,7 @@ module ActiveAdmin
215
220
  # Applies any Ransack search methods to the currently scoped collection.
216
221
  # Both `search` and `ransack` are provided, but we use `ransack` to prevent conflicts.
217
222
  def apply_filtering(chain)
218
- @search = chain.ransack(params[:q] || {})
223
+ @search = chain.ransack(params[:q] || {}, auth_object: active_admin_authorization)
219
224
  @search.result
220
225
  end
221
226
 
@@ -231,7 +236,7 @@ module ActiveAdmin
231
236
 
232
237
  def apply_includes(chain)
233
238
  if active_admin_config.includes.any?
234
- chain.includes *active_admin_config.includes
239
+ chain.includes(*active_admin_config.includes)
235
240
  else
236
241
  chain
237
242
  end
@@ -16,7 +16,7 @@ module ActiveAdmin
16
16
  # Collection can be scoped conditionally with an :if or :unless proc.
17
17
  def begin_of_association_chain
18
18
  return nil unless active_admin_config.scope_to?(self)
19
- MethodOrProcHelper.render_in_context(self, active_admin_config.scope_to_method)
19
+ helpers.render_in_context(self, active_admin_config.scope_to_method)
20
20
  end
21
21
 
22
22
  # Overriding from InheritedResources::BaseHelpers
@@ -24,20 +24,20 @@ module ActiveAdmin
24
24
  headers["Last-Modified"] = Time.current.httpdate
25
25
 
26
26
  if ActiveAdmin.application.disable_streaming_in.include? Rails.env
27
- self.response_body = block[String.new]
27
+ self.response_body = block[String.new] # rubocop:disable Performance/UnfreezeString to preserve encoding
28
28
  else
29
- self.response_body = Enumerator.new &block
29
+ self.response_body = Enumerator.new(&block)
30
30
  end
31
31
  end
32
32
 
33
33
  def csv_filename
34
- "#{resource_collection_name.to_s.gsub('_', '-')}-#{Time.zone.now.to_date.to_s}.csv"
34
+ "#{resource_collection_name.to_s.tr('_', '-')}-#{Time.zone.now.to_date}.csv"
35
35
  end
36
36
 
37
37
  def stream_csv
38
38
  headers["Content-Type"] = "text/csv; charset=utf-8" # In Rails 5 it's set to HTML??
39
39
  headers["Content-Disposition"] = %{attachment; filename="#{csv_filename}"}
40
- stream_resource &active_admin_config.csv_builder.method(:build).to_proc.curry[self]
40
+ stream_resource(&active_admin_config.csv_builder.method(:build).to_proc.curry[self])
41
41
  end
42
42
 
43
43
  end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+ require "active_admin/collection_decorator"
3
+
4
+ module ActiveAdmin
5
+ # All Resources Controller inherits from this controller.
6
+ # It implements actions and helpers for resources.
7
+ class ResourceController < BaseController
8
+ respond_to :html, :xml, :json
9
+ respond_to :csv, only: :index
10
+
11
+ before_action :restrict_download_format_access!, only: [:index, :show]
12
+
13
+ include ResourceController::ActionBuilder
14
+ include ResourceController::Decorators
15
+ include ResourceController::DataAccess
16
+ include ResourceController::PolymorphicRoutes
17
+ include ResourceController::Scoping
18
+ include ResourceController::Streaming
19
+ extend ResourceClassMethods
20
+
21
+ def self.active_admin_config=(config)
22
+ if @active_admin_config = config
23
+ defaults resource_class: config.resource_class,
24
+ route_prefix: config.route_prefix,
25
+ instance_name: config.resource_name.singular
26
+ end
27
+ end
28
+
29
+ # Inherited Resources uses the `self.inherited(base)` hook to add
30
+ # in `self.resource_class`. To override it, we need to install
31
+ # our resource_class method each time we're inherited from.
32
+ def self.inherited(base)
33
+ super(base)
34
+ base.override_resource_class_methods!
35
+ end
36
+
37
+ private
38
+
39
+ def page_presenter
40
+ case params[:action].to_sym
41
+ when :index
42
+ active_admin_config.get_page_presenter(params[:action], params[:as])
43
+ when :new, :edit, :create, :update
44
+ active_admin_config.get_page_presenter(:form)
45
+ end || super
46
+ end
47
+
48
+ def default_page_presenter
49
+ case params[:action].to_sym
50
+ when :index
51
+ PagePresenter.new(as: :table)
52
+ when :new, :edit
53
+ PagePresenter.new
54
+ end || super
55
+ end
56
+
57
+ def page_title
58
+ if page_presenter[:title]
59
+ case params[:action].to_sym
60
+ when :index
61
+ case page_presenter[:title]
62
+ when Symbol, Proc
63
+ instance_exec(&page_presenter[:title])
64
+ else
65
+ page_presenter[:title]
66
+ end
67
+ else
68
+ helpers.render_or_call_method_or_proc_on(resource, page_presenter[:title])
69
+ end
70
+ else
71
+ default_page_title
72
+ end
73
+ end
74
+
75
+ def default_page_title
76
+ case params[:action].to_sym
77
+ when :index
78
+ active_admin_config.plural_resource_label
79
+ when :show
80
+ helpers.display_name(resource)
81
+ when :new, :edit, :create, :update
82
+ normalized_action = params[:action]
83
+ normalized_action = 'new' if normalized_action == 'create'
84
+ normalized_action = 'edit' if normalized_action == 'update'
85
+
86
+ ActiveAdmin::Localizers.resource(active_admin_config).t("#{normalized_action}_model")
87
+ else
88
+ I18n.t("active_admin.#{params[:action]}", default: params[:action].to_s.titleize)
89
+ end
90
+ end
91
+
92
+ def restrict_download_format_access!
93
+ unless request.format.html?
94
+ presenter = active_admin_config.get_page_presenter(:index)
95
+ download_formats = (presenter || {}).fetch(:download_links, active_admin_config.namespace.download_links)
96
+ unless build_download_formats(download_formats).include?(request.format.symbol)
97
+ raise ActiveAdmin::AccessDenied.new(current_active_admin_user, :index)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+ module ActiveAdmin
3
+ module AutoLinkHelper
4
+ # Automatically links objects to their resource controllers. If
5
+ # the resource has not been registered, a string representation of
6
+ # the object is returned.
7
+ #
8
+ # The default content in the link is returned from ActiveAdmin::DisplayHelper#display_name
9
+ #
10
+ # You can pass in the content to display
11
+ # eg: auto_link(@post, "My Link")
12
+ #
13
+ def auto_link(resource, content = display_name(resource), **html_options)
14
+ if url = auto_url_for(resource)
15
+ link_to content, url, html_options
16
+ else
17
+ content
18
+ end
19
+ end
20
+
21
+ # Like `auto_link`, except that it only returns a URL for the resource
22
+ def auto_url_for(resource)
23
+ config = active_admin_resource_for(resource.class)
24
+ return unless config
25
+
26
+ if config.controller.action_methods.include?("show") &&
27
+ authorized?(ActiveAdmin::Auth::READ, resource)
28
+ url_for config.route_instance_path resource, url_options
29
+ elsif config.controller.action_methods.include?("edit") &&
30
+ authorized?(ActiveAdmin::Auth::EDIT, resource)
31
+ url_for config.route_edit_instance_path resource, url_options
32
+ end
33
+ end
34
+
35
+ def new_action_authorized?(resource_or_class)
36
+ controller.action_methods.include?("new") && authorized?(ActiveAdmin::Auth::NEW, resource_or_class)
37
+ end
38
+
39
+ def show_action_authorized?(resource_or_class)
40
+ controller.action_methods.include?("show") && authorized?(ActiveAdmin::Auth::READ, resource_or_class)
41
+ end
42
+
43
+ def edit_action_authorized?(resource_or_class)
44
+ controller.action_methods.include?("edit") && authorized?(ActiveAdmin::Auth::EDIT, resource_or_class)
45
+ end
46
+
47
+ def destroy_action_authorized?(resource_or_class)
48
+ controller.action_methods.include?("destroy") && authorized?(ActiveAdmin::Auth::DESTROY, resource_or_class)
49
+ end
50
+
51
+ def auto_logout_link_path
52
+ render_or_call_method_or_proc_on(self, active_admin_namespace.logout_link_path)
53
+ end
54
+
55
+ private
56
+
57
+ # Returns the ActiveAdmin::Resource instance for a class
58
+ # While `active_admin_namespace` is a helper method, this method seems
59
+ # to exist to otherwise resolve failed component specs using mock_action_view.
60
+ def active_admin_resource_for(klass)
61
+ if respond_to? :active_admin_namespace
62
+ active_admin_namespace.resource_for klass
63
+ end
64
+ end
65
+ end
66
+ end