diff --git a/CHANGELOG.md b/CHANGELOG.md index 848ea5a7..f464f9c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,32 @@ - Remove Tailwind CDN - Add styles through asset pipeline - Refactor JavaScript into an Import map (separate from the Rails app) +- Include Rails route helpers in Madmin controllers and views for better integration with the main app +- Add `menu` to resources to allow customizing navigation sort order and add headers for grouping + +```ruby +# config/initializers/madmin.rb + +# Add a Payments header at the first position in the menu +Madmin.menu.add label: "Payments", position: 0 +``` + +```ruby +class SubscriptionResource < Madmin::Resource + # Add Subscriptions under the Payments header + menu parent: "Payments" +end +``` + +- `member_action` now yields the record to the block + +```ruby +class UserResource < Madmin::Resource + member_action do |user| + button_to "Impersonate", impersonate_user_path(user) + end +end +``` ### 1.2.10 diff --git a/app/assets/stylesheets/madmin/sidebar.css b/app/assets/stylesheets/madmin/sidebar.css index bf496aab..502d803a 100644 --- a/app/assets/stylesheets/madmin/sidebar.css +++ b/app/assets/stylesheets/madmin/sidebar.css @@ -14,7 +14,25 @@ main { position: fixed; width: var(--sidebar-width); + h1 { + margin-top: 0; + + a { + color: var(--text-color); + text-decoration: none; + + &:hover { + text-decoration: underline; + } + } + } + nav { + h4 { + margin-top: 0.5rem; + margin-bottom: 0.25rem; + } + a { border-radius: .375rem; color: var(--text-color); @@ -23,6 +41,9 @@ main { padding: 0.5rem; text-decoration: none; + margin-top: 0.1rem; + margin-bottom: 0.1rem; + &:hover { background-color: rgb(243 244 246); } diff --git a/app/controllers/madmin/application_controller.rb b/app/controllers/madmin/application_controller.rb index 3fb90202..cffb6fcf 100644 --- a/app/controllers/madmin/application_controller.rb +++ b/app/controllers/madmin/application_controller.rb @@ -7,18 +7,11 @@ class ApplicationController < Madmin::BaseController def authenticate_admin_user # TODO: Add your authentication logic here - # For example, we could redirect if the user isn't an admin - # redirect_to "/", alert: "Not authorized." unless user_signed_in? && current_user.admin? - end - - # Authenticate with Clearance - # include Clearance::Controller - # before_action :require_login + # For example, with Rails 8 authentication + # redirect_to "/", alert: "Not authorized." unless authenticated? && Current.user.admin? - # Authenticate with Devise - # before_action :authenticate_user! - - # Authenticate with Basic Auth - # http_basic_authenticate_with(name: Rails.application.credentials.admin_username, password: Rails.application.credentials.admin_password) + # Or with Devise + # redirect_to "/", alert: "Not authorized." unless current_user&.admin? + end end end diff --git a/app/views/madmin/application/_menu_resources.html.erb b/app/views/madmin/application/_menu_resources.html.erb deleted file mode 100644 index 3492ce38..00000000 --- a/app/views/madmin/application/_menu_resources.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%= nav_link_to "Dashboard", main_app.madmin_root_path %> - -<% Madmin.resources.select(&:show_in_nav).each do |resource| %> - <%= nav_link_to resource.friendly_name.pluralize, resource.index_path, starts_with: resource.index_path %> -<% end %> diff --git a/app/views/madmin/application/_navigation.html.erb b/app/views/madmin/application/_navigation.html.erb index 2ddd34fd..122b188b 100644 --- a/app/views/madmin/application/_navigation.html.erb +++ b/app/views/madmin/application/_navigation.html.erb @@ -1,8 +1,19 @@ -