activeadmin 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activeadmin might be problematic. Click here for more details.
- data/.travis.yml +8 -5
- data/CHANGELOG.md +151 -0
- data/Gemfile +16 -16
- data/LICENSE +1 -1
- data/activeadmin.gemspec +1 -0
- data/app/assets/images/active_admin/index_list_icons/block_icon.svg +10 -0
- data/app/assets/images/active_admin/index_list_icons/blog_icon.svg +4 -0
- data/app/assets/images/active_admin/index_list_icons/grid_icon.svg +13 -0
- data/app/assets/images/active_admin/index_list_icons/table_icon.svg +3 -0
- data/app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee +17 -44
- data/app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee +2 -4
- data/app/assets/javascripts/active_admin/components/jquery.aa.popover.js.coffee +0 -3
- data/app/assets/javascripts/active_admin/components/jquery.aa.table-checkbox-toggler.js.coffee +10 -12
- data/app/assets/javascripts/active_admin/pages/application.js.coffee +13 -10
- data/app/assets/javascripts/active_admin/pages/batch_actions.js.coffee +3 -3
- data/app/assets/stylesheets/active_admin/_base.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/_header.css.scss +5 -2
- data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_index_list.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_popovers.css.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +2 -2
- data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +4 -4
- data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +5 -4
- data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +1 -1
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +1 -1
- data/app/assets/stylesheets/active_admin/print.css.scss +2 -2
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +1 -1
- data/app/views/active_admin/devise/unlocks/new.html.erb +14 -12
- data/docs/1-general-configuration.md +13 -0
- data/docs/10-custom-pages.md +40 -28
- data/docs/11-decorators.md +6 -4
- data/docs/12-arbre-components.md +1 -1
- data/docs/13-authorization-adapter.md +206 -0
- data/docs/2-resource-customization.md +129 -14
- data/docs/3-index-pages.md +65 -0
- data/docs/3-index-pages/create-an-index.md +29 -0
- data/docs/3-index-pages/index-as-table.md +35 -11
- data/docs/5-forms.md +2 -2
- data/features/authorization.feature +64 -0
- data/features/authorization_cancan.feature +52 -0
- data/features/belongs_to.feature +41 -5
- data/features/index/batch_actions.feature +27 -3
- data/features/index/formats.feature +27 -0
- data/features/index/index_as_table.feature +74 -2
- data/features/index/index_parameters.feature +69 -0
- data/features/index/index_scopes.feature +7 -11
- data/features/index/page_title.feature +18 -0
- data/features/index/switch_index_view.feature +73 -0
- data/features/menu.feature +27 -0
- data/features/registering_pages.feature +21 -0
- data/features/step_definitions/additional_web_steps.rb +4 -0
- data/features/step_definitions/batch_action_steps.rb +16 -6
- data/features/step_definitions/index_scope_steps.rb +3 -3
- data/features/step_definitions/index_views_steps.rb +3 -0
- data/features/step_definitions/menu_steps.rb +4 -0
- data/features/support/env.rb +4 -0
- data/features/support/paths.rb +3 -0
- data/lib/active_admin.rb +4 -0
- data/lib/active_admin/application.rb +43 -76
- data/lib/active_admin/authorization_adapter.rb +128 -0
- data/lib/active_admin/base_controller.rb +18 -1
- data/lib/active_admin/base_controller/authorization.rb +153 -0
- data/lib/active_admin/base_controller/menu.rb +8 -3
- data/lib/active_admin/batch_actions/resource_extension.rb +8 -7
- data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -1
- data/lib/active_admin/cancan_adapter.rb +40 -0
- data/lib/active_admin/dashboards.rb +4 -5
- data/lib/active_admin/dashboards/dashboard_controller.rb +1 -1
- data/lib/active_admin/devise.rb +22 -7
- data/lib/active_admin/dsl.rb +18 -5
- data/lib/active_admin/engine.rb +1 -1
- data/lib/active_admin/filters/dsl.rb +1 -1
- data/lib/active_admin/filters/forms.rb +9 -7
- data/lib/active_admin/filters/resource_extension.rb +20 -15
- data/lib/active_admin/form_builder.rb +44 -49
- data/lib/active_admin/helpers/optional_display.rb +4 -8
- data/lib/active_admin/inputs/filter_boolean_input.rb +1 -1
- data/lib/active_admin/inputs/filter_string_input.rb +5 -1
- data/lib/active_admin/locales/bg.yml +1 -1
- data/lib/active_admin/locales/ca.yml +1 -1
- data/lib/active_admin/locales/cs.yml +26 -25
- data/lib/active_admin/locales/da.yml +1 -1
- data/lib/active_admin/locales/de.yml +1 -1
- data/lib/active_admin/locales/en.yml +11 -1
- data/lib/active_admin/locales/es.yml +16 -16
- data/lib/active_admin/locales/fr.yml +1 -1
- data/lib/active_admin/locales/he.yml +1 -1
- data/lib/active_admin/locales/hr.yml +1 -1
- data/lib/active_admin/locales/hu.yml +1 -1
- data/lib/active_admin/locales/it.yml +1 -1
- data/lib/active_admin/locales/ja.yml +4 -1
- data/lib/active_admin/locales/ko.yml +1 -1
- data/lib/active_admin/locales/lt.yml +1 -1
- data/lib/active_admin/locales/lv.yml +12 -1
- data/lib/active_admin/locales/nl.yml +2 -2
- data/lib/active_admin/locales/no-NB.yml +22 -1
- data/lib/active_admin/locales/pl.yml +1 -1
- data/lib/active_admin/locales/pt-BR.yml +1 -1
- data/lib/active_admin/locales/pt-PT.yml +81 -0
- data/lib/active_admin/locales/ro.yml +1 -1
- data/lib/active_admin/locales/ru.yml +1 -1
- data/lib/active_admin/locales/sv-SE.yml +1 -1
- data/lib/active_admin/locales/tr.yml +1 -1
- data/lib/active_admin/locales/vi.yml +1 -1
- data/lib/active_admin/locales/zh-CN.yml +1 -1
- data/lib/active_admin/locales/zh-TW.yml +1 -1
- data/lib/active_admin/menu.rb +76 -38
- data/lib/active_admin/menu_collection.rb +96 -0
- data/lib/active_admin/menu_item.rb +61 -71
- data/lib/active_admin/namespace.rb +67 -5
- data/lib/active_admin/page.rb +6 -0
- data/lib/active_admin/page_controller.rb +13 -3
- data/lib/active_admin/resource.rb +11 -20
- data/lib/active_admin/resource/action_items.rb +3 -3
- data/lib/active_admin/resource/controllers.rb +0 -17
- data/lib/active_admin/resource/menu.rb +52 -24
- data/lib/active_admin/resource/naming.rb +6 -10
- data/lib/active_admin/resource/page_presenters.rb +57 -3
- data/lib/active_admin/resource/routes.rb +46 -0
- data/lib/active_admin/resource_controller.rb +2 -17
- data/lib/active_admin/resource_controller/data_access.rb +299 -0
- data/lib/active_admin/resource_controller/decorators.rb +2 -1
- data/lib/active_admin/resource_dsl.rb +12 -14
- data/lib/active_admin/router.rb +61 -56
- data/lib/active_admin/scope.rb +28 -18
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +0 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +13 -19
- data/lib/active_admin/view_helpers/fields_for.rb +2 -0
- data/lib/active_admin/view_helpers/form_helper.rb +1 -1
- data/lib/active_admin/view_helpers/method_or_proc_helper.rb +66 -11
- data/lib/active_admin/views/components/attributes_table.rb +7 -4
- data/lib/active_admin/views/components/index_list.rb +68 -0
- data/lib/active_admin/views/components/paginated_collection.rb +13 -9
- data/lib/active_admin/views/components/scopes.rb +2 -8
- data/lib/active_admin/views/components/table_for.rb +1 -1
- data/lib/active_admin/views/footer.rb +1 -1
- data/lib/active_admin/views/header.rb +3 -2
- data/lib/active_admin/views/index_as_block.rb +4 -0
- data/lib/active_admin/views/index_as_blog.rb +4 -0
- data/lib/active_admin/views/index_as_grid.rb +4 -0
- data/lib/active_admin/views/index_as_table.rb +49 -7
- data/lib/active_admin/views/pages/index.rb +19 -4
- data/lib/active_admin/views/tabbed_navigation.rb +10 -54
- data/lib/generators/active_admin/install/install_generator.rb +5 -1
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +58 -0
- data/spec/integration/{default_namespace.rb → default_namespace_spec.rb} +0 -16
- data/spec/spec_helper.rb +3 -0
- data/spec/support/detect_rails_version.rb +10 -3
- data/spec/support/rails_template.rb +1 -1
- data/spec/support/templates/post_decorator.rb +6 -6
- data/spec/unit/application_spec.rb +5 -5
- data/spec/unit/authorization/authorization_adapter_spec.rb +61 -0
- data/spec/unit/authorization/controller_authorization_spec.rb +47 -0
- data/spec/unit/base_controller_spec.rb +0 -2
- data/spec/unit/batch_actions/resource_spec.rb +1 -1
- data/spec/unit/breadcrumbs_spec.rb +3 -3
- data/spec/unit/cancan_adapter_spec.rb +35 -0
- data/spec/unit/config_shared_examples.rb +9 -30
- data/spec/unit/devise_spec.rb +29 -0
- data/spec/unit/dsl_spec.rb +61 -0
- data/spec/unit/filters/filter_form_builder_spec.rb +58 -4
- data/spec/unit/filters/resource_spec.rb +17 -5
- data/spec/unit/form_builder_spec.rb +15 -0
- data/spec/unit/menu_collection_spec.rb +62 -0
- data/spec/unit/menu_item_spec.rb +51 -37
- data/spec/unit/menu_spec.rb +33 -29
- data/spec/unit/namespace/authorization_spec.rb +31 -0
- data/spec/unit/namespace/register_page_spec.rb +6 -28
- data/spec/unit/namespace/register_resource_spec.rb +11 -34
- data/spec/unit/namespace_spec.rb +63 -2
- data/spec/unit/page_controller_spec.rb +0 -3
- data/spec/unit/reloader_spec.rb +5 -5
- data/spec/unit/resource/menu_spec.rb +1 -13
- data/spec/unit/resource/naming_spec.rb +20 -2
- data/spec/unit/resource/page_presenters_spec.rb +14 -2
- data/spec/unit/resource_controller/{collection_spec.rb → data_access_spec.rb} +31 -13
- data/spec/unit/resource_controller_spec.rb +4 -5
- data/spec/unit/resource_spec.rb +33 -11
- data/spec/unit/routing_spec.rb +43 -0
- data/spec/unit/scope_spec.rb +13 -0
- data/spec/unit/view_factory_spec.rb +0 -1
- data/spec/unit/view_helpers/fields_for_spec.rb +4 -0
- data/spec/unit/view_helpers/form_helper_spec.rb +6 -2
- data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +97 -0
- data/spec/unit/views/components/attributes_table_spec.rb +11 -0
- data/spec/unit/views/components/index_list_spec.rb +32 -0
- data/spec/unit/views/tabbed_navigation_spec.rb +42 -40
- data/tasks/test.rake +1 -1
- metadata +127 -40
- data/lib/active_admin/menu_builder.rb +0 -65
- data/lib/active_admin/resource_controller/callbacks.rb +0 -59
- data/lib/active_admin/resource_controller/collection.rb +0 -158
- data/lib/active_admin/views/utility_nav.rb +0 -41
- data/spec/unit/base_controller_shared_examples.rb +0 -25
- data/spec/unit/dsl_include_spec.rb +0 -20
data/lib/active_admin/page.rb
CHANGED
@@ -37,6 +37,7 @@ module ActiveAdmin
|
|
37
37
|
include Resource::ActionItems
|
38
38
|
include Resource::Menu
|
39
39
|
include Resource::Naming
|
40
|
+
include Resource::Routes
|
40
41
|
|
41
42
|
# label is singular
|
42
43
|
def plural_resource_label
|
@@ -63,6 +64,11 @@ module ActiveAdmin
|
|
63
64
|
[namespace.module_name, camelized_resource_name + "Controller"].compact.join('::')
|
64
65
|
end
|
65
66
|
|
67
|
+
# Override from `ActiveAdmin::Resource::Controllers`
|
68
|
+
def route_uncountable?
|
69
|
+
false
|
70
|
+
end
|
71
|
+
|
66
72
|
def belongs_to?
|
67
73
|
false
|
68
74
|
end
|
@@ -3,17 +3,27 @@ module ActiveAdmin
|
|
3
3
|
# All Pages controllers inherit from this controller.
|
4
4
|
class PageController < BaseController
|
5
5
|
|
6
|
-
#
|
7
|
-
|
6
|
+
# Active admin actions don't require layout. All custom actions do.
|
7
|
+
ACTIVE_ADMIN_ACTIONS = [:index]
|
8
8
|
|
9
9
|
actions :index
|
10
10
|
|
11
|
+
before_filter :authorize_access!
|
12
|
+
|
11
13
|
def index(options={}, &block)
|
12
14
|
render "active_admin/page/index"
|
13
15
|
end
|
14
|
-
|
16
|
+
|
15
17
|
def clear_page_actions!
|
16
18
|
active_admin_config.clear_page_actions!
|
17
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def authorize_access!
|
24
|
+
permission = action_to_permission(params[:action])
|
25
|
+
authorize! permission, active_admin_config
|
26
|
+
end
|
27
|
+
|
18
28
|
end
|
19
29
|
end
|
@@ -3,6 +3,7 @@ require 'active_admin/resource/controllers'
|
|
3
3
|
require 'active_admin/resource/menu'
|
4
4
|
require 'active_admin/resource/page_presenters'
|
5
5
|
require 'active_admin/resource/pagination'
|
6
|
+
require 'active_admin/resource/routes'
|
6
7
|
require 'active_admin/resource/naming'
|
7
8
|
require 'active_admin/resource/scopes'
|
8
9
|
require 'active_admin/resource/sidebars'
|
@@ -68,14 +69,17 @@ module ActiveAdmin
|
|
68
69
|
end
|
69
70
|
|
70
71
|
include Base
|
72
|
+
include ActionItems
|
73
|
+
include Authorization
|
71
74
|
include Controllers
|
75
|
+
include Menu
|
76
|
+
include Naming
|
72
77
|
include PagePresenters
|
73
78
|
include Pagination
|
74
|
-
include ActionItems
|
75
|
-
include Naming
|
76
79
|
include Scopes
|
77
80
|
include Sidebars
|
78
81
|
include Menu
|
82
|
+
include Routes
|
79
83
|
|
80
84
|
# The class this resource wraps. If you register the Post model, Resource#resource_class
|
81
85
|
# will point to the Post class
|
@@ -91,6 +95,10 @@ module ActiveAdmin
|
|
91
95
|
resource_class.quoted_table_name
|
92
96
|
end
|
93
97
|
|
98
|
+
def resource_column_names
|
99
|
+
resource_class.column_names
|
100
|
+
end
|
101
|
+
|
94
102
|
def resource_quoted_column_name(column)
|
95
103
|
resource_class.connection.quote_column_name(column)
|
96
104
|
end
|
@@ -100,20 +108,6 @@ module ActiveAdmin
|
|
100
108
|
[route_prefix, controller.resources_configuration[:self][:route_instance_name], 'path'].compact.join('_').to_sym
|
101
109
|
end
|
102
110
|
|
103
|
-
# Returns a symbol for the route to use to get to the
|
104
|
-
# collection of this resource
|
105
|
-
def route_collection_path
|
106
|
-
route = super
|
107
|
-
|
108
|
-
# Handle plural resources.
|
109
|
-
if controller.resources_configuration[:self][:route_collection_name] ==
|
110
|
-
controller.resources_configuration[:self][:route_instance_name]
|
111
|
-
route = route.to_s.gsub('_path', '_index_path').to_sym
|
112
|
-
end
|
113
|
-
|
114
|
-
route
|
115
|
-
end
|
116
|
-
|
117
111
|
# Clears all the member actions this resource knows about
|
118
112
|
def clear_member_actions!
|
119
113
|
@member_actions = []
|
@@ -135,6 +129,7 @@ module ActiveAdmin
|
|
135
129
|
|
136
130
|
def belongs_to(target, options = {})
|
137
131
|
@belongs_to = Resource::BelongsTo.new(self, target, options)
|
132
|
+
self.menu_item_menu_name = target unless @belongs_to.optional?
|
138
133
|
controller.belongs_to(target, options.dup)
|
139
134
|
end
|
140
135
|
|
@@ -147,10 +142,6 @@ module ActiveAdmin
|
|
147
142
|
!belongs_to_config.nil?
|
148
143
|
end
|
149
144
|
|
150
|
-
def include_in_menu?
|
151
|
-
super && !(belongs_to? && !belongs_to_config.optional?)
|
152
|
-
end
|
153
|
-
|
154
145
|
# The csv builder for this resource
|
155
146
|
def csv_builder
|
156
147
|
@csv_builder || default_csv_builder
|
@@ -53,21 +53,21 @@ module ActiveAdmin
|
|
53
53
|
def add_default_action_items
|
54
54
|
# New Link on all actions except :new and :show
|
55
55
|
add_action_item :except => [:new, :show] do
|
56
|
-
if controller.action_methods.include?('new')
|
56
|
+
if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
|
57
57
|
link_to(I18n.t('active_admin.new_model', :model => active_admin_config.resource_label), new_resource_path)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
# Edit link on show
|
62
62
|
add_action_item :only => :show do
|
63
|
-
if controller.action_methods.include?('edit')
|
63
|
+
if controller.action_methods.include?('edit') && authorized?(ActiveAdmin::Auth::UPDATE, resource)
|
64
64
|
link_to(I18n.t('active_admin.edit_model', :model => active_admin_config.resource_label), edit_resource_path(resource))
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
# Destroy link on show
|
69
69
|
add_action_item :only => :show do
|
70
|
-
if controller.action_methods.include?("destroy")
|
70
|
+
if controller.action_methods.include?("destroy") && authorized?(ActiveAdmin::Auth::DESTROY, resource)
|
71
71
|
link_to(I18n.t('active_admin.delete_model', :model => active_admin_config.resource_label),
|
72
72
|
resource_path(resource),
|
73
73
|
:method => :delete, :data => {:confirm => I18n.t('active_admin.delete_confirmation')})
|
@@ -13,23 +13,6 @@ module ActiveAdmin
|
|
13
13
|
@controller ||= controller_name.constantize
|
14
14
|
end
|
15
15
|
|
16
|
-
# Returns the routes prefix for this config
|
17
|
-
def route_prefix
|
18
|
-
namespace.module_name.try(:underscore)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns a symbol for the route to use to get to the
|
22
|
-
# collection of this resource
|
23
|
-
def route_collection_path
|
24
|
-
route = [
|
25
|
-
route_prefix,
|
26
|
-
controller.resources_configuration[:self][:route_collection_name],
|
27
|
-
'path'
|
28
|
-
]
|
29
|
-
|
30
|
-
route.compact.join('_').to_sym
|
31
|
-
end
|
32
|
-
|
33
16
|
end
|
34
17
|
end
|
35
18
|
end
|
@@ -1,49 +1,77 @@
|
|
1
1
|
module ActiveAdmin
|
2
2
|
class Resource
|
3
|
+
|
3
4
|
module Menu
|
4
5
|
|
5
6
|
# Set the menu options. To not add this resource to the menu, just
|
6
7
|
# call #menu(false)
|
7
|
-
def
|
8
|
+
def menu_item_options=(options)
|
8
9
|
if options == false
|
9
|
-
@
|
10
|
+
@navigation_menu = false
|
11
|
+
@menu_item_options = {}
|
10
12
|
else
|
11
|
-
|
12
|
-
@
|
13
|
-
@menu_item = MenuItem.new(default_menu_options.merge(options))
|
13
|
+
self.menu_item_menu_name = options[:menu_name]
|
14
|
+
@menu_item_options = default_menu_options.merge(options)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
-
@
|
19
|
-
end
|
20
|
-
|
21
|
-
def parent_menu_item_name
|
22
|
-
return nil unless @parent_menu_item
|
23
|
-
ActiveAdmin::Resource::Name.new(nil, @parent_menu_item)
|
18
|
+
def menu_item_options
|
19
|
+
@menu_item_options ||= default_menu_options
|
24
20
|
end
|
25
21
|
|
26
|
-
# The default menu options to pass through to MenuItem.new
|
27
22
|
def default_menu_options
|
23
|
+
# These local variables are accessible to the procs.
|
24
|
+
menu_resource_class = respond_to?(:resource_class) ? resource_class : self
|
25
|
+
resource = self
|
28
26
|
{
|
29
|
-
:id
|
30
|
-
:label => proc{ plural_resource_label },
|
31
|
-
:url
|
27
|
+
:id => resource_name.plural,
|
28
|
+
:label => proc{ resource.plural_resource_label },
|
29
|
+
:url => proc{ resource.route_collection_path(params) },
|
30
|
+
:if => proc{ authorized?(:read, menu_resource_class) }
|
32
31
|
}
|
33
32
|
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
def navigation_menu_name=(menu_name)
|
35
|
+
@navigation_menu_name = menu_name
|
36
|
+
end
|
37
|
+
|
38
|
+
def navigation_menu_name
|
39
|
+
@navigation_menu_name ||= DEFAULT_MENU
|
40
|
+
case @navigation_menu_name
|
41
|
+
when Proc
|
42
|
+
controller.instance_eval(&@navigation_menu_name).to_sym
|
43
|
+
else
|
44
|
+
@navigation_menu_name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def navigation_menu
|
49
|
+
namespace.fetch_menu(navigation_menu_name)
|
38
50
|
end
|
39
51
|
|
40
|
-
|
52
|
+
def menu_item_menu_name=(menu_name)
|
53
|
+
@menu_item_menu_name = menu_name
|
54
|
+
end
|
55
|
+
|
56
|
+
def menu_item_menu_name
|
57
|
+
@menu_item_menu_name ||= DEFAULT_MENU
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_to_menu(menu_collection)
|
61
|
+
if include_in_menu?
|
62
|
+
@menu_item = menu_collection.add(menu_item_menu_name, menu_item_options)
|
63
|
+
end
|
64
|
+
end
|
41
65
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
66
|
+
def menu_item
|
67
|
+
@menu_item
|
68
|
+
end
|
69
|
+
|
70
|
+
# Should this resource be added to the menu system?
|
71
|
+
def include_in_menu?
|
72
|
+
@navigation_menu != false
|
46
73
|
end
|
74
|
+
|
47
75
|
end
|
48
76
|
end
|
49
77
|
end
|
@@ -17,20 +17,12 @@ module ActiveAdmin
|
|
17
17
|
|
18
18
|
# Returns the name to call this resource such as "Bank Account"
|
19
19
|
def resource_label
|
20
|
-
|
21
|
-
@options[:as]
|
22
|
-
else
|
23
|
-
resource_name.human(:default => resource_name.gsub('::', ' ').titleize)
|
24
|
-
end
|
20
|
+
resource_name.translate :count => 1, :default => resource_name.gsub('::', ' ').titleize
|
25
21
|
end
|
26
22
|
|
27
23
|
# Returns the plural version of this resource such as "Bank Accounts"
|
28
24
|
def plural_resource_label
|
29
|
-
|
30
|
-
@options[:as].pluralize
|
31
|
-
else
|
32
|
-
resource_name.human(:count => 1.1, :default => resource_label.pluralize.titleize)
|
33
|
-
end
|
25
|
+
resource_name.translate :count => 1.1, :default => resource_label.pluralize.titleize
|
34
26
|
end
|
35
27
|
end
|
36
28
|
|
@@ -46,6 +38,10 @@ module ActiveAdmin
|
|
46
38
|
end
|
47
39
|
end
|
48
40
|
|
41
|
+
def translate(options = {})
|
42
|
+
I18n.t i18n_key, {:scope => [:activerecord, :models]}.merge(options)
|
43
|
+
end
|
44
|
+
|
49
45
|
def proxy_for_initializer(klass, name)
|
50
46
|
return klass unless name
|
51
47
|
return StringClassProxy.new(klass, name) if klass
|
@@ -2,6 +2,11 @@ module ActiveAdmin
|
|
2
2
|
class Resource
|
3
3
|
module PagePresenters
|
4
4
|
|
5
|
+
# for setting default css class in admin ui
|
6
|
+
def default_index_class
|
7
|
+
@default_index
|
8
|
+
end
|
9
|
+
|
5
10
|
# A hash of page configurations for the controller indexed by action name
|
6
11
|
def page_presenters
|
7
12
|
@page_presenters ||= {}
|
@@ -12,15 +17,64 @@ module ActiveAdmin
|
|
12
17
|
# @param [String, Symbol] action The action to store this configuration for
|
13
18
|
# @param [PagePresenter] page_presenter The instance of PagePresenter to store
|
14
19
|
def set_page_presenter(action, page_presenter)
|
15
|
-
|
20
|
+
|
21
|
+
if action.to_s == "index" && page_presenter[:as]
|
22
|
+
index_class = find_index_class(page_presenter[:as])
|
23
|
+
page_presenter_key = index_class.index_name.to_sym
|
24
|
+
set_index_presenter page_presenter_key, page_presenter
|
25
|
+
else
|
26
|
+
page_presenters[action.to_sym] = page_presenter
|
27
|
+
end
|
28
|
+
|
16
29
|
end
|
17
30
|
|
18
31
|
# Returns a stored page config
|
19
32
|
#
|
20
33
|
# @param [Symbol, String] action The action to get the config for
|
34
|
+
# @param [String] type The string specified in the presenters index_name method
|
21
35
|
# @returns [PagePresenter, nil]
|
22
|
-
def get_page_presenter(action)
|
23
|
-
|
36
|
+
def get_page_presenter(action, type=nil)
|
37
|
+
|
38
|
+
if action.to_s == "index" && type && page_presenters[:index].kind_of?(Hash)
|
39
|
+
page_presenters[:index][type.to_sym]
|
40
|
+
elsif action.to_s == "index" && page_presenters[:index].kind_of?(Hash)
|
41
|
+
page_presenters[:index].default
|
42
|
+
else
|
43
|
+
page_presenters[action.to_sym]
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
# Stores a config for all index actions supplied
|
51
|
+
#
|
52
|
+
# @param [Symbol] index_as The index type to store in the configuration
|
53
|
+
# @param [PagePresenter] page_presenter The intance of PagePresenter to store
|
54
|
+
def set_index_presenter(index_as, page_presenter)
|
55
|
+
page_presenters[:index] ||= {}
|
56
|
+
|
57
|
+
#set first index as default value or the index with default param set to to true
|
58
|
+
if page_presenters[:index].empty? || page_presenter[:default] == true
|
59
|
+
page_presenters[:index].default = page_presenter
|
60
|
+
@default_index = find_index_class(page_presenter[:as])
|
61
|
+
end
|
62
|
+
|
63
|
+
page_presenters[:index][index_as] = page_presenter
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns the actual class for renderering the main content on the index
|
67
|
+
# page. To set this, use the :as option in the page_presenter block.
|
68
|
+
#
|
69
|
+
# @param [Symbol, Class] symbol_or_class The component symbol or class
|
70
|
+
# @return [Class]
|
71
|
+
def find_index_class(symbol_or_class)
|
72
|
+
case symbol_or_class
|
73
|
+
when Symbol
|
74
|
+
::ActiveAdmin::Views.const_get("IndexAs" + symbol_or_class.to_s.camelcase)
|
75
|
+
when Class
|
76
|
+
symbol_or_class
|
77
|
+
end
|
24
78
|
end
|
25
79
|
|
26
80
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
class Resource
|
3
|
+
module Routes
|
4
|
+
|
5
|
+
# Returns the routes prefix for this config
|
6
|
+
def route_prefix
|
7
|
+
namespace.module_name.try(:underscore)
|
8
|
+
end
|
9
|
+
|
10
|
+
def route_uncountable?
|
11
|
+
controller.resources_configuration[:self][:route_collection_name] ==
|
12
|
+
controller.resources_configuration[:self][:route_instance_name]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a symbol for the route to use to get to the
|
16
|
+
# collection of this resource
|
17
|
+
def route_collection_path(params = {})
|
18
|
+
route, required_params = [], []
|
19
|
+
|
20
|
+
route << route_prefix
|
21
|
+
|
22
|
+
if belongs_to? && !belongs_to_config.optional?
|
23
|
+
name = belongs_to_config.target.resource_name.singular
|
24
|
+
route << name
|
25
|
+
required_params << :"#{name}_id"
|
26
|
+
end
|
27
|
+
|
28
|
+
route << controller.resources_configuration[:self][:route_collection_name]
|
29
|
+
|
30
|
+
route << (route_uncountable? ? 'index_path' : 'path')
|
31
|
+
|
32
|
+
route_name = route.compact.join("_").to_sym
|
33
|
+
|
34
|
+
route_params = params.values_at(*required_params)
|
35
|
+
routes.send(route_name, *route_params)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def routes
|
41
|
+
Rails.application.routes.url_helpers
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'inherited_resources'
|
2
2
|
require 'active_admin/resource_controller/actions'
|
3
3
|
require 'active_admin/resource_controller/action_builder'
|
4
|
-
require 'active_admin/resource_controller/
|
5
|
-
require 'active_admin/resource_controller/collection'
|
4
|
+
require 'active_admin/resource_controller/data_access'
|
6
5
|
require 'active_admin/resource_controller/decorators'
|
7
6
|
require 'active_admin/resource_controller/scoping'
|
8
7
|
require 'active_admin/resource_controller/sidebars'
|
@@ -17,13 +16,10 @@ module ActiveAdmin
|
|
17
16
|
respond_to :html, :xml, :json
|
18
17
|
respond_to :csv, :only => :index
|
19
18
|
|
20
|
-
ACTIVE_ADMIN_ACTIONS = [:index, :show, :new, :create, :edit, :update, :destroy]
|
21
|
-
|
22
19
|
include Actions
|
23
20
|
include ActionBuilder
|
24
|
-
include Callbacks
|
25
|
-
include Collection
|
26
21
|
include Decorators
|
22
|
+
include DataAccess
|
27
23
|
include Scoping
|
28
24
|
include Sidebars
|
29
25
|
extend ResourceClassMethods
|
@@ -50,17 +46,6 @@ module ActiveAdmin
|
|
50
46
|
|
51
47
|
private
|
52
48
|
|
53
|
-
# Determine which layout to use.
|
54
|
-
#
|
55
|
-
# 1. If we're rendering a standard Active Admin action, we want layout(false)
|
56
|
-
# because these actions are subclasses of the Base page (which implementes
|
57
|
-
# all the required layout code)
|
58
|
-
# 2. If we're rendering a custom action, we'll use the active_admin layout so
|
59
|
-
# that users can render any template inside Active Admin.
|
60
|
-
def determine_active_admin_layout
|
61
|
-
ACTIVE_ADMIN_ACTIONS.include?(params[:action].to_sym) ? false : 'active_admin'
|
62
|
-
end
|
63
|
-
|
64
49
|
# Returns the renderer class to use for the given action.
|
65
50
|
def renderer_for(action)
|
66
51
|
active_admin_namespace.view_factory["#{action}_page"]
|