From ddc6926394f2f6fe21008041257f9365ba51f2dd Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Sat, 5 Jun 2021 20:01:23 +0100 Subject: [PATCH 1/4] Adjust naming of Stat resource and dashboard --- app/helpers/administrate/application_helper.rb | 2 +- docs/adding_controllers_without_related_model.md | 4 ++-- spec/example_app/app/dashboards/stat_dashboard.rb | 2 +- spec/example_app/app/policies/stat_policy.rb | 2 ++ spec/example_app/app/policies/stats_policy.rb | 2 -- 5 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 spec/example_app/app/policies/stat_policy.rb delete mode 100644 spec/example_app/app/policies/stats_policy.rb diff --git a/app/helpers/administrate/application_helper.rb b/app/helpers/administrate/application_helper.rb index 0002d299e8..800c7f41d2 100644 --- a/app/helpers/administrate/application_helper.rb +++ b/app/helpers/administrate/application_helper.rb @@ -26,7 +26,7 @@ def dashboard_from_resource(resource_name) def model_from_resource(resource_name) dashboard = dashboard_from_resource(resource_name) - dashboard.try(:model) || resource_name.to_sym + dashboard.try(:model) || resource_name.singularize.to_sym end def display_resource_name(resource_name, opts = {}) diff --git a/docs/adding_controllers_without_related_model.md b/docs/adding_controllers_without_related_model.md index f4882aa170..c6c22cb878 100644 --- a/docs/adding_controllers_without_related_model.md +++ b/docs/adding_controllers_without_related_model.md @@ -9,7 +9,7 @@ To do that, you must define an `index` route, as only controllers with index routes are displayed in the sidebar and then add a custom dashboard: ```erb -# app/views/admin/stats/index.html.erb +# app/views/admin/stats/index.html.erb

Stats

@@ -25,7 +25,7 @@ routes are displayed in the sidebar and then add a custom dashboard: require "administrate/custom_dashboard" class StatDashboard < Administrate::CustomDashboard - resource "Stats" # used by administrate in the views + resource "Stat" # used by administrate in the views end ``` diff --git a/spec/example_app/app/dashboards/stat_dashboard.rb b/spec/example_app/app/dashboards/stat_dashboard.rb index 73813c303f..d54e0cd3ad 100644 --- a/spec/example_app/app/dashboards/stat_dashboard.rb +++ b/spec/example_app/app/dashboards/stat_dashboard.rb @@ -1,5 +1,5 @@ require "administrate/custom_dashboard" class StatDashboard < Administrate::CustomDashboard - resource "Stats" + resource "Stat" end diff --git a/spec/example_app/app/policies/stat_policy.rb b/spec/example_app/app/policies/stat_policy.rb new file mode 100644 index 0000000000..bfa8b806e6 --- /dev/null +++ b/spec/example_app/app/policies/stat_policy.rb @@ -0,0 +1,2 @@ +class StatPolicy < ApplicationPolicy +end diff --git a/spec/example_app/app/policies/stats_policy.rb b/spec/example_app/app/policies/stats_policy.rb deleted file mode 100644 index 76e9342b81..0000000000 --- a/spec/example_app/app/policies/stats_policy.rb +++ /dev/null @@ -1,2 +0,0 @@ -class StatsPolicy < ApplicationPolicy -end From 9aeb977b8220d37063ba3f2eccfb0ea5d8ea6473 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Thu, 28 Apr 2022 13:44:04 +0100 Subject: [PATCH 2/4] Correct markup --- docs/adding_controllers_without_related_model.md | 3 +-- spec/example_app/app/views/admin/stats/index.html.erb | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/adding_controllers_without_related_model.md b/docs/adding_controllers_without_related_model.md index c6c22cb878..00b923cec7 100644 --- a/docs/adding_controllers_without_related_model.md +++ b/docs/adding_controllers_without_related_model.md @@ -11,11 +11,10 @@ routes are displayed in the sidebar and then add a custom dashboard: ```erb # app/views/admin/stats/index.html.erb -
+

Stats


Total Customers: <%= @stats[:customer_count] %>

-

Total Orders: <%= @stats[:order_count] %>

``` diff --git a/spec/example_app/app/views/admin/stats/index.html.erb b/spec/example_app/app/views/admin/stats/index.html.erb index b2032fc0eb..48084aa812 100644 --- a/spec/example_app/app/views/admin/stats/index.html.erb +++ b/spec/example_app/app/views/admin/stats/index.html.erb @@ -1,7 +1,6 @@

Stats


-

Total Customers: <%= @stats[:customer_count] %> -
-

Total Orders: <%= @stats[:order_count] %> +

Total Customers: <%= @stats[:customer_count] %>

+

Total Orders: <%= @stats[:order_count] %>

From c08af74d4501e2158d84b90bb74ae6d3ca5c5273 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Thu, 28 Apr 2022 13:46:54 +0100 Subject: [PATCH 3/4] Comma --- docs/adding_controllers_without_related_model.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/adding_controllers_without_related_model.md b/docs/adding_controllers_without_related_model.md index 00b923cec7..a9d96d0061 100644 --- a/docs/adding_controllers_without_related_model.md +++ b/docs/adding_controllers_without_related_model.md @@ -6,7 +6,7 @@ Sometimes you may want to add a custom controller that has no resource related to it (for example for a statistics page). To do that, you must define an `index` route, as only controllers with index -routes are displayed in the sidebar and then add a custom dashboard: +routes are displayed in the sidebar, and then add a custom dashboard: ```erb # app/views/admin/stats/index.html.erb From 0b37fb10cc532fd406d5776a8316451371036c75 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Thu, 28 Apr 2022 14:16:36 +0100 Subject: [PATCH 4/4] Less complex option --- lib/administrate/custom_dashboard.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/administrate/custom_dashboard.rb b/lib/administrate/custom_dashboard.rb index a8fe1d0e4d..b94fe60b24 100644 --- a/lib/administrate/custom_dashboard.rb +++ b/lib/administrate/custom_dashboard.rb @@ -4,11 +4,11 @@ class CustomDashboard class << self def resource_name(_opts) - named_resource.pluralize.titleize + @named_resource.pluralize.titleize end def resource(resource_name) - define_singleton_method(:named_resource) { resource_name } + @named_resource = resource_name end end end