iron_admin 0.7.0 → 0.8.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 (210) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +129 -1
  3. data/README.md +48 -1
  4. data/UPGRADING.md +495 -8
  5. data/app/assets/tailwind/iron_admin/engine.css +79 -4
  6. data/app/components/iron_admin/dashboards/activity_feed_component/item_component.html.haml +6 -9
  7. data/app/components/iron_admin/dashboards/activity_feed_component.html.haml +6 -5
  8. data/app/components/iron_admin/dashboards/activity_feed_component.rb +21 -24
  9. data/app/components/iron_admin/dashboards/chart_component.html.haml +3 -5
  10. data/app/components/iron_admin/dashboards/chart_component.rb +86 -24
  11. data/app/components/iron_admin/dashboards/concerns/themed_card.rb +39 -0
  12. data/app/components/iron_admin/dashboards/metric_card_component.html.haml +8 -7
  13. data/app/components/iron_admin/dashboards/metric_card_component.rb +2 -0
  14. data/app/components/iron_admin/dashboards/progress_component.html.haml +11 -7
  15. data/app/components/iron_admin/dashboards/progress_component.rb +11 -6
  16. data/app/components/iron_admin/dashboards/quick_links_component/link_component.html.haml +8 -9
  17. data/app/components/iron_admin/dashboards/quick_links_component.html.haml +6 -5
  18. data/app/components/iron_admin/dashboards/quick_links_component.rb +4 -12
  19. data/app/components/iron_admin/dashboards/recent_table_component.html.haml +15 -10
  20. data/app/components/iron_admin/dashboards/recent_table_component.rb +49 -0
  21. data/app/components/iron_admin/dashboards/stats_grid_component/stat_component.html.haml +13 -14
  22. data/app/components/iron_admin/dashboards/stats_grid_component.html.haml +1 -0
  23. data/app/components/iron_admin/dashboards/stats_grid_component.rb +9 -11
  24. data/app/components/iron_admin/filters/bar_component.html.haml +8 -6
  25. data/app/components/iron_admin/filters/bar_component.rb +56 -9
  26. data/app/components/iron_admin/filters/control_styles.rb +82 -0
  27. data/app/components/iron_admin/filters/date_range_component.html.haml +9 -4
  28. data/app/components/iron_admin/filters/date_range_component.rb +10 -6
  29. data/app/components/iron_admin/filters/search_component.html.haml +4 -4
  30. data/app/components/iron_admin/filters/search_component.rb +3 -5
  31. data/app/components/iron_admin/filters/select_filter_component.html.haml +1 -1
  32. data/app/components/iron_admin/filters/select_filter_component.rb +5 -16
  33. data/app/components/iron_admin/form/belongs_to_autocomplete_component.html.haml +9 -5
  34. data/app/components/iron_admin/form/belongs_to_autocomplete_component.rb +10 -8
  35. data/app/components/iron_admin/form/belongs_to_component.html.haml +2 -2
  36. data/app/components/iron_admin/form/belongs_to_component.rb +4 -18
  37. data/app/components/iron_admin/form/checkbox_component.rb +2 -3
  38. data/app/components/iron_admin/form/concerns/form_input_behavior.rb +1 -1
  39. data/app/components/iron_admin/form/control_classes.rb +108 -0
  40. data/app/components/iron_admin/form/date_picker_component.rb +3 -7
  41. data/app/components/iron_admin/form/field_wrapper_component.html.haml +3 -3
  42. data/app/components/iron_admin/form/field_wrapper_component.rb +3 -3
  43. data/app/components/iron_admin/form/nested_form_component.html.haml +4 -5
  44. data/app/components/iron_admin/form/nested_form_component.rb +12 -2
  45. data/app/components/iron_admin/form/select_component.html.haml +1 -1
  46. data/app/components/iron_admin/form/select_component.rb +2 -16
  47. data/app/components/iron_admin/form/text_input_component.rb +1 -5
  48. data/app/components/iron_admin/form/textarea_component.rb +1 -5
  49. data/app/components/iron_admin/layout/flash_component.html.haml +1 -1
  50. data/app/components/iron_admin/layout/flash_component.rb +4 -3
  51. data/app/components/iron_admin/layout/navbar_component.html.haml +15 -9
  52. data/app/components/iron_admin/layout/navbar_component.rb +29 -1
  53. data/app/components/iron_admin/layout/shell_component.html.haml +4 -4
  54. data/app/components/iron_admin/layout/shell_component.rb +16 -3
  55. data/app/components/iron_admin/layout/sidebar_component.html.haml +21 -25
  56. data/app/components/iron_admin/layout/sidebar_component.rb +76 -1
  57. data/app/components/iron_admin/layout/theme_switcher_component.html.haml +15 -0
  58. data/app/components/iron_admin/layout/theme_switcher_component.rb +74 -0
  59. data/app/components/iron_admin/resources/actions_component.html.haml +15 -8
  60. data/app/components/iron_admin/resources/actions_component.rb +34 -2
  61. data/app/components/iron_admin/resources/breadcrumb_component.html.haml +3 -3
  62. data/app/components/iron_admin/resources/breadcrumb_component.rb +8 -7
  63. data/app/components/iron_admin/resources/bulk_actions_component.html.haml +9 -8
  64. data/app/components/iron_admin/resources/bulk_actions_component.rb +47 -4
  65. data/app/components/iron_admin/resources/data_table_component.html.haml +15 -15
  66. data/app/components/iron_admin/resources/data_table_component.rb +34 -3
  67. data/app/components/iron_admin/resources/related_list_component.html.haml +7 -7
  68. data/app/components/iron_admin/resources/related_list_component.rb +26 -2
  69. data/app/components/iron_admin/resources/show_field_component.html.haml +3 -3
  70. data/app/components/iron_admin/resources/show_field_component.rb +10 -4
  71. data/app/components/iron_admin/resources/styles.rb +136 -0
  72. data/app/components/iron_admin/ui/alert_component.html.haml +2 -2
  73. data/app/components/iron_admin/ui/alert_component.rb +27 -31
  74. data/app/components/iron_admin/ui/badge_component.rb +40 -20
  75. data/app/components/iron_admin/ui/button_component.rb +37 -11
  76. data/app/components/iron_admin/ui/card_component.rb +3 -3
  77. data/app/components/iron_admin/ui/dropdown_component.html.haml +1 -1
  78. data/app/components/iron_admin/ui/dropdown_component.rb +34 -13
  79. data/app/components/iron_admin/ui/empty_state_component.html.haml +4 -5
  80. data/app/components/iron_admin/ui/empty_state_component.rb +2 -2
  81. data/app/components/iron_admin/ui/modal_component.html.haml +5 -5
  82. data/app/components/iron_admin/ui/modal_component.rb +6 -4
  83. data/app/components/iron_admin/ui/pagination_component.html.haml +14 -14
  84. data/app/components/iron_admin/ui/pagination_component.rb +26 -9
  85. data/app/components/iron_admin/ui/scopes_component.html.haml +2 -2
  86. data/app/components/iron_admin/ui/scopes_component.rb +44 -11
  87. data/app/components/iron_admin/ui/tooltip_component.rb +11 -4
  88. data/app/controllers/iron_admin/application_controller.rb +58 -4
  89. data/app/controllers/iron_admin/audit_controller.rb +30 -6
  90. data/app/controllers/iron_admin/concerns/action_executable.rb +37 -0
  91. data/app/controllers/iron_admin/concerns/assignable_references.rb +149 -0
  92. data/app/controllers/iron_admin/concerns/authorizable.rb +11 -0
  93. data/app/controllers/iron_admin/concerns/blank_password_filterable.rb +21 -0
  94. data/app/controllers/iron_admin/concerns/event_emittable.rb +47 -7
  95. data/app/controllers/iron_admin/concerns/filterable.rb +34 -9
  96. data/app/controllers/iron_admin/concerns/nested_permittable.rb +5 -3
  97. data/app/controllers/iron_admin/concerns/nested_tenant_check.rb +159 -0
  98. data/app/controllers/iron_admin/concerns/polymorphic_references.rb +131 -0
  99. data/app/controllers/iron_admin/concerns/scopeable.rb +54 -7
  100. data/app/controllers/iron_admin/concerns/searchable.rb +3 -3
  101. data/app/controllers/iron_admin/concerns/tenant_assignable.rb +118 -0
  102. data/app/controllers/iron_admin/concerns/tenant_containment.rb +146 -0
  103. data/app/controllers/iron_admin/exports_controller.rb +2 -2
  104. data/app/controllers/iron_admin/imports_controller.rb +1 -1
  105. data/app/controllers/iron_admin/resources_controller.rb +48 -41
  106. data/app/controllers/iron_admin/search_controller.rb +1 -2
  107. data/app/controllers/iron_admin/themes_controller.rb +50 -0
  108. data/app/controllers/iron_admin/tools_controller.rb +58 -5
  109. data/app/helpers/iron_admin/action_form_helper.rb +19 -0
  110. data/app/helpers/iron_admin/application_helper.rb +93 -16
  111. data/app/helpers/iron_admin/assignable_records_helper.rb +32 -0
  112. data/app/helpers/iron_admin/component_overrides_helper.rb +9 -4
  113. data/app/helpers/iron_admin/field_display_helper.rb +88 -43
  114. data/app/helpers/iron_admin/related_records_helper.rb +51 -0
  115. data/app/helpers/iron_admin/theme_helper.rb +56 -46
  116. data/app/javascript/iron_admin/controllers/cp_bulk_select_controller.js +12 -0
  117. data/app/javascript/iron_admin/controllers/cp_chart_controller.js +4 -0
  118. data/app/javascript/iron_admin/controllers/cp_disclosure_controller.js +19 -0
  119. data/app/javascript/iron_admin/controllers/cp_search_shortcut_controller.js +39 -0
  120. data/app/javascript/iron_admin/index.js +4 -0
  121. data/app/views/iron_admin/audit/index.html.haml +78 -81
  122. data/app/views/iron_admin/dashboard/index.html.haml +10 -9
  123. data/app/views/iron_admin/form/_action_field.html.haml +50 -0
  124. data/app/views/iron_admin/form/_nested_row.html.haml +18 -13
  125. data/app/views/iron_admin/imports/new.html.haml +14 -13
  126. data/app/views/iron_admin/imports/preview.html.haml +24 -21
  127. data/app/views/iron_admin/resources/_form.html.haml +70 -68
  128. data/app/views/iron_admin/resources/action_form.html.haml +16 -59
  129. data/app/views/iron_admin/resources/bulk_action_form.html.haml +20 -58
  130. data/app/views/iron_admin/resources/edit.html.haml +3 -3
  131. data/app/views/iron_admin/resources/index.html.haml +87 -74
  132. data/app/views/iron_admin/resources/new.html.haml +2 -2
  133. data/app/views/iron_admin/resources/show.html.haml +53 -41
  134. data/app/views/iron_admin/search/index.html.haml +17 -9
  135. data/app/views/iron_admin/shared/_pagination.html.haml +13 -10
  136. data/app/views/iron_admin/shared/error.html.haml +16 -12
  137. data/app/views/iron_admin/tools/action_form.html.haml +9 -55
  138. data/app/views/iron_admin/tools/show.html.haml +4 -5
  139. data/app/views/layouts/iron_admin/_document_head.html.haml +24 -0
  140. data/app/views/layouts/iron_admin/application.html.haml +4 -17
  141. data/app/views/layouts/iron_admin/minimal.html.haml +7 -0
  142. data/config/importmap.rb +2 -0
  143. data/config/locales/en.yml +23 -0
  144. data/config/routes.rb +1 -0
  145. data/docs/FAQ.md +87 -37
  146. data/docs/README.md +8 -2
  147. data/docs/components/README.md +6 -2
  148. data/docs/components/dashboard-components.md +24 -35
  149. data/docs/components/filter-components.md +44 -92
  150. data/docs/components/form-components.md +16 -32
  151. data/docs/components/resource-components.md +46 -27
  152. data/docs/components/ui-components.md +44 -26
  153. data/docs/getting-started/installation.md +5 -1
  154. data/docs/getting-started/quick-start.md +36 -23
  155. data/docs/guides/authentication.md +182 -42
  156. data/docs/guides/components.md +97 -15
  157. data/docs/guides/custom-adapters.md +24 -4
  158. data/docs/guides/dashboard.md +68 -44
  159. data/docs/guides/export.md +24 -8
  160. data/docs/guides/extending.md +206 -51
  161. data/docs/guides/fields.md +229 -70
  162. data/docs/guides/imports.md +33 -18
  163. data/docs/guides/resources.md +333 -111
  164. data/docs/guides/theming.md +930 -58
  165. data/docs/guides/troubleshooting.md +7 -3
  166. data/docs/plugin-system-design.md +8 -7
  167. data/docs/reference/configuration.md +51 -16
  168. data/docs/reference/routes.md +1 -0
  169. data/docs/reference/theme-properties.md +101 -38
  170. data/lib/generators/iron_admin/install/templates/initializer.rb.tt +7 -2
  171. data/lib/generators/iron_admin/install_audit/templates/create_iron_admin_audit_entries.rb.tt +2 -0
  172. data/lib/iron_admin/action_field.rb +11 -0
  173. data/lib/iron_admin/adapters/active_record.rb +95 -0
  174. data/lib/iron_admin/adapters/base.rb +107 -0
  175. data/lib/iron_admin/adapters/http/query.rb +21 -0
  176. data/lib/iron_admin/adapters/http.rb +84 -4
  177. data/lib/iron_admin/adapters/mongoid.rb +96 -2
  178. data/lib/iron_admin/audit_log.rb +64 -6
  179. data/lib/iron_admin/authentication_warning.rb +31 -0
  180. data/lib/iron_admin/concerns/filter_definable.rb +15 -1
  181. data/lib/iron_admin/concerns/nestable.rb +25 -0
  182. data/lib/iron_admin/concerns/scope_countable.rb +56 -0
  183. data/lib/iron_admin/concerns/soft_deletable.rb +28 -9
  184. data/lib/iron_admin/configuration/components.rb +14 -3
  185. data/lib/iron_admin/configuration/theme/neutral_defaults.rb +179 -0
  186. data/lib/iron_admin/configuration/theme.rb +292 -87
  187. data/lib/iron_admin/configuration.rb +340 -45
  188. data/lib/iron_admin/dashboard.rb +22 -38
  189. data/lib/iron_admin/engine.rb +16 -2
  190. data/lib/iron_admin/errors.rb +3 -0
  191. data/lib/iron_admin/field.rb +78 -17
  192. data/lib/iron_admin/field_inferrer.rb +61 -3
  193. data/lib/iron_admin/field_override_warning.rb +67 -0
  194. data/lib/iron_admin/import/import_preview.rb +56 -7
  195. data/lib/iron_admin/import/importer.rb +91 -14
  196. data/lib/iron_admin/import/tenant_precheck.rb +67 -0
  197. data/lib/iron_admin/plugin/registration.rb +64 -0
  198. data/lib/iron_admin/plugin_registry.rb +3 -2
  199. data/lib/iron_admin/policy.rb +22 -12
  200. data/lib/iron_admin/policy_coverage_warning.rb +46 -0
  201. data/lib/iron_admin/request_context.rb +18 -0
  202. data/lib/iron_admin/resource.rb +218 -77
  203. data/lib/iron_admin/resource_registry.rb +86 -13
  204. data/lib/iron_admin/scope_counts.rb +73 -0
  205. data/lib/iron_admin/tenant_scope.rb +30 -0
  206. data/lib/iron_admin/tool.rb +61 -12
  207. data/lib/iron_admin/tool_context.rb +10 -6
  208. data/lib/iron_admin/version.rb +1 -1
  209. data/lib/iron_admin.rb +29 -2
  210. metadata +37 -7
@@ -3,9 +3,20 @@
3
3
  module IronAdmin
4
4
  module Layout
5
5
  # Renders the sidebar navigation menu.
6
+ #
7
+ # The current page's link gets +aria-current="page"+ and the theme's
8
+ # +sidebar_link_active+ classes. See the theming guide for which pages
9
+ # make each link current.
6
10
  class SidebarComponent < ViewComponent::Base
7
11
  include IronAdmin::ThemeHelper
8
12
 
13
+ # Layout classes of every sidebar link, current or not. Its radius, focus
14
+ # outline and colors come from the theme.
15
+ LINK_CLASSES = "relative flex items-center gap-2.5 px-2.5 py-1.5 text-sm font-medium"
16
+
17
+ # Classes of the icon of a sidebar link.
18
+ ICON_CLASSES = "h-4 w-4 shrink-0"
19
+
9
20
  # @param current_user [Object, nil]
10
21
  def initialize(current_user: nil)
11
22
  @current_user = current_user
@@ -22,9 +33,13 @@ module IronAdmin
22
33
  end
23
34
 
24
35
  # Returns tools grouped by menu group.
36
+ # Tools the current user cannot access are omitted.
25
37
  # @return [Hash{String => Array<Class>}]
26
38
  def grouped_tools
27
- IronAdmin::ToolRegistry.grouped
39
+ IronAdmin::ToolRegistry.grouped.each_with_object({}) do |(group, tools), visible|
40
+ accessible = tools.select { |tool| tool.accessible_by?(@current_user) }
41
+ visible[group] = accessible if accessible.any?
42
+ end
28
43
  end
29
44
 
30
45
  # Returns custom menu items (e.g. from plugins) grouped by menu group.
@@ -36,6 +51,59 @@ module IronAdmin
36
51
  .group_by(&:group)
37
52
  end
38
53
 
54
+ # @api private
55
+ # @param active [Boolean] Whether the link is for the current page
56
+ # @param extra [String] More classes for the link
57
+ # @return [Hash] +link_to+ options: the link classes, plus +aria-current="page"+ when +active+
58
+ def link_options(active, extra = nil)
59
+ classes = [LINK_CLASSES, theme.control_radius, theme.focus_ring, active ? cp_sidebar_link_active : cp_sidebar_link, extra]
60
+ { class: classes.compact_blank.join(" "), aria: { current: ("page" if active) } }
61
+ end
62
+
63
+ # @api private
64
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
65
+ def theme
66
+ IronAdmin.current_theme
67
+ end
68
+
69
+ # @api private
70
+ # @return [String] Classes of the group labels: the theme's label case and color
71
+ def group_label_classes
72
+ "#{theme.label_transform} #{theme.sidebar_group_label}".strip
73
+ end
74
+
75
+ # @api private
76
+ # @return [Boolean] Whether the current page is the dashboard
77
+ def dashboard_active?
78
+ path_parameter(:controller) == "iron_admin/dashboard"
79
+ end
80
+
81
+ # @api private
82
+ # @param resource [Class<IronAdmin::Resource>]
83
+ # @return [Boolean] Whether the current page belongs to +resource+
84
+ def resource_active?(resource)
85
+ path_parameter(:resource_name) == resource.resource_name.to_s
86
+ end
87
+
88
+ # @api private
89
+ # @param tool [Class<IronAdmin::Tool>]
90
+ # @return [Boolean] Whether the current page belongs to +tool+
91
+ def tool_active?(tool)
92
+ path_parameter(:tool_name) == tool.tool_name.to_s
93
+ end
94
+
95
+ # @api private
96
+ # Query strings, fragments and a trailing slash are ignored.
97
+ #
98
+ # @param item [IronAdmin::MenuItem]
99
+ # @return [Boolean] Whether the request's path (or URL, for an absolute item URL) is the item's
100
+ def menu_item_active?(item)
101
+ item_url = item.path.sub(/[?#].*\z/, "").chomp("/")
102
+ request = helpers.request
103
+ current_url = item_url.match?(%r{\A[a-z][a-z\d+.-]*://}i) ? "#{request.base_url}#{request.path}" : request.path
104
+ item_url == current_url.chomp("/")
105
+ end
106
+
39
107
  # @api private
40
108
  # @return [String] Configured admin panel title
41
109
  def title
@@ -47,6 +115,13 @@ module IronAdmin
47
115
  def logo
48
116
  IronAdmin.configuration.logo
49
117
  end
118
+
119
+ private
120
+
121
+ # From the route, not the query string, so +?resource_name=+ cannot mark a link current.
122
+ def path_parameter(name)
123
+ helpers.request.path_parameters[name]&.to_s
124
+ end
50
125
  end
51
126
  end
52
127
  end
@@ -0,0 +1,15 @@
1
+ %details.relative{ data: { controller: "cp-disclosure", action: "keydown->cp-disclosure#closeOnEscape click@document->cp-disclosure#closeOnOutsideClick" } }
2
+ %summary.flex.h-9.w-9.cursor-pointer.list-none.items-center.justify-center{ class: "#{theme.control_radius} #{theme.btn_ghost} #{theme.focus_ring} [&::-webkit-details-marker]:hidden", data: { cp_disclosure_target: "summary" } }
3
+ = heroicon "swatch", variant: :outline, options: { class: "h-5 w-5" }
4
+ %span.sr-only= summary_label
5
+ -# A dropdown surface, like IronAdmin::Ui::DropdownComponent's menu.
6
+ .absolute.right-0.z-40.w-52.origin-top-right.p-1{ class: "mt-1.5 #{theme.popover_background} #{theme.border_width} #{theme.card_border} #{theme.border_radius} #{theme.popover_shadow}" }
7
+ = form_with url: helpers.iron_admin.theme_path, method: :post, data: { turbo: false }, html: { role: "group", "aria-label": menu_label } do
8
+ - if return_path
9
+ = hidden_field_tag :return_to, return_path, id: nil
10
+ - themes.each do |option|
11
+ %button.flex.h-8.w-full.cursor-pointer.items-center.gap-2.px-2.text-left.text-sm{ type: "submit", name: "theme", value: option.name, "aria-pressed": current?(option).to_s, class: "#{theme.control_radius} #{theme.body_text} #{theme.item_hover} #{theme.focus_ring}" }
12
+ %span.h-3.w-3.shrink-0{ "aria-hidden": "true", class: option.swatch }
13
+ %span.flex-1.truncate= option.label
14
+ - if current?(option)
15
+ = heroicon "check", variant: :mini, options: { class: "h-4 w-4 shrink-0", "aria-hidden": "true" }
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IronAdmin
4
+ module Layout
5
+ # Navbar disclosure that switches between the registered themes. Each theme
6
+ # is a submit button of a form posted to {IronAdmin::ThemesController}; the
7
+ # +cp-disclosure+ Stimulus controller closes it on Escape and outside clicks.
8
+ class ThemeSwitcherComponent < ViewComponent::Base
9
+ # @param themes [Array<IronAdmin::Configuration::Theme>] Registered themes, default first
10
+ # @param current_theme [IronAdmin::Configuration::Theme] Theme of the current request
11
+ # @param current_user [Object, nil] Current user
12
+ def initialize(themes:, current_theme:, current_user: nil)
13
+ @themes = themes
14
+ @current_theme = current_theme
15
+ @current_user = current_user
16
+ end
17
+
18
+ # @return [Array<IronAdmin::Configuration::Theme>] Themes offered
19
+ attr_reader :themes
20
+
21
+ # @api private
22
+ # @return [Boolean] Whether there is another theme to switch to
23
+ def render?
24
+ themes.size > 1
25
+ end
26
+
27
+ # @api private
28
+ # @return [IronAdmin::Configuration::Theme] Theme that styles the switcher
29
+ def theme
30
+ @current_theme
31
+ end
32
+
33
+ # @api private
34
+ # @param option [IronAdmin::Configuration::Theme] One of {#themes}
35
+ # @return [Boolean] Whether it is the theme of the current request
36
+ def current?(option)
37
+ option.name == @current_theme.name
38
+ end
39
+
40
+ # @api private
41
+ # @return [String] Accessible name of the disclosure
42
+ def summary_label
43
+ I18n.t("iron_admin.theme_switcher.button_label", theme: @current_theme.label)
44
+ end
45
+
46
+ # @api private
47
+ # @return [String] Accessible name of the list of themes
48
+ def menu_label
49
+ I18n.t("iron_admin.theme_switcher.menu_label")
50
+ end
51
+
52
+ # @api private
53
+ # @return [String, nil] Path the switch returns to: the current path on a GET page; on a page
54
+ # answering a POST, which may have no GET route (an import preview), the same-site
55
+ # Referer's path, else nil (the admin root)
56
+ def return_path
57
+ return @return_path if defined?(@return_path)
58
+
59
+ @return_path = request.get? || request.head? ? request.fullpath : referer_path
60
+ end
61
+
62
+ private
63
+
64
+ def referer_path
65
+ referer = URI.parse(request.referer.to_s)
66
+ return unless referer.is_a?(URI::HTTP) && referer.host == request.host && referer.port == request.port
67
+
68
+ referer.request_uri
69
+ rescue URI::InvalidURIError
70
+ nil
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,11 +1,18 @@
1
- .p-6{ class: "#{theme.card_bg} border #{theme.card_border} #{theme.border_radius} #{theme.card_shadow}" }
2
- %h2.text-lg.font-semibold.mb-4{ class: theme.body_text }
1
+ %div{ class: panel_classes }
2
+ %h2{ class: title_classes }
3
3
  Actions
4
4
  .flex.flex-wrap.gap-2
5
5
  - actions.each do |action|
6
- = button_to action_url(action), method: :post,
7
- data: action[:confirm] ? { turbo_confirm: confirm_message(action) } : {},
8
- class: "#{theme.btn_ghost} inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg" do
9
- - if action[:icon]
10
- = heroicon action[:icon], variant: :outline, options: { class: "h-5 w-5" }
11
- = action[:name].to_s.humanize
6
+ -# An action with form fields opens its form, which asks for the confirmation on submit.
7
+ - if form?(action)
8
+ = link_to form_url(action), class: button_classes do
9
+ - if action[:icon]
10
+ = heroicon action[:icon], variant: :outline, options: { class: "h-4 w-4", "stroke-width": IronAdmin::ApplicationHelper::SMALL_ICON_STROKE }
11
+ = action[:name].to_s.humanize
12
+ - else
13
+ = button_to action_url(action), method: :post,
14
+ data: action[:confirm] ? { turbo_confirm: confirm_message(action) } : {},
15
+ class: button_classes do
16
+ - if action[:icon]
17
+ = heroicon action[:icon], variant: :outline, options: { class: "h-4 w-4", "stroke-width": IronAdmin::ApplicationHelper::SMALL_ICON_STROKE }
18
+ = action[:name].to_s.humanize
@@ -24,9 +24,27 @@ module IronAdmin
24
24
  end
25
25
 
26
26
  # @api private
27
- # @return [IronAdmin::Configuration::Theme] Theme configuration
27
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
28
28
  def theme
29
- IronAdmin.configuration.theme
29
+ IronAdmin.current_theme
30
+ end
31
+
32
+ # @api private
33
+ # @return [String] CSS classes of the panel
34
+ def panel_classes
35
+ "p-4 #{Styles.panel(theme)}"
36
+ end
37
+
38
+ # @api private
39
+ # @return [String] CSS classes of the panel title
40
+ def title_classes
41
+ "mb-3 #{Styles.panel_title(theme)}"
42
+ end
43
+
44
+ # @api private
45
+ # @return [String] CSS classes of an action button
46
+ def button_classes
47
+ Styles.secondary_button(theme)
30
48
  end
31
49
 
32
50
  # @api private
@@ -36,6 +54,20 @@ module IronAdmin
36
54
  helpers.iron_admin.resource_action_path(resource_class.resource_name, record, action[:name])
37
55
  end
38
56
 
57
+ # @api private
58
+ # @param action [Hash] Action configuration
59
+ # @return [Boolean] Whether the action has form fields, so its button opens the form
60
+ def form?(action)
61
+ action[:form_fields].present?
62
+ end
63
+
64
+ # @api private
65
+ # @param action [Hash] Action configuration
66
+ # @return [String] URL of the action's form
67
+ def form_url(action)
68
+ helpers.iron_admin.resource_action_form_path(resource_class.resource_name, record, action[:name])
69
+ end
70
+
39
71
  # @api private
40
72
  # @param action [Hash] Action configuration
41
73
  # @return [String] Text of the action's confirmation dialog
@@ -1,7 +1,7 @@
1
1
  %nav.flex{ aria: { label: "Breadcrumb" } }
2
- %ol.flex.items-center.space-x-2{ role: "list" }
2
+ %ol.flex.flex-wrap.items-center{ class: "gap-1.5", role: "list" }
3
3
  - items.each_with_index do |item, index|
4
- %li.flex.items-center
4
+ %li.flex.items-center{ class: "gap-1.5" }
5
5
  - unless index.zero?
6
- = heroicon "chevron-right", variant: :mini, options: { class: "h-4 w-4 mx-2 #{theme.muted_text}" }
6
+ = heroicon "chevron-right", variant: :mini, options: { class: "h-4 w-4 shrink-0 #{theme.icon_muted}", "aria-hidden": "true" }
7
7
  = item
@@ -2,14 +2,14 @@
2
2
 
3
3
  module IronAdmin
4
4
  module Resources
5
- # Renders breadcrumb navigation.
5
+ # Renders breadcrumb navigation: small muted links separated by chevrons.
6
6
  class BreadcrumbComponent < ViewComponent::Base
7
7
  renders_many :items, "ItemComponent"
8
8
 
9
9
  # @api private
10
- # @return [IronAdmin::Configuration::Theme] Theme configuration
10
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
11
11
  def theme
12
- IronAdmin.configuration.theme
12
+ IronAdmin.current_theme
13
13
  end
14
14
 
15
15
  # Individual breadcrumb item component.
@@ -34,18 +34,19 @@ module IronAdmin
34
34
  end
35
35
 
36
36
  # @api private
37
- # @return [IronAdmin::Configuration::Theme] Theme configuration
37
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
38
38
  def theme
39
- IronAdmin.configuration.theme
39
+ IronAdmin.current_theme
40
40
  end
41
41
 
42
42
  # @api private
43
- # @return [String] CSS classes for breadcrumb item
43
+ # @return [String] CSS classes for breadcrumb item: the current page in
44
+ # body text, the others as the theme's muted links
44
45
  def item_classes
45
46
  if current
46
47
  "text-sm font-medium #{theme.body_text}"
47
48
  else
48
- "text-sm #{theme.link}"
49
+ "text-sm #{theme.link_muted} #{theme.focus_ring}"
49
50
  end
50
51
  end
51
52
 
@@ -1,16 +1,17 @@
1
- %div{ class: "hidden items-center gap-3 p-4 #{theme.card_bg} border-t #{theme.card_border}",
2
- data: { controller: "bulk-actions", bulk_actions_target: "toolbar" } }
1
+ %div{ class: toolbar_classes, data: { controller: "bulk-actions", bulk_actions_target: "toolbar" } }
3
2
  %span.text-sm{ class: theme.muted_text }
4
- %span{ data: { bulk_actions_target: "count" } } 0
3
+ %span.tabular-nums{ data: { bulk_actions_target: "count" } } 0
5
4
  selected
6
5
 
7
- .flex.gap-2
6
+ .flex.flex-wrap.gap-2
8
7
  - actions.each do |action|
9
- = button_to action_url(action), method: :post, form: { data: { bulk_actions_target: "form" } },
10
- class: "#{theme.btn_secondary} px-3 py-1.5 text-sm font-medium rounded-lg" do
8
+ -# A bulk action with form fields takes the selected ids to its form with a GET, which has no CSRF token,
9
+ -# and the form asks for the confirmation on submit.
10
+ = button_to form?(action) ? form_url(action) : action_url(action), method: form?(action) ? :get : :post,
11
+ form: { data: { bulk_actions_target: "form" } }, data: confirm_data(action), class: button_classes do
11
12
  - if action[:icon]
12
- = heroicon action[:icon], variant: :mini, options: { class: "h-4 w-4 mr-1" }
13
+ = heroicon action[:icon], variant: :mini, options: { class: "h-4 w-4" }
13
14
  = action[:name].to_s.humanize
14
15
 
15
- %button.ml-auto.text-sm{ type: "button", class: theme.link_muted, data: { action: "bulk-actions#clearAll" } }
16
+ %button.ml-auto.text-sm{ type: "button", class: "#{theme.link_muted} #{theme.focus_ring}", data: { action: "bulk-actions#clearAll" } }
16
17
  Clear selection
@@ -18,9 +18,21 @@ module IronAdmin
18
18
  end
19
19
 
20
20
  # @api private
21
- # @return [IronAdmin::Configuration::Theme] Theme configuration
21
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
22
22
  def theme
23
- IronAdmin.configuration.theme
23
+ IronAdmin.current_theme
24
+ end
25
+
26
+ # @api private
27
+ # @return [String] CSS classes of the toolbar, shown once records are selected
28
+ def toolbar_classes
29
+ "hidden flex-wrap items-center gap-3 px-4 py-3 border-t #{theme.card_bg} #{theme.card_border}"
30
+ end
31
+
32
+ # @api private
33
+ # @return [String] CSS classes of an action button
34
+ def button_classes
35
+ Styles.secondary_button(theme)
24
36
  end
25
37
 
26
38
  # @api private
@@ -31,9 +43,40 @@ module IronAdmin
31
43
  end
32
44
 
33
45
  # @api private
34
- # @return [Boolean] Whether to render the component
46
+ # @param action [Hash] Bulk action configuration
47
+ # @return [Boolean] Whether the action has form fields, so its button opens the form
48
+ def form?(action)
49
+ action[:form_fields].present?
50
+ end
51
+
52
+ # @api private
53
+ # @param action [Hash] Bulk action configuration
54
+ # @return [String] URL of the bulk action's form
55
+ def form_url(action)
56
+ helpers.iron_admin.resource_bulk_action_form_path(resource_class.resource_name, action[:name])
57
+ end
58
+
59
+ # @api private
60
+ # @param action [Hash] Bulk action configuration
61
+ # @return [String] Text of the action's confirmation dialog
62
+ def confirm_message(action)
63
+ action[:confirm_message].presence || I18n.t("iron_admin.resources.action.confirm")
64
+ end
65
+
66
+ # @api private
67
+ # @param action [Hash] Bulk action configuration
68
+ # @return [Hash] Data attributes of the action's button: the confirmation of a confirm: true
69
+ # action without form fields (an action with form fields asks on its form's submit)
70
+ def confirm_data(action)
71
+ action[:confirm] && !form?(action) ? { turbo_confirm: confirm_message(action) } : {}
72
+ end
73
+
74
+ # @api private
75
+ # @return [Boolean] Whether to render the component. A nil list, which is
76
+ # what a page other than the index has for +@permitted_bulk_actions+,
77
+ # renders nothing.
35
78
  def render?
36
- actions.any?
79
+ Array(actions).any?
37
80
  end
38
81
  end
39
82
  end
@@ -1,26 +1,26 @@
1
- .overflow-x-auto
2
- %table{ class: "#{table_classes} #{theme.card_border} divide-y" }
1
+ %div{ class: frame_classes }
2
+ %table{ class: table_classes }
3
3
  %thead{ class: header_classes }
4
4
  %tr
5
5
  - visible_fields.each do |field|
6
- %th.px-6.py-3.text-left.text-xs.font-medium.uppercase.tracking-wider{ class: theme.muted_text }
6
+ %th{ scope: "col", class: header_cell_classes }
7
7
  -# A whole-page visit, so forms outside the records frame get the new sort.
8
- = link_to sort_url(field.name), class: "inline-flex items-center gap-1 hover:text-gray-700",
9
- data: { turbo_frame: "_top" } do
8
+ = link_to sort_url(field.name), class: sort_link_classes, data: { turbo_frame: "_top" } do
10
9
  = field.name.to_s.humanize
11
- - if sorted?(field.name)
12
- - if sort_direction == "asc"
13
- = heroicon "chevron-up", variant: :mini, options: { class: "h-4 w-4" }
14
- - else
15
- = heroicon "chevron-down", variant: :mini, options: { class: "h-4 w-4" }
10
+ - if !sorted?(field.name)
11
+ = heroicon "chevron-up-down", variant: :mini, options: { class: "h-3.5 w-3.5 opacity-0 group-hover:opacity-50 transition-opacity" }
12
+ - elsif sort_direction == "asc"
13
+ = heroicon "chevron-up", variant: :mini, options: { class: "h-3.5 w-3.5" }
14
+ - else
15
+ = heroicon "chevron-down", variant: :mini, options: { class: "h-3.5 w-3.5" }
16
16
  -# relative keeps the absolutely positioned sr-only text inside the scrolling table.
17
- %th.relative.px-6.py-3
17
+ %th{ scope: "col", class: "relative #{theme.table_cell_padding}" }
18
18
  %span.sr-only Actions
19
19
 
20
- %tbody{ class: "#{theme.card_border} divide-y" }
20
+ %tbody{ class: body_classes }
21
21
  - if empty?
22
22
  %tr
23
- %td.px-6.py-8.text-center.text-sm{ colspan: visible_fields.size + 1, class: theme.muted_text }
23
+ %td.px-4.py-12.text-center.text-sm{ colspan: visible_fields.size + 1, class: theme.muted_text }
24
24
  - if empty_state?
25
25
  = empty_state
26
26
  - else
@@ -29,8 +29,8 @@
29
29
  - records.each do |record|
30
30
  %tr{ id: row_dom_id(record), class: theme.table_row_hover }
31
31
  - visible_fields.each do |field|
32
- %td.px-6.py-4.whitespace-nowrap.text-sm{ class: theme.body_text }
32
+ %td{ class: cell_classes(field) }
33
33
  = helpers.display_index_field_value(record, field)
34
- %td.px-6.py-4.whitespace-nowrap.text-right.text-sm
34
+ %td{ class: "whitespace-nowrap text-right text-sm #{theme.table_cell_padding}" }
35
35
  = link_to "View", helpers.iron_admin.resource_path(resource_class.resource_name, record),
36
36
  class: theme.link, data: { turbo_frame: "_top" }
@@ -50,15 +50,21 @@ module IronAdmin
50
50
  end
51
51
 
52
52
  # @api private
53
- # @return [IronAdmin::Configuration::Theme] Theme configuration
53
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
54
54
  def theme
55
- IronAdmin.configuration.theme
55
+ IronAdmin.current_theme
56
+ end
57
+
58
+ # @api private
59
+ # @return [String] CSS classes of the panel the table scrolls in
60
+ def frame_classes
61
+ Styles.table_frame(theme)
56
62
  end
57
63
 
58
64
  # @api private
59
65
  # @return [String] CSS classes for table element
60
66
  def table_classes
61
- "min-w-full divide-y #{theme.card_bg} #{theme.border_radius} #{theme.card_shadow}"
67
+ Styles.table(theme)
62
68
  end
63
69
 
64
70
  # @api private
@@ -67,6 +73,31 @@ module IronAdmin
67
73
  theme.table_header_bg
68
74
  end
69
75
 
76
+ # @api private
77
+ # @return [String] CSS classes of a header cell
78
+ def header_cell_classes
79
+ Styles.header_cell(theme)
80
+ end
81
+
82
+ # @api private
83
+ # @return [String] CSS classes of a column's sort link
84
+ def sort_link_classes
85
+ "group inline-flex items-center gap-1 #{theme.focus_ring}"
86
+ end
87
+
88
+ # @api private
89
+ # @return [String] CSS classes of the table body
90
+ def body_classes
91
+ Styles.divided(theme)
92
+ end
93
+
94
+ # @api private
95
+ # @param field [IronAdmin::Field] The cell's field
96
+ # @return [String] CSS classes of a body cell
97
+ def cell_classes(field)
98
+ Styles.cell(theme, field)
99
+ end
100
+
70
101
  delegate :empty?, to: :records
71
102
 
72
103
  # @api private
@@ -1,13 +1,13 @@
1
- .mt-6.overflow-hidden{ class: "#{theme.card_bg} #{theme.border_radius} #{theme.card_shadow}" }
2
- .px-6.py-4.border-b.flex.items-center.justify-between{ class: theme.card_border }
3
- %h2.text-lg.font-semibold{ class: theme.body_text }
1
+ %div{ class: panel_classes }
2
+ %div{ class: header_classes }
3
+ %h2{ class: title_classes }
4
4
  = title
5
5
  = link_to I18n.t("iron_admin.resources.show.view_all"), view_all_url, class: "text-sm #{theme.link}"
6
6
 
7
- .overflow-x-auto
8
- %table.min-w-full{ class: "#{theme.table_border} divide-y" }
9
- %tbody{ class: "#{theme.table_border} divide-y" }
7
+ .overflow-x-auto.cp-scroll-fade
8
+ %table.min-w-full
9
+ %tbody{ class: body_classes }
10
10
  - records.each do |record|
11
11
  %tr{ class: theme.table_row_hover }
12
- %td.px-6.py-3.text-sm{ class: theme.body_text }
12
+ %td{ class: "text-sm #{theme.table_cell_padding}" }
13
13
  = link_to helpers.display_record_label(record, display_method), record_url(record), class: theme.link
@@ -29,9 +29,33 @@ module IronAdmin
29
29
  end
30
30
 
31
31
  # @api private
32
- # @return [IronAdmin::Configuration::Theme] Theme configuration
32
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
33
33
  def theme
34
- IronAdmin.configuration.theme
34
+ IronAdmin.current_theme
35
+ end
36
+
37
+ # @api private
38
+ # @return [String] CSS classes of the panel
39
+ def panel_classes
40
+ "mt-6 overflow-hidden #{Styles.panel(theme)}"
41
+ end
42
+
43
+ # @api private
44
+ # @return [String] CSS classes of the title row
45
+ def header_classes
46
+ Styles.panel_header(theme)
47
+ end
48
+
49
+ # @api private
50
+ # @return [String] CSS classes of the title
51
+ def title_classes
52
+ Styles.panel_title(theme)
53
+ end
54
+
55
+ # @api private
56
+ # @return [String] CSS classes of the list body
57
+ def body_classes
58
+ Styles.divided(theme)
35
59
  end
36
60
 
37
61
  # @api private
@@ -1,5 +1,5 @@
1
- .px-6.py-4.flex.items-center
2
- %dt.text-sm.font-medium{ class: "w-1/3 #{theme.muted_text}" }
1
+ %div{ class: row_classes }
2
+ %dt.text-sm.font-medium{ class: "sm:w-1/3 #{theme.muted_text} #{theme.field_label_transform}" }
3
3
  = label
4
- %dd.text-sm{ class: "w-2/3 #{theme.body_text}" }
4
+ %dd.text-sm.break-words{ class: "sm:w-2/3 #{theme.body_text}" }
5
5
  = value
@@ -29,9 +29,15 @@ module IronAdmin
29
29
  end
30
30
 
31
31
  # @api private
32
- # @return [IronAdmin::Configuration::Theme] Theme configuration
32
+ # @return [IronAdmin::Configuration::Theme] Theme of the current request
33
33
  def theme
34
- IronAdmin.configuration.theme
34
+ IronAdmin.current_theme
35
+ end
36
+
37
+ # @api private
38
+ # @return [String] CSS classes of the label and value row
39
+ def row_classes
40
+ Styles::DETAIL_ROW
35
41
  end
36
42
 
37
43
  # @api private
@@ -41,9 +47,9 @@ module IronAdmin
41
47
  end
42
48
 
43
49
  # @api private
44
- # @return [String, nil] Formatted field value
50
+ # @return [String] Formatted field value, or the empty value marker
45
51
  def value
46
- helpers.display_field_value(record, field)
52
+ helpers.display_show_field_value(record, field)
47
53
  end
48
54
  end
49
55
  end