reactiveadmin 0.2.0

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 (260) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +88 -0
  3. data/LICENSE +21 -0
  4. data/README.md +81 -0
  5. data/app/assets/reactive_admin/bridge.js +89 -0
  6. data/app/controllers/reactive_admin/api_controller.rb +30 -0
  7. data/app/controllers/reactive_admin/client_errors_controller.rb +38 -0
  8. data/app/controllers/reactive_admin/manifest_controller.rb +10 -0
  9. data/app/controllers/reactive_admin/mcp_controller.rb +48 -0
  10. data/app/controllers/reactive_admin/openapi_controller.rb +13 -0
  11. data/app/controllers/reactive_admin/session_controller.rb +11 -0
  12. data/app/views/layouts/reactive_admin/embed.html.erb +30 -0
  13. data/lib/generators/reactiveadmin/install/install_generator.rb +341 -0
  14. data/lib/generators/reactiveadmin/install/templates/menu.rb.tt +25 -0
  15. data/lib/generators/reactiveadmin/install/templates/reactive_admin.rb.tt +53 -0
  16. data/lib/generators/reactiveadmin/install/templates/reactive_admin_annotated.rb.tt +110 -0
  17. data/lib/reactive_admin/aa/v3/controller.rb +76 -0
  18. data/lib/reactive_admin/aa/v3/forms.rb +29 -0
  19. data/lib/reactive_admin/aa/v3/inputs/filters/typeahead_input.rb +51 -0
  20. data/lib/reactive_admin/aa/v3/inputs/typeahead_input.rb +8 -0
  21. data/lib/reactive_admin/aa/v3/install.rb +36 -0
  22. data/lib/reactive_admin/aa/v3/menu.rb +67 -0
  23. data/lib/reactive_admin/aa/v3/presenters.rb +102 -0
  24. data/lib/reactive_admin/aa/v3/registry.rb +78 -0
  25. data/lib/reactive_admin/aa/v3/views.rb +63 -0
  26. data/lib/reactive_admin/aa/v3.rb +23 -0
  27. data/lib/reactive_admin/aa/v4.rb +59 -0
  28. data/lib/reactive_admin/aa.rb +46 -0
  29. data/lib/reactive_admin/action_items.rb +39 -0
  30. data/lib/reactive_admin/action_links.rb +197 -0
  31. data/lib/reactive_admin/action_safety.rb +19 -0
  32. data/lib/reactive_admin/actions.rb +95 -0
  33. data/lib/reactive_admin/api_errors.rb +116 -0
  34. data/lib/reactive_admin/api_fallback.rb +15 -0
  35. data/lib/reactive_admin/api_guards.rb +445 -0
  36. data/lib/reactive_admin/audit.rb +72 -0
  37. data/lib/reactive_admin/auth/guard.rb +68 -0
  38. data/lib/reactive_admin/auth/token_requests.rb +15 -0
  39. data/lib/reactive_admin/auth.rb +135 -0
  40. data/lib/reactive_admin/authorizer.rb +47 -0
  41. data/lib/reactive_admin/background_requests.rb +33 -0
  42. data/lib/reactive_admin/batch_actions.rb +57 -0
  43. data/lib/reactive_admin/choices.rb +289 -0
  44. data/lib/reactive_admin/client_error.rb +70 -0
  45. data/lib/reactive_admin/composite_keys.rb +12 -0
  46. data/lib/reactive_admin/configuration.rb +221 -0
  47. data/lib/reactive_admin/controller_extension.rb +229 -0
  48. data/lib/reactive_admin/csv_injection.rb +26 -0
  49. data/lib/reactive_admin/date_bound.rb +31 -0
  50. data/lib/reactive_admin/degradation.rb +72 -0
  51. data/lib/reactive_admin/diagnostics.rb +16 -0
  52. data/lib/reactive_admin/doctor.rb +466 -0
  53. data/lib/reactive_admin/dry_run.rb +147 -0
  54. data/lib/reactive_admin/dry_run_flag.rb +18 -0
  55. data/lib/reactive_admin/embed.rb +73 -0
  56. data/lib/reactive_admin/engine.rb +47 -0
  57. data/lib/reactive_admin/error_keys.rb +23 -0
  58. data/lib/reactive_admin/exposure.rb +86 -0
  59. data/lib/reactive_admin/filters.rb +165 -0
  60. data/lib/reactive_admin/fixtures/scrubber.rb +1075 -0
  61. data/lib/reactive_admin/fixtures.rb +161 -0
  62. data/lib/reactive_admin/form_content.rb +78 -0
  63. data/lib/reactive_admin/form_field.rb +279 -0
  64. data/lib/reactive_admin/form_has_many.rb +116 -0
  65. data/lib/reactive_admin/form_lock.rb +71 -0
  66. data/lib/reactive_admin/form_payload.rb +57 -0
  67. data/lib/reactive_admin/form_recorder.rb +192 -0
  68. data/lib/reactive_admin/form_schema.rb +160 -0
  69. data/lib/reactive_admin/frame.rb +97 -0
  70. data/lib/reactive_admin/html_nodes.rb +390 -0
  71. data/lib/reactive_admin/html_policy.rb +338 -0
  72. data/lib/reactive_admin/html_rich.rb +186 -0
  73. data/lib/reactive_admin/implicit_defaults.rb +102 -0
  74. data/lib/reactive_admin/index_options.rb +41 -0
  75. data/lib/reactive_admin/index_payload.rb +259 -0
  76. data/lib/reactive_admin/index_recorder.rb +115 -0
  77. data/lib/reactive_admin/index_views.rb +85 -0
  78. data/lib/reactive_admin/inline_style.rb +125 -0
  79. data/lib/reactive_admin/labels_payload.rb +34 -0
  80. data/lib/reactive_admin/ladder.rb +268 -0
  81. data/lib/reactive_admin/layout_classes.rb +167 -0
  82. data/lib/reactive_admin/legacy_inventory.rb +547 -0
  83. data/lib/reactive_admin/location.rb +22 -0
  84. data/lib/reactive_admin/lookup_audit.rb +30 -0
  85. data/lib/reactive_admin/lookup_payload.rb +41 -0
  86. data/lib/reactive_admin/manifest.rb +36 -0
  87. data/lib/reactive_admin/masked_json.rb +62 -0
  88. data/lib/reactive_admin/masking.rb +100 -0
  89. data/lib/reactive_admin/mcp/access.rb +111 -0
  90. data/lib/reactive_admin/mcp/api.rb +123 -0
  91. data/lib/reactive_admin/mcp/count_tool.rb +22 -0
  92. data/lib/reactive_admin/mcp/layout.rb +175 -0
  93. data/lib/reactive_admin/mcp/output.rb +46 -0
  94. data/lib/reactive_admin/mcp/prompts.rb +111 -0
  95. data/lib/reactive_admin/mcp/server.rb +134 -0
  96. data/lib/reactive_admin/mcp/shapes.rb +164 -0
  97. data/lib/reactive_admin/mcp/tools.rb +386 -0
  98. data/lib/reactive_admin/mcp.rb +53 -0
  99. data/lib/reactive_admin/media_nodes.rb +34 -0
  100. data/lib/reactive_admin/menu.rb +90 -0
  101. data/lib/reactive_admin/menu_overlay.rb +291 -0
  102. data/lib/reactive_admin/node_registry.rb +47 -0
  103. data/lib/reactive_admin/open_api/builder.rb +156 -0
  104. data/lib/reactive_admin/open_api/context.rb +46 -0
  105. data/lib/reactive_admin/open_api/core.rb +51 -0
  106. data/lib/reactive_admin/open_api/operation_ids.rb +18 -0
  107. data/lib/reactive_admin/open_api/page_doc.rb +75 -0
  108. data/lib/reactive_admin/open_api/parts.rb +86 -0
  109. data/lib/reactive_admin/open_api/resource_doc.rb +423 -0
  110. data/lib/reactive_admin/open_api/security.rb +55 -0
  111. data/lib/reactive_admin/open_api/write_schema.rb +104 -0
  112. data/lib/reactive_admin/open_api.rb +41 -0
  113. data/lib/reactive_admin/option_source.rb +36 -0
  114. data/lib/reactive_admin/option_sources.rb +14 -0
  115. data/lib/reactive_admin/options_payload.rb +61 -0
  116. data/lib/reactive_admin/page_controller_extension.rb +112 -0
  117. data/lib/reactive_admin/page_forms.rb +181 -0
  118. data/lib/reactive_admin/page_payload.rb +120 -0
  119. data/lib/reactive_admin/param_normalizer.rb +89 -0
  120. data/lib/reactive_admin/paths.rb +63 -0
  121. data/lib/reactive_admin/permissions.rb +31 -0
  122. data/lib/reactive_admin/provenance.rb +57 -0
  123. data/lib/reactive_admin/query_guard.rb +108 -0
  124. data/lib/reactive_admin/ransack_guard.rb +107 -0
  125. data/lib/reactive_admin/rate_limit.rb +59 -0
  126. data/lib/reactive_admin/reactive_dsl.rb +99 -0
  127. data/lib/reactive_admin/readiness.rb +189 -0
  128. data/lib/reactive_admin/registry.rb +69 -0
  129. data/lib/reactive_admin/resource_meta.rb +120 -0
  130. data/lib/reactive_admin/resource_summary.rb +41 -0
  131. data/lib/reactive_admin/routes.rb +60 -0
  132. data/lib/reactive_admin/row_errors.rb +29 -0
  133. data/lib/reactive_admin/rspec.rb +116 -0
  134. data/lib/reactive_admin/scrubbed_error.rb +22 -0
  135. data/lib/reactive_admin/search.rb +79 -0
  136. data/lib/reactive_admin/server_timing.rb +31 -0
  137. data/lib/reactive_admin/show_payload.rb +88 -0
  138. data/lib/reactive_admin/sidebars.rb +34 -0
  139. data/lib/reactive_admin/site.rb +55 -0
  140. data/lib/reactive_admin/style_report.rb +129 -0
  141. data/lib/reactive_admin/style_sources.rb +83 -0
  142. data/lib/reactive_admin/template_actions.rb +126 -0
  143. data/lib/reactive_admin/template_content.rb +49 -0
  144. data/lib/reactive_admin/template_form.rb +442 -0
  145. data/lib/reactive_admin/test_support.rb +31 -0
  146. data/lib/reactive_admin/typeahead.rb +33 -0
  147. data/lib/reactive_admin/ui/assets.rb +91 -0
  148. data/lib/reactive_admin/ui/client_build.rb +47 -0
  149. data/lib/reactive_admin/ui/helper.rb +24 -0
  150. data/lib/reactive_admin/ui/packaged_client.rb +67 -0
  151. data/lib/reactive_admin/ui/shell.rb +81 -0
  152. data/lib/reactive_admin/ui/switch.rb +38 -0
  153. data/lib/reactive_admin/ui.rb +43 -0
  154. data/lib/reactive_admin/value_payload.rb +147 -0
  155. data/lib/reactive_admin/value_token.rb +36 -0
  156. data/lib/reactive_admin/values.rb +43 -0
  157. data/lib/reactive_admin/version.rb +3 -0
  158. data/lib/reactive_admin/write_audit.rb +60 -0
  159. data/lib/reactive_admin/write_guards.rb +142 -0
  160. data/lib/reactive_admin.rb +153 -0
  161. data/lib/reactiveadmin.rb +1 -0
  162. data/lib/tasks/reactiveadmin.rake +36 -0
  163. data/lib/tasks/reactiveadmin_client.rake +11 -0
  164. data/lib/tasks/reactiveadmin_legacy.rake +7 -0
  165. data/lib/tasks/reactiveadmin_styles.rake +6 -0
  166. data/openapi/core.yaml +1643 -0
  167. data/vendor/client/assets/ActionPage-XUYorI8E.js +1 -0
  168. data/vendor/client/assets/ActionView-BsZFcsgp.js +1 -0
  169. data/vendor/client/assets/CommandPalette-C59HT1ip.js +1 -0
  170. data/vendor/client/assets/DatePicker-DuaK0iMg.js +1 -0
  171. data/vendor/client/assets/DateRangeCalendar-B2BDsG-X.js +1 -0
  172. data/vendor/client/assets/DegradedNotice-DiH5n2DO.js +1 -0
  173. data/vendor/client/assets/FormDialog-pmYl8Eov.js +1 -0
  174. data/vendor/client/assets/FormSkeleton-DuSBZO3C.js +1 -0
  175. data/vendor/client/assets/FrameView-2X8cFvUt.css +1 -0
  176. data/vendor/client/assets/FrameView-zmUeDO8d.js +1 -0
  177. data/vendor/client/assets/GroupOverview-DI5T3k5K.js +1 -0
  178. data/vendor/client/assets/InlineForm-CMEIMgeh.js +1 -0
  179. data/vendor/client/assets/JsonDiff-o7JWr7CH.js +3 -0
  180. data/vendor/client/assets/JsonEditor-D4VXdlEx.js +1 -0
  181. data/vendor/client/assets/JsonView-BrJLDmSN.js +1 -0
  182. data/vendor/client/assets/MobileMenu-GAeFOeEb.js +1 -0
  183. data/vendor/client/assets/Node-SQl61V4K.js +2 -0
  184. data/vendor/client/assets/PageView-C-laNEPZ.js +1 -0
  185. data/vendor/client/assets/ResourceForm-BPjsoCY6.js +1 -0
  186. data/vendor/client/assets/ResourceIndex-COezAw5t.js +3 -0
  187. data/vendor/client/assets/ResourceOrPage-CRZGCY84.js +1 -0
  188. data/vendor/client/assets/ResourceShow-DweRXn18.js +1 -0
  189. data/vendor/client/assets/Segmented-BE9TCbph.js +1 -0
  190. data/vendor/client/assets/Sidebars-CsB9rFqX.js +1 -0
  191. data/vendor/client/assets/breadcrumb-DSA3Tlyd.js +1 -0
  192. data/vendor/client/assets/button-CvZ4_DFC.js +1 -0
  193. data/vendor/client/assets/calendar-BoyMpJIf.js +1 -0
  194. data/vendor/client/assets/check-C5A3J16N.js +1 -0
  195. data/vendor/client/assets/command-CMuk0oAt.js +1 -0
  196. data/vendor/client/assets/dist-CqEI82S_.js +1 -0
  197. data/vendor/client/assets/dist-IW4yX942.js +1 -0
  198. data/vendor/client/assets/editor-yqRLzgsJ.js +2 -0
  199. data/vendor/client/assets/external-link-C2aR4slL.js +1 -0
  200. data/vendor/client/assets/frames-C9gPCc3N.js +1 -0
  201. data/vendor/client/assets/humanize-DtU_Kpr4.js +1 -0
  202. data/vendor/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  203. data/vendor/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  204. data/vendor/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  205. data/vendor/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  206. data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  207. data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  208. data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  209. data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  210. data/vendor/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  211. data/vendor/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  212. data/vendor/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  213. data/vendor/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  214. data/vendor/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  215. data/vendor/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  216. data/vendor/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  217. data/vendor/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  218. data/vendor/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  219. data/vendor/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  220. data/vendor/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  221. data/vendor/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  222. data/vendor/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
  223. data/vendor/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
  224. data/vendor/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
  225. data/vendor/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
  226. data/vendor/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
  227. data/vendor/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
  228. data/vendor/client/assets/index-B51aUaAY.js +43 -0
  229. data/vendor/client/assets/index-Cs9rCoWM.css +2 -0
  230. data/vendor/client/assets/input-DByFmQPa.js +1 -0
  231. data/vendor/client/assets/json-De3PN-R6.css +1 -0
  232. data/vendor/client/assets/json-oTp7Q-d-.js +5 -0
  233. data/vendor/client/assets/media-D4a_En8R.js +1 -0
  234. data/vendor/client/assets/plus-CfJ9vo8X.js +1 -0
  235. data/vendor/client/assets/popover-CDtI9R8Q.js +1 -0
  236. data/vendor/client/assets/purify-G7QKJyJq.js +1 -0
  237. data/vendor/client/assets/query-CCsZN2fa.js +1 -0
  238. data/vendor/client/assets/recent-BrzLwL0D.js +1 -0
  239. data/vendor/client/assets/rich-BQc_q5T7.js +1 -0
  240. data/vendor/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  241. data/vendor/client/assets/select-C43qDA3k.js +1 -0
  242. data/vendor/client/assets/sheet-BPl2n-4n.js +1 -0
  243. data/vendor/client/assets/textarea-BnOphXry.js +1 -0
  244. data/vendor/client/assets/uiMode-z0ZbRV49.js +1 -0
  245. data/vendor/client/assets/uiToggle-DwnRQTH1.js +1 -0
  246. data/vendor/client/assets/useRecordForm-X_DExEP2.js +1 -0
  247. data/vendor/client/assets/useRecordVisit-BRtfMi-q.js +1 -0
  248. data/vendor/client/assets/utils-DwBGbDkG.js +1 -0
  249. data/vendor/client/assets/vendor-calendar-nTZiq9oY.js +1 -0
  250. data/vendor/client/assets/vendor-datefns-BoC6MCnl.js +1 -0
  251. data/vendor/client/assets/vendor-forms-D0h8hG_S.js +55 -0
  252. data/vendor/client/assets/vendor-purify-BXoPR7WT.js +3 -0
  253. data/vendor/client/assets/vendor-query-DZ6APRNI.js +1 -0
  254. data/vendor/client/assets/vendor-react-C1iE8mnY.js +9 -0
  255. data/vendor/client/assets/vendor-router-CI6Vh4k_.js +1 -0
  256. data/vendor/client/assets/vendor-table-DuQ835by.js +4 -0
  257. data/vendor/client/index.html +24 -0
  258. data/vendor/client/manifest.json +867 -0
  259. data/vendor/client/reactiveadmin-client.json +4 -0
  260. metadata +350 -0
@@ -0,0 +1,51 @@
1
+ module ActiveAdmin
2
+ module Inputs
3
+ module Filters
4
+ # Filter counterpart of ActiveAdmin::Inputs::TypeaheadInput; names its param like AA's select filters.
5
+ class TypeaheadInput < ::Formtastic::Inputs::DatalistInput
6
+ include Base
7
+ include ReactiveAdmin::Typeahead::SourceCollection
8
+
9
+ def input_name
10
+ return method if seems_searchable?
11
+
12
+ searchable_method_name + "_eq"
13
+ end
14
+
15
+ def searchable_method_name
16
+ if searchable_has_many_through?
17
+ "#{reflection.through_reflection.name}_#{reflection.foreign_key}"
18
+ else
19
+ name = method.to_s
20
+ name.concat "_#{reflection.association_primary_key}" if reflection_searchable?
21
+ name
22
+ end
23
+ end
24
+
25
+ # Provide the AA translation to the blank input field.
26
+ def include_blank
27
+ I18n.t "active_admin.any" if super
28
+ end
29
+
30
+ def input_html_options_name = "#{object_name}[#{input_name}]"
31
+
32
+ # The field is read from and named after the ransack predicate, not the attribute or association.
33
+ def to_html
34
+ @name = input_html_options[:id].gsub(/_id$/, "")
35
+ input_wrapping { label_html << builder.text_field(input_name, input_html_options) << data_list_html }
36
+ end
37
+
38
+ # Without a source or collection, offer the distinct values of the column.
39
+ def collection
40
+ (!options[:source] && !options[:collection] && column) ? pluck_column : super
41
+ rescue ActiveRecord::QueryCanceled => error
42
+ raise ActiveRecord::QueryCanceled.new "#{error.message.strip} while querying the values for the ActiveAdmin :#{method} filter"
43
+ end
44
+
45
+ def pluck_column = klass.reorder("#{method} asc").distinct.pluck(method)
46
+
47
+ def reflection_searchable? = reflection && !reflection.polymorphic?
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,8 @@
1
+ module Formtastic
2
+ module Inputs
3
+ # A datalist in the classic admin; the API serves the same declaration as a searchable typeahead.
4
+ class TypeaheadInput < DatalistInput
5
+ include ReactiveAdmin::Typeahead::SourceCollection
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,36 @@
1
+ module ReactiveAdmin
2
+ module AA
3
+ module V3
4
+ # Extensions mixed into AA's classes. Idempotent: `to_prepare` runs them again on every reload.
5
+ module Install
6
+ def prepend_display_helper(mod) = prepend_once(::ActiveAdmin::ViewHelpers::DisplayHelper, mod)
7
+
8
+ def prepend_tag(mod) = prepend_once(::Arbre::HTML::Tag, mod)
9
+
10
+ def prepend_csv_builder(*mods) = mods.each { prepend_once(::ActiveAdmin::CSVBuilder, it) }
11
+
12
+ # `dsl` joins the `register_page` block's DSL, `config` the page's registration object.
13
+ def extend_page(dsl:, config:)
14
+ ::ActiveAdmin::PageDSL.include(dsl)
15
+ ::ActiveAdmin::Page.include(config)
16
+ end
17
+
18
+ def extend_resource(dsl:, config:)
19
+ ::ActiveAdmin::ResourceDSL.include(dsl)
20
+ ::ActiveAdmin::Resource.include(config)
21
+ end
22
+
23
+ # Registers the typeahead input for forms and filters and lets selects take a `source:`.
24
+ def install_typeahead(source_collection)
25
+ ::Formtastic::Inputs.autoload(:TypeaheadInput, "reactive_admin/aa/v3/inputs/typeahead_input")
26
+ ::ActiveAdmin::Inputs::Filters.autoload(:TypeaheadInput, "reactive_admin/aa/v3/inputs/filters/typeahead_input")
27
+ [::Formtastic::Inputs::SelectInput, ::ActiveAdmin::Inputs::Filters::SelectInput].each { it.prepend(source_collection) }
28
+ end
29
+
30
+ private
31
+
32
+ def prepend_once(target, mod) = (target.prepend(mod) unless target.include?(mod))
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,67 @@
1
+ module ReactiveAdmin
2
+ module AA
3
+ module V3
4
+ # AA's navigation menus: items carry procs that are evaluated in a view.
5
+ module Menu
6
+ # One menu item with its procs evaluated lazily in the view, in the order the caller asks.
7
+ Entry = Struct.new(:item, :view) do
8
+ def id = item.id
9
+
10
+ def priority = item.priority
11
+
12
+ def display? = evaluate(item.should_display)
13
+
14
+ def url = evaluate(item.url)
15
+
16
+ def label = evaluate(item.label)
17
+
18
+ # The HTTP verb of a link such as logout.
19
+ def http_method = item.html_options[:method]
20
+
21
+ def children = item.items.map { Entry.new(it, view) }
22
+
23
+ private
24
+
25
+ def evaluate(value) = view.render_in_context(view, value)
26
+ end
27
+
28
+ def default_menu = ::ActiveAdmin::DEFAULT_MENU
29
+
30
+ def utility_menu = :utility_navigation
31
+
32
+ # The menu's top-level entries.
33
+ def menu_entries(namespace, name, view) = namespace.fetch_menu(name).items.map { Entry.new(it, view) }
34
+
35
+ # What AA would have listed for a config registered with `menu false`.
36
+ def menu_entry_for(config, view) = Entry.new(::ActiveAdmin::MenuItem.new(config.default_menu_options), view)
37
+
38
+ # AA's menu procs are instance_exec'd in a view that answers these.
39
+ def prepare_menu_view(view, namespace:, user:, authorizer:)
40
+ view.define_singleton_method(:authorized?) { |action, subject = nil| authorizer.authorized?(action, subject) }
41
+ view.define_singleton_method(:current_active_admin_user) { user }
42
+ view.define_singleton_method(:current_active_admin_user?) { !!user }
43
+ view.define_singleton_method(:active_admin_namespace) { namespace }
44
+ end
45
+
46
+ # `belongs_to` moves an entry into the parent's own navigation menu (shown only when nested
47
+ # under it) while leaving `include_in_menu?` true. A Proc names its menu per request, so it counts
48
+ # as the default menu.
49
+ def in_menu?(config)
50
+ name = config.instance_variable_get(:@navigation_menu_name)
51
+ config.include_in_menu? && (name.nil? || name.is_a?(Proc) || name == ::ActiveAdmin::DEFAULT_MENU)
52
+ end
53
+
54
+ # Where a resource sits in the default menu: `{priority:, parent:}` (the immediate parent group's
55
+ # label), or nil when it isn't listed. The parent is read from the built item because AA
56
+ # consumes the option's parent chain while adding it.
57
+ def menu_placement(config)
58
+ return unless in_menu?(config)
59
+
60
+ parent = config.menu_item&.parent
61
+ {priority: config.menu_item_options[:priority],
62
+ parent: (parent.label.to_s if parent.is_a?(::ActiveAdmin::MenuItem) && !parent.label.respond_to?(:call))}
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,102 @@
1
+ module ReactiveAdmin
2
+ module AA
3
+ module V3
4
+ # What a resource or page declares: presenters, filters, scopes, batch actions, action items
5
+ # and sidebars.
6
+ module Presenters
7
+ BUILT_IN_INDEX = %w[Table Grid Blog Block].freeze
8
+
9
+ # The presenter of a page type (`:index`, `:show`, `:form`); for `:index`, `as` picks one of
10
+ # several index views.
11
+ def page_presenter(config, type, as = nil) = as ? config.get_page_presenter(type, as) : config.get_page_presenter(type)
12
+
13
+ # All index presenters: a Hash by `as` when the resource declared several.
14
+ def index_presenters(config) = config.page_presenters[:index]
15
+
16
+ # Built-in index renderers by name; anything else a host passes as `as:` is custom.
17
+ def index_renderers = @index_renderers ||= BUILT_IN_INDEX.to_h { [it.downcase, ::ActiveAdmin::Views.const_get("IndexAs#{it}")] }
18
+
19
+ def index_renderer(as)
20
+ case as
21
+ when Class then as
22
+ when nil then ::ActiveAdmin::Views::IndexAsTable
23
+ else ::ActiveAdmin::Views.const_get("IndexAs#{as.to_s.camelcase}")
24
+ end
25
+ end
26
+
27
+ def index_name(renderer) = renderer.index_name
28
+
29
+ def table_column_class = ::ActiveAdmin::Views::TableFor::Column
30
+
31
+ # A copy of a table column that reads `data` instead (a masked export, say).
32
+ def column_with_data(column, data) = column.dup.tap { it.instance_variable_set(:@data, data) }
33
+
34
+ # No `csv` block: AA would export the id and every content column.
35
+ def default_csv?(config) = config.csv_builder.equal?(config.send(:default_csv_builder))
36
+
37
+ # A builder of its own for one export, so the resource's shared one is never changed. A String
38
+ # names a composite key's id column, which has no attribute to read.
39
+ def csv_builder(config, names)
40
+ ::ActiveAdmin::CSVBuilder.new(resource: config) { names.each { it.is_a?(String) ? column(it, &:to_param) : column(it) } }
41
+ end
42
+
43
+ # AA's parse of an `order` param (`name_desc`), which rewrites keys it doesn't recognise.
44
+ def order_clause(config, order) = config.order_clause.new(config, order)
45
+
46
+ def filters(config) = config.filters
47
+
48
+ def filters_enabled?(config) = config.filters_enabled?
49
+
50
+ def scopes(config) = config.scopes
51
+
52
+ def scope_visible?(view, scope) = view.call_method_or_exec_proc(scope.display_if_block)
53
+
54
+ def scope_name(view, scope) = view.scope_name(scope)
55
+
56
+ # The scope's row count, or nil when it doesn't show one. `chain` is the collection before scoping.
57
+ def scope_count(controller, scope, chain)
58
+ collection_size(scope_chain(controller, scope, chain)) if scope.show_count
59
+ end
60
+
61
+ def batch_actions(config) = config.batch_actions
62
+
63
+ def batch_action_visible?(view, action) = view.call_method_or_proc_on(view, action.display_if_block)
64
+
65
+ def batch_action_title(view, action) = view.render_or_call_method_or_proc_on(view, action.title)
66
+
67
+ def batch_action_confirm(view, action) = view.render_or_call_method_or_proc_on(view, action.confirm)
68
+
69
+ # The `form:` dialog's inputs: `{name => type}`, where a type is an input kind or a list of options.
70
+ def batch_action_inputs(view, action) = view.render_in_context(view, action.inputs)
71
+
72
+ # Items in the order AA lays them out.
73
+ def action_items(config) = config.action_items.each_with_index.sort_by { |item, index| [item.priority, index] }.map(&:first)
74
+
75
+ # The item rendered for a page, or nil when it isn't displayed there.
76
+ def render_action_item(item, page, assigns, view)
77
+ context = arbre_context(assigns, view)
78
+ return unless item.display_on?(page, context)
79
+
80
+ context.insert_tag(::ActiveAdmin::Views::ActionItems, [item])
81
+ context.to_s
82
+ end
83
+
84
+ def sidebar_sections(config) = config.sidebar_sections? ? config.sidebar_sections : []
85
+
86
+ # `{title:, html:}` of a section's contents for an action, or nil when it isn't displayed there.
87
+ def render_sidebar(section, action, assigns, view)
88
+ context = arbre_context(assigns, view)
89
+ return unless section.display_on?(action, context)
90
+
91
+ panel = context.insert_tag(::ActiveAdmin::Views::SidebarSection, section)
92
+ fragment = HtmlPolicy.parse(panel.to_s)
93
+ {title: section.title, html: fragment ? fragment.at_css(".panel_contents")&.inner_html : HtmlPolicy::TOO_COMPLEX}
94
+ end
95
+
96
+ # Row count the way AA's paginator and scope counts take it: ignores select and order, and
97
+ # counts groups.
98
+ def collection_size(relation) = (@collection_helper ||= Object.new.extend(::ActiveAdmin::Helpers::Collection)).collection_size(relation)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,78 @@
1
+ module ReactiveAdmin
2
+ module AA
3
+ module V3
4
+ # Registrations, namespace settings and authorization.
5
+ module Registry
6
+ def namespace(name) = ::ActiveAdmin.application.namespaces[name]
7
+
8
+ # Everything registered in the namespace, resources and pages, as AA's own collection.
9
+ def registrations(namespace) = namespace.resources
10
+
11
+ def resource?(config) = config.is_a?(::ActiveAdmin::Resource)
12
+
13
+ def page?(config) = config.is_a?(::ActiveAdmin::Page)
14
+
15
+ # The resource registered for a model, or nil (pages and unregistered models too).
16
+ def resource_for(namespace, klass)
17
+ config = namespace.resources[klass]
18
+ config if resource?(config)
19
+ end
20
+
21
+ def defined_actions(config) = config.defined_actions
22
+
23
+ # Member and collection actions of a resource, or the actions of a page.
24
+ def custom_actions(config) = page?(config) ? config.page_actions : [*config.member_actions, *config.collection_actions]
25
+
26
+ def root_page_key(namespace) = namespace.root_to.to_s.split("#").first
27
+
28
+ def current_user_method(namespace) = namespace.current_user_method
29
+
30
+ # The adapter class the namespace authorizes with (AA stores a class or its name).
31
+ def authorization_adapter(namespace)
32
+ adapter = namespace.authorization_adapter
33
+ adapter.is_a?(String) ? adapter.constantize : adapter
34
+ end
35
+
36
+ def load_registrations! = ::ActiveAdmin.application.load!
37
+
38
+ def draw_routes(router) = ::ActiveAdmin.routes(router)
39
+
40
+ def on_before_load(&block) = ActiveSupport::Notifications.subscribe(::ActiveAdmin::Application::BeforeLoadEvent) { block.call }
41
+
42
+ # Attributes AA keeps out of default views and forms.
43
+ def filter_attributes = ::ActiveAdmin.application.filter_attributes
44
+
45
+ def display_name_methods = ::ActiveAdmin.application.display_name_methods
46
+
47
+ def default_per_page = ::ActiveAdmin.application.default_per_page
48
+
49
+ def localize_format = ::ActiveAdmin.application.localize_format
50
+
51
+ # The namespace's settings, as its site header evaluates them for a view.
52
+ def site_settings(namespace, view)
53
+ {
54
+ name: namespace.name,
55
+ title: namespace.site_title(view),
56
+ title_link: namespace.site_title_link,
57
+ title_image: namespace.site_title_image(view),
58
+ favicon: namespace.favicon,
59
+ footer: namespace.footer(view),
60
+ comments: !!namespace.try(:comments),
61
+ default_per_page: namespace.default_per_page,
62
+ max_per_page: namespace.max_per_page,
63
+ logout_path: namespace.logout_link_path,
64
+ logout_method: namespace.logout_link_method
65
+ }
66
+ end
67
+
68
+ def site_title(view) = ::ActiveAdmin.application.site_title(view)
69
+
70
+ # A text of the resource's locale scope, such as `:details`.
71
+ def resource_text(config, key) = ::ActiveAdmin::Localizers.resource(config).t(key)
72
+
73
+ # AA's own translations (`active_admin.*`).
74
+ def t(key, **) = I18n.t("active_admin.#{key}", **)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,63 @@
1
+ module ReactiveAdmin
2
+ module AA
3
+ module V3
4
+ # AA's view helpers, Arbre, and the markup of its classic pages.
5
+ module Views
6
+ # Host procs and method names AA evaluates against a subject: `call_on` calls them, `render_or_call`
7
+ # also accepts a string to render, `exec_in` runs a proc in the view.
8
+ def call_on(view, subject, value) = view.call_method_or_proc_on(subject, value)
9
+
10
+ def render_or_call(view, subject, value) = view.render_or_call_method_or_proc_on(subject, value)
11
+
12
+ def exec_in(view, value) = view.call_method_or_exec_proc(value)
13
+
14
+ def render_in_context(view, context, value) = view.render_in_context(context, value)
15
+
16
+ # The attribute's value as AA's tables read it (a method, or a record's association).
17
+ def find_value(view, record, attr) = view.find_value(record, attr)
18
+
19
+ def format_attribute(view, record, attr) = view.format_attribute(record, attr)
20
+
21
+ def pretty_format(view, value) = view.pretty_format(value)
22
+
23
+ def display_name(view, record) = view.display_name(record)
24
+
25
+ # The display name when the resource has a method AA knows, nil where AA would fall back to "Model #id".
26
+ def explicit_display_name(view, record)
27
+ method = view.display_name_method_for(record)
28
+ view.render_in_context(record, method).to_s.strip.presence unless fallback_method?(method)
29
+ end
30
+
31
+ def display_name_fallback?(view, record) = fallback_method?(view.display_name_method_for(record))
32
+
33
+ def plural_many_count = ::ActiveAdmin::Helpers::I18n::PLURAL_MANY_COUNT
34
+
35
+ def arbre_element = ::Arbre::Element
36
+
37
+ def arbre_context(assigns, view) = ::Arbre::Context.new(assigns, view)
38
+
39
+ def arbre_element?(object) = object.is_a?(::Arbre::Element)
40
+
41
+ # Has `tracer` see every tag's `build`, once.
42
+ def trace_arbre_tags(tracer) = (::Arbre::HTML::Tag.prepend(tracer) unless ::Arbre::HTML::Tag.include?(tracer))
43
+
44
+ # Where a classic page keeps its content, and the chrome the embed hides.
45
+ def frame_content_selector = "#main_content"
46
+
47
+ def chrome_selectors = "#header, #footer, #title_bar, .breadcrumb, #sidebar, .flashes"
48
+
49
+ # Stylesheet and script tags of AA's layout, for the embed layout's head.
50
+ def embed_head(view)
51
+ app = ::ActiveAdmin.application
52
+ styles = app.stylesheets.map { |style, options| app.use_webpacker ? view.stylesheet_pack_tag(style, **options) : view.stylesheet_link_tag(style, **options) }
53
+ scripts = app.javascripts.map { |path, options| app.use_webpacker ? view.javascript_pack_tag(path, **options) : view.javascript_include_tag(path, **options) }
54
+ view.safe_join([*styles, *scripts], "\n")
55
+ end
56
+
57
+ private
58
+
59
+ def fallback_method?(method) = method == ::ActiveAdmin::ViewHelpers::DisplayHelper::DISPLAY_NAME_FALLBACK
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,23 @@
1
+ module ReactiveAdmin
2
+ module AA
3
+ # ActiveAdmin 3.5 (activeadmin >= 3.5, < 4). The public methods are the adapter contract;
4
+ # `AA::V4` inherits them and lists what has to change.
5
+ module V3
6
+ require "reactive_admin/aa/v3/registry"
7
+ require "reactive_admin/aa/v3/controller"
8
+ require "reactive_admin/aa/v3/install"
9
+ require "reactive_admin/aa/v3/presenters"
10
+ require "reactive_admin/aa/v3/views"
11
+ require "reactive_admin/aa/v3/menu"
12
+ require "reactive_admin/aa/v3/forms"
13
+
14
+ include Registry
15
+ include Controller
16
+ include Install
17
+ include Presenters
18
+ include Views
19
+ include Menu
20
+ include Forms
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,59 @@
1
+ module ReactiveAdmin
2
+ module AA
3
+ # ActiveAdmin 4 (tested against 4.0.0.beta23), not supported yet: the gemspec stays `< 4`. It
4
+ # inherits V3 for what the AA 4 source shows to be unchanged, implements the small differences, and
5
+ # raises NotImplementedError for the rest, each naming what to build (docs/internal/AA_SOURCE_NOTES.md, 3).
6
+ # The `aa4` CI probe boots the dummy app against it and reports what still fails.
7
+ #
8
+ # Hook names our prepended modules override that differ in AA 4 are not renamed here but through the
9
+ # `format_guard_names` and `layout_hook` methods; the others (`authenticate_active_admin_user`,
10
+ # `dispatch_active_admin_access_denied`, `action_to_permission`, `find_resource`) exist unchanged.
11
+ module V4
12
+ include V3
13
+
14
+ TODO = {
15
+ index_renderers: "IndexAsGrid, IndexAsBlog and IndexAsBlock are gone; only table and custom classes remain",
16
+ index_renderer: "no built-in grid, blog or block renderers; map `as:` to a table or a custom class",
17
+ scope_count: "scopes take `show_count: :async` (Scope#async_count?, AsyncCount); honour it or count synchronously",
18
+ batch_action_inputs: "no `form:` hash or `inputs`; batch actions take `partial:` and `link_html_options:`, so flag them degraded",
19
+ render_action_item: "Views::ActionItems is gone; run the item's block with instance_exec against the context",
20
+ render_sidebar: "Views::SidebarSection is gone; sections are blocks or partials, and `title` is an I18n lookup",
21
+ menu_entries: "menu items evaluate `label(ctx)`, `url(ctx)`, `display?(ctx)` and `items(ctx)`; one nesting level",
22
+ menu_entry_for: "build the item from the config's default menu options for resources registered with `menu false`",
23
+ prepare_menu_view: "the menu API takes the context as an argument instead of reading helpers off the view",
24
+ menu_placement: "`menu_item.parent` is a single level; read the parent through the new item API",
25
+ site_settings: "namespace settings removed (logout link, footer, site_title_image, ...); read what remains, nil for the rest",
26
+ default_download_formats: "`controller.formats` is gone; read the formats from the resource config",
27
+ layout_hook: "the layout is static (`layout \"active_admin\"`); declare a `layout` lambda instead of overriding a method",
28
+ embed_head: "assets come from importmap (`javascript_importmap_tags`, `stylesheet_link_tag \"active_admin\"`), not `application.stylesheets`",
29
+ display_name_fallback?: "`DISPLAY_NAME_FALLBACK` moved with the display helper (ActiveAdmin::DisplayHelper)",
30
+ explicit_display_name: "see display_name_fallback?"
31
+ }.freeze
32
+
33
+ TODO.each do |name, change|
34
+ define_method(name) { |*, **, &| raise NotImplementedError, "ReactiveAdmin::AA::V4##{name}: #{change}" }
35
+ end
36
+
37
+ def format_guard_names = %i[restrict_download_format_access!]
38
+
39
+ # Moved out of AA's Helpers::Collection into IndexHelper.
40
+ def collection_size(relation)
41
+ return relation.count if relation.is_a?(Array)
42
+ return relation.length if relation.limit_value
43
+
44
+ relation = relation.except(:select, :order)
45
+ relation.group_values.present? ? relation.count.count : relation.count
46
+ end
47
+
48
+ # Inlined in AA 4 (no ActiveAdmin::Helpers::I18n::PLURAL_MANY_COUNT).
49
+ def plural_many_count = 2.1
50
+
51
+ # Private in AA 4.
52
+ def find_value(view, record, attr) = view.send(:find_value, record, attr)
53
+
54
+ def frame_content_selector = "[data-test-page-content]"
55
+
56
+ def chrome_selectors = "[data-test-page-header], #main-menu, header"
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,46 @@
1
+ require "active_admin"
2
+
3
+ module ReactiveAdmin
4
+ # The one boundary between this gem and ActiveAdmin's internals: AA constants, private controller
5
+ # and view methods, inherited_resources ivars, Arbre and Formtastic classes. Everything else calls
6
+ # intention-revealing methods here (`AA.scopes(config)`, `AA.resource_ivar(controller)`), so an AA
7
+ # upgrade is a new implementation module, not a hunt through the gem. `aa_boundary_spec` fails when
8
+ # an AA constant appears elsewhere in `lib` or `app`.
9
+ #
10
+ # `V3` implements AA 3.5; `V4` documents what changes for AA 4. The module is picked by
11
+ # `ActiveAdmin::VERSION` when this file loads.
12
+ #
13
+ # Kept outside the boundary on purpose, because hosts and AA itself define them:
14
+ # - the read-only resource and page config API (`resource_class`, `resource_name`, `param_key`,
15
+ # `route_*_path`, `belongs_to_config`, `member_actions`, ...), the same names in AA 4;
16
+ # - names of AA hooks our prepended modules override (`authenticate_active_admin_user`,
17
+ # `dispatch_active_admin_access_denied`, `find_resource`, `process_action`, `format_attribute`, ...),
18
+ # listed per version in `AA::V4`;
19
+ # - the host DSL (`ActiveAdmin.register`, `reactive do ... end`).
20
+ module AA
21
+ autoload :V3, "reactive_admin/aa/v3"
22
+ autoload :V4, "reactive_admin/aa/v4"
23
+
24
+ class << self
25
+ def version = Gem::Version.new(::ActiveAdmin::VERSION)
26
+
27
+ def v4? = version.segments.first >= 4
28
+
29
+ def implementation = v4? ? V4 : V3
30
+ end
31
+
32
+ AccessDenied = ::ActiveAdmin::AccessDenied
33
+
34
+ # Authorization action symbols; the same in AA 3 and 4.
35
+ module Auth
36
+ READ = ::ActiveAdmin::Auth::READ
37
+ NEW = ::ActiveAdmin::Auth::NEW
38
+ CREATE = ::ActiveAdmin::Auth::CREATE
39
+ EDIT = ::ActiveAdmin::Auth::EDIT
40
+ UPDATE = ::ActiveAdmin::Auth::UPDATE
41
+ DESTROY = ::ActiveAdmin::Auth::DESTROY
42
+ end
43
+
44
+ extend implementation
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ module ReactiveAdmin
2
+ # A resource's AA `action_item`s for one page, rendered in the page's view context and walked
3
+ # into header Actions.
4
+ class ActionItems
5
+ def initialize(controller, page, subject: nil)
6
+ @controller = controller
7
+ @page = page
8
+ @config = AA.config_of(controller)
9
+ @view = controller.view_context
10
+ @links = ActionLinks.new(host: controller.request.host, base_url: controller.request.base_url, authorizer: Authorizer.for(controller),
11
+ subject: subject || @config.resource_class)
12
+ end
13
+
14
+ # `generated` are the buttons the client already derives (edit, destroy, ...); AA's default
15
+ # items for them would duplicate those.
16
+ def call(generated = [])
17
+ known = generated.map { signature(it) }
18
+ ordered.flat_map { render(it) }.reject { known.include?(signature(it)) }
19
+ end
20
+
21
+ private
22
+
23
+ def ordered = AA.action_items(@config)
24
+
25
+ def render(item)
26
+ html = AA.render_action_item(item, @page, @controller.view_assigns, @view) or return []
27
+
28
+ ActionLinks.controls(html).each_with_index.filter_map do |el, index|
29
+ @links.action(el, placement: "header", key: index.zero? ? item.name : "#{item.name}_#{index + 1}")
30
+ end
31
+ rescue => e
32
+ Rails.logger.warn("[reactiveadmin] #{@config.resource_name} action item #{item.name} skipped: #{e.class} at #{e.backtrace&.first}")
33
+ Degradation.record(kind: :action_item_dropped, where: "#{@page}/action_item[#{item.name}]", reason: "Action item raised #{e.class}; left out")
34
+ []
35
+ end
36
+
37
+ def signature(action) = [action[:method], action[:href].to_s.split("?").first]
38
+ end
39
+ end