activeadmin 0.6.0 → 0.6.1
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/.gitignore +5 -1
- data/.travis.yml +1 -1
- data/.yardopts +2 -3
- data/CHANGELOG.md +180 -36
- data/CONTRIBUTING.md +12 -2
- data/Gemfile +9 -3
- data/README.rdoc +38 -65
- data/Rakefile +1 -3
- data/activeadmin.gemspec +10 -11
- data/app/assets/images/active_admin/index_list_icons/block_icon.svg +1 -1
- data/app/assets/images/active_admin/index_list_icons/blog_icon.svg +1 -1
- data/app/assets/images/active_admin/index_list_icons/grid_icon.svg +1 -1
- data/app/assets/images/active_admin/index_list_icons/table_icon.svg +1 -1
- data/app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee +2 -2
- data/app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee +2 -2
- data/app/assets/javascripts/active_admin/components/jquery.aa.popover.js.coffee +2 -2
- data/app/assets/javascripts/active_admin/components/jquery.aa.table-checkbox-toggler.js.coffee +2 -2
- data/app/assets/javascripts/active_admin/lib/namespace.js.coffee +2 -1
- data/app/assets/javascripts/active_admin/pages/application.js.coffee +6 -1
- data/app/assets/stylesheets/active_admin/_base.css.scss +29 -34
- data/app/assets/stylesheets/active_admin/_forms.css.scss +65 -62
- data/app/assets/stylesheets/active_admin/_header.css.scss +57 -45
- data/app/assets/stylesheets/active_admin/_typography.css.scss +9 -9
- data/app/assets/stylesheets/active_admin/components/_batch_actions.css.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +5 -5
- data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_comments.css.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_date_picker.css.scss +20 -20
- data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +16 -16
- data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +25 -23
- data/app/assets/stylesheets/active_admin/components/_grid.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_index_list.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_pagination.scss +10 -10
- data/app/assets/stylesheets/active_admin/components/_panels.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_popovers.css.scss +27 -27
- data/app/assets/stylesheets/active_admin/components/_scopes.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +10 -10
- data/app/assets/stylesheets/active_admin/components/_tables.css.scss +9 -9
- data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +3 -3
- data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +4 -4
- data/app/assets/stylesheets/active_admin/mixins/_icons.css.scss +4 -7
- data/app/assets/stylesheets/active_admin/mixins/_reset.css.scss +5 -5
- data/app/assets/stylesheets/active_admin/mixins/_rounded.css.scss +3 -3
- data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +6 -6
- data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +8 -8
- data/app/assets/stylesheets/active_admin/mixins/_typography.scss +1 -1
- data/app/assets/stylesheets/active_admin/mixins/_utilities.scss +1 -1
- data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +9 -1
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +1 -1
- data/app/assets/stylesheets/active_admin/print.css.scss +2 -8
- data/app/assets/stylesheets/active_admin/structure/_footer.scss +5 -5
- data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +13 -13
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +14 -14
- data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
- data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
- data/app/views/active_admin/devise/shared/_links.erb +8 -1
- data/app/views/active_admin/resource/index.csv.erb +3 -3
- data/app/views/layouts/active_admin_logged_out.html.erb +5 -3
- data/config/locales/bg.yml +101 -0
- data/{lib/active_admin → config}/locales/ca.yml +24 -7
- data/{lib/active_admin → config}/locales/cs.yml +34 -12
- data/{lib/active_admin → config}/locales/da.yml +29 -7
- data/config/locales/de-CH.yml +117 -0
- data/{lib/active_admin → config}/locales/de.yml +19 -9
- data/config/locales/en-GB.yml +90 -0
- data/{lib/active_admin → config}/locales/en.yml +16 -6
- data/config/locales/es.yml +106 -0
- data/{lib/active_admin/locales/es.yml → config/locales/es_MX.yml} +14 -8
- data/{lib/active_admin → config}/locales/fr.yml +14 -6
- data/{lib/active_admin → config}/locales/he.yml +16 -6
- data/{lib/active_admin → config}/locales/hr.yml +14 -6
- data/{lib/active_admin → config}/locales/hu.yml +31 -6
- data/{lib/active_admin → config}/locales/it.yml +14 -6
- data/{lib/active_admin → config}/locales/ja.yml +32 -7
- data/{lib/active_admin → config}/locales/ko.yml +14 -6
- data/{lib/active_admin → config}/locales/lt.yml +15 -6
- data/{lib/active_admin → config}/locales/lv.yml +14 -6
- data/{lib/active_admin → config}/locales/nl.yml +14 -6
- data/{lib/active_admin → config}/locales/no-NB.yml +14 -6
- data/{lib/active_admin → config}/locales/pl.yml +14 -6
- data/{lib/active_admin → config}/locales/pt-BR.yml +14 -6
- data/{lib/active_admin → config}/locales/pt-PT.yml +14 -6
- data/{lib/active_admin → config}/locales/ro.yml +32 -7
- data/{lib/active_admin → config}/locales/ru.yml +30 -8
- data/{lib/active_admin → config}/locales/sv-SE.yml +14 -6
- data/{lib/active_admin → config}/locales/tr.yml +15 -6
- data/config/locales/uk.yml +100 -0
- data/{lib/active_admin → config}/locales/vi.yml +15 -6
- data/{lib/active_admin → config}/locales/zh-CN.yml +15 -6
- data/{lib/active_admin → config}/locales/zh-TW.yml +15 -6
- data/docs/0-installation.md +22 -18
- data/docs/1-general-configuration.md +1 -1
- data/docs/10-custom-pages.md +3 -3
- data/docs/11-decorators.md +18 -2
- data/docs/12-arbre-components.md +53 -54
- data/docs/13-authorization-adapter.md +31 -10
- data/docs/2-resource-customization.md +16 -1
- data/docs/3-index-pages.md +13 -1
- data/docs/3-index-pages/create-an-index.md +4 -4
- data/docs/3-index-pages/index-as-block.md +1 -1
- data/docs/3-index-pages/index-as-blog.md +1 -1
- data/docs/3-index-pages/index-as-grid.md +1 -1
- data/docs/4-csv-format.md +4 -4
- data/docs/5-forms.md +46 -3
- data/docs/{6-show-screens.md → 6-show-pages.md} +3 -3
- data/docs/8-custom-actions.md +3 -3
- data/docs/9-batch-actions.md +9 -1
- data/features/action_item.feature +6 -6
- data/features/authorization_cancan.feature +1 -1
- data/features/belongs_to.feature +3 -3
- data/features/breadcrumb.feature +2 -2
- data/features/comments/commenting.feature +7 -5
- data/features/dashboard.feature +0 -51
- data/features/favicon.feature +20 -0
- data/features/global_navigation.feature +0 -1
- data/features/index/batch_actions.feature +12 -11
- data/features/index/filters.feature +6 -6
- data/features/index/format_as_csv.feature +4 -5
- data/features/index/index_as_blog.feature +20 -1
- data/features/index/index_as_table.feature +1 -1
- data/features/index/index_blank_slate.feature +3 -3
- data/features/index/index_parameters.feature +4 -10
- data/features/index/index_scope_to.feature +24 -0
- data/features/index/index_scopes.feature +17 -5
- data/features/index/pagination.feature +15 -0
- data/features/registering_pages.feature +1 -1
- data/features/registering_resources.feature +2 -2
- data/features/show/default_content.feature +3 -3
- data/features/sidebar_sections.feature +3 -3
- data/features/specifying_actions.feature +1 -1
- data/features/step_definitions/additional_web_steps.rb +3 -16
- data/features/step_definitions/asset_steps.rb +5 -1
- data/features/step_definitions/attribute_steps.rb +4 -4
- data/features/step_definitions/batch_action_steps.rb +25 -74
- data/features/step_definitions/breadcrumb_steps.rb +1 -3
- data/features/step_definitions/comment_steps.rb +0 -1
- data/features/step_definitions/configuration_steps.rb +53 -69
- data/features/step_definitions/dashboard_steps.rb +2 -2
- data/features/step_definitions/factory_steps.rb +17 -33
- data/features/step_definitions/filter_steps.rb +2 -2
- data/features/step_definitions/format_steps.rb +10 -14
- data/features/step_definitions/index_scope_steps.rb +9 -25
- data/features/step_definitions/index_views_steps.rb +1 -1
- data/features/step_definitions/sidebar_steps.rb +2 -1
- data/features/step_definitions/site_title_steps.rb +1 -1
- data/features/step_definitions/table_steps.rb +6 -1
- data/features/step_definitions/user_steps.rb +23 -38
- data/features/step_definitions/web_steps.rb +18 -147
- data/features/support/env.rb +13 -34
- data/features/support/paths.rb +2 -0
- data/features/users/logging_in.feature +2 -2
- data/features/users/logging_out.feature +0 -12
- data/features/users/resetting_password.feature +1 -1
- data/lib/active_admin.rb +4 -17
- data/lib/active_admin/abstract_view_factory.rb +1 -1
- data/lib/active_admin/application.rb +19 -28
- data/lib/active_admin/asset_registration.rb +7 -25
- data/lib/active_admin/authorization_adapter.rb +9 -5
- data/lib/active_admin/base_controller.rb +2 -2
- data/lib/active_admin/base_controller/authorization.rb +25 -27
- data/lib/active_admin/batch_actions/resource_extension.rb +3 -3
- data/lib/active_admin/batch_actions/views/batch_action_selector.rb +1 -1
- data/lib/active_admin/batch_actions/views/selection_cells.rb +1 -1
- data/lib/active_admin/callbacks.rb +1 -1
- data/lib/active_admin/cancan_adapter.rb +2 -2
- data/lib/active_admin/comments.rb +32 -38
- data/lib/active_admin/comments/comment.rb +6 -8
- data/lib/active_admin/comments/views.rb +0 -1
- data/lib/active_admin/comments/views/active_admin_comments.rb +27 -38
- data/lib/active_admin/csv_builder.rb +4 -6
- data/lib/active_admin/dependency_checker.rb +4 -0
- data/lib/active_admin/deprecation.rb +3 -3
- data/lib/active_admin/dsl.rb +5 -5
- data/lib/active_admin/engine.rb +1 -1
- data/lib/active_admin/filters.rb +2 -1
- data/lib/active_admin/filters/forms.rb +36 -43
- data/lib/active_admin/filters/formtastic_addons.rb +45 -0
- data/lib/active_admin/filters/resource_extension.rb +9 -1
- data/lib/active_admin/form_builder.rb +30 -19
- data/lib/active_admin/helpers/optional_display.rb +11 -13
- data/lib/active_admin/helpers/settings.rb +50 -8
- data/lib/active_admin/inputs/filter_base.rb +5 -18
- data/lib/active_admin/inputs/filter_base/search_method_select.rb +73 -0
- data/lib/active_admin/inputs/filter_boolean_input.rb +6 -14
- data/lib/active_admin/inputs/filter_check_boxes_input.rb +1 -1
- data/lib/active_admin/inputs/filter_numeric_input.rb +2 -47
- data/lib/active_admin/inputs/filter_select_input.rb +32 -10
- data/lib/active_admin/inputs/filter_string_input.rb +12 -14
- data/lib/active_admin/namespace.rb +8 -40
- data/lib/active_admin/page.rb +2 -2
- data/lib/active_admin/page_dsl.rb +1 -1
- data/lib/active_admin/reloader.rb +3 -3
- data/lib/active_admin/resource.rb +16 -23
- data/lib/active_admin/resource/belongs_to.rb +8 -5
- data/lib/active_admin/resource/menu.rb +10 -23
- data/lib/active_admin/resource/naming.rb +3 -3
- data/lib/active_admin/resource/page_presenters.rb +2 -2
- data/lib/active_admin/resource/routes.rb +74 -21
- data/lib/active_admin/resource/scope_to.rb +74 -0
- data/lib/active_admin/resource/scopes.rb +8 -4
- data/lib/active_admin/resource_collection.rb +20 -66
- data/lib/active_admin/resource_controller.rb +12 -16
- data/lib/active_admin/resource_controller/data_access.rb +19 -22
- data/lib/active_admin/resource_controller/resource_class_methods.rb +2 -2
- data/lib/active_admin/resource_controller/scoping.rb +4 -9
- data/lib/active_admin/resource_dsl.rb +5 -32
- data/lib/active_admin/router.rb +34 -47
- data/lib/active_admin/scope.rb +5 -3
- data/lib/active_admin/sidebar_section.rb +1 -1
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +1 -1
- data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +8 -8
- data/lib/active_admin/view_helpers/display_helper.rb +15 -6
- data/lib/active_admin/view_helpers/download_format_links_helper.rb +2 -2
- data/lib/active_admin/view_helpers/form_helper.rb +6 -1
- data/lib/active_admin/view_helpers/icon_helper.rb +1 -1
- data/lib/active_admin/view_helpers/method_or_proc_helper.rb +5 -5
- data/lib/active_admin/view_helpers/title_helper.rb +1 -1
- data/lib/active_admin/views/components/action_list_popover.rb +6 -6
- data/lib/active_admin/views/components/attributes_table.rb +9 -12
- data/lib/active_admin/views/components/blank_slate.rb +4 -4
- data/lib/active_admin/views/components/columns.rb +1 -1
- data/lib/active_admin/views/components/index_list.rb +1 -1
- data/lib/active_admin/views/components/paginated_collection.rb +20 -12
- data/lib/active_admin/views/components/panel.rb +1 -1
- data/lib/active_admin/views/components/scopes.rb +2 -1
- data/lib/active_admin/views/components/sidebar_section.rb +1 -1
- data/lib/active_admin/views/components/status_tag.rb +1 -1
- data/lib/active_admin/views/header.rb +2 -2
- data/lib/active_admin/views/index_as_blog.rb +16 -3
- data/lib/active_admin/views/index_as_table.rb +2 -2
- data/lib/active_admin/views/pages/base.rb +8 -3
- data/lib/active_admin/views/pages/form.rb +2 -2
- data/lib/active_admin/views/pages/index.rb +19 -17
- data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +1 -1
- data/lib/generators/active_admin/assets/templates/3.1/active_admin.css.scss +1 -13
- data/lib/generators/active_admin/devise/devise_generator.rb +22 -1
- data/lib/generators/active_admin/install/install_generator.rb +1 -5
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +40 -19
- data/lib/generators/active_admin/install/templates/admin_user.rb.erb +18 -18
- data/lib/generators/active_admin/install/templates/migrations/create_active_admin_comments.rb +19 -0
- data/lib/generators/active_admin/resource/resource_generator.rb +1 -1
- data/lib/generators/active_admin/resource/templates/admin.rb +1 -1
- data/script/use_rails +1 -1
- data/spec/integration/memory_spec.rb +3 -2
- data/spec/javascripts/coffeescripts/jquery.aa.checkbox-toggler-spec.js.coffee +4 -4
- data/spec/javascripts/coffeescripts/jquery.aa.popover-spec.js.coffee +1 -1
- data/spec/javascripts/coffeescripts/jquery.aa.table-checkbox-toggler-spec.js.coffee +2 -2
- data/spec/javascripts/compiled/jquery.aa.checkbox-toggler-spec.js +4 -4
- data/spec/javascripts/compiled/jquery.aa.popover-spec.js +1 -1
- data/spec/javascripts/compiled/jquery.aa.table-checkbox-toggler-spec.js +2 -2
- data/spec/spec_helper.rb +16 -6
- data/spec/spec_helper_without_rails.rb +2 -0
- data/spec/support/deferred_garbage_collection.rb +19 -0
- data/spec/support/jslint.yml +1 -1
- data/spec/support/rails_template.rb +29 -27
- data/spec/support/templates/admin/stores.rb +5 -1
- data/spec/unit/abstract_view_factory_spec.rb +1 -1
- data/spec/unit/action_builder_spec.rb +7 -7
- data/spec/unit/active_admin_spec.rb +0 -14
- data/spec/unit/application_spec.rb +16 -17
- data/spec/unit/asset_registration_spec.rb +21 -8
- data/spec/unit/authorization/authorization_adapter_spec.rb +3 -3
- data/spec/unit/authorization/controller_authorization_spec.rb +16 -24
- data/spec/unit/batch_actions/resource_spec.rb +11 -11
- data/spec/unit/belongs_to_spec.rb +1 -1
- data/spec/unit/cancan_adapter_spec.rb +11 -3
- data/spec/unit/comments_spec.rb +10 -28
- data/spec/unit/controller_filters_spec.rb +22 -24
- data/spec/unit/csv_builder_spec.rb +3 -3
- data/spec/unit/devise_spec.rb +10 -10
- data/spec/unit/filters/filter_form_builder_spec.rb +140 -45
- data/spec/unit/filters/resource_spec.rb +20 -19
- data/spec/unit/form_builder_spec.rb +122 -70
- data/spec/unit/menu_item_spec.rb +3 -3
- data/spec/unit/namespace/authorization_spec.rb +4 -8
- data/spec/unit/namespace/register_page_spec.rb +1 -1
- data/spec/unit/namespace/register_resource_spec.rb +12 -7
- data/spec/unit/namespace_spec.rb +4 -10
- data/spec/unit/page_spec.rb +1 -1
- data/spec/unit/resource/menu_spec.rb +1 -1
- data/spec/unit/resource/naming_spec.rb +9 -0
- data/spec/unit/resource/pagination_spec.rb +2 -2
- data/spec/unit/resource/routes_spec.rb +73 -0
- data/spec/unit/resource/scopes_spec.rb +1 -1
- data/spec/unit/resource_collection_spec.rb +95 -43
- data/spec/unit/resource_registration_spec.rb +3 -12
- data/spec/unit/resource_spec.rb +41 -48
- data/spec/unit/routing_spec.rb +10 -64
- data/spec/unit/scope_spec.rb +19 -0
- data/spec/unit/settings_spec.rb +88 -0
- data/spec/unit/view_factory_spec.rb +1 -0
- data/spec/unit/{breadcrumbs_spec.rb → view_helpers/breadcrumbs_spec.rb} +16 -7
- data/spec/unit/view_helpers/display_name_spec.rb +41 -0
- data/spec/unit/view_helpers/form_helper_spec.rb +36 -2
- data/spec/unit/views/components/attributes_table_spec.rb +17 -9
- data/spec/unit/views/components/batch_action_popover_spec.rb +4 -4
- data/spec/unit/views/components/index_list_spec.rb +2 -2
- data/spec/unit/views/components/paginated_collection_spec.rb +42 -0
- data/spec/unit/views/components/panel_spec.rb +8 -0
- data/spec/unit/views/components/site_title_spec.rb +2 -2
- data/spec/unit/views/components/table_for_spec.rb +4 -4
- data/spec/unit/views/pages/form_spec.rb +35 -0
- data/spec/unit/views/pages/layout_spec.rb +1 -1
- data/spec/unit/views/tabbed_navigation_spec.rb +10 -10
- data/tasks/parallel_tests.rake +1 -1
- data/tasks/test.rake +4 -1
- metadata +117 -106
- data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +0 -5
- data/lib/active_admin/comments/views/active_admin_comment.rb +0 -0
- data/lib/active_admin/dashboards.rb +0 -68
- data/lib/active_admin/dashboards/dashboard_controller.rb +0 -50
- data/lib/active_admin/dashboards/section.rb +0 -34
- data/lib/active_admin/locales/bg.yml +0 -77
- data/lib/generators/active_admin/install/templates/migrations/1_create_admin_notes.rb +0 -17
- data/lib/generators/active_admin/install/templates/migrations/2_move_admin_notes_to_comments.rb +0 -26
- data/spec/unit/base_controller_spec.rb +0 -6
- data/spec/unit/dashboard_controller_spec.rb +0 -76
- data/spec/unit/dashboard_section_spec.rb +0 -56
- data/spec/unit/dashboards_spec.rb +0 -59
- data/spec/unit/display_name_spec.rb +0 -29
@@ -9,15 +9,15 @@ module ActiveAdmin
|
|
9
9
|
# The resource which initiated this relationship
|
10
10
|
attr_reader :owner
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
@owner, @target_name =
|
14
|
-
@options = options
|
12
|
+
def initialize(owner, target_name, options = {})
|
13
|
+
@owner, @target_name, @options = owner, target_name, options
|
15
14
|
end
|
16
15
|
|
17
16
|
# Returns the target resource class or raises an exception if it doesn't exist
|
18
17
|
def target
|
19
|
-
|
20
|
-
|
18
|
+
key = @target_name.to_s.camelize
|
19
|
+
namespace.resources[key] or raise TargetNotFound, "Could not find #{key} in" +
|
20
|
+
" #{namespace.name} with #{namespace.resources.map(&:resource_name)}"
|
21
21
|
end
|
22
22
|
|
23
23
|
def namespace
|
@@ -28,6 +28,9 @@ module ActiveAdmin
|
|
28
28
|
@options[:optional]
|
29
29
|
end
|
30
30
|
|
31
|
+
def required?
|
32
|
+
!optional?
|
33
|
+
end
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
@@ -3,15 +3,15 @@ module ActiveAdmin
|
|
3
3
|
|
4
4
|
module Menu
|
5
5
|
|
6
|
-
# Set the menu options.
|
7
|
-
# call
|
6
|
+
# Set the menu options.
|
7
|
+
# To disable this menu item, call `menu(false)` from the DSL
|
8
8
|
def menu_item_options=(options)
|
9
9
|
if options == false
|
10
|
-
@
|
10
|
+
@include_in_menu = false
|
11
11
|
@menu_item_options = {}
|
12
12
|
else
|
13
|
-
|
14
|
-
@menu_item_options
|
13
|
+
@navigation_menu_name = options[:menu_name]
|
14
|
+
@menu_item_options = default_menu_options.merge options
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -31,13 +31,10 @@ module ActiveAdmin
|
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
@navigation_menu_name = menu_name
|
36
|
-
end
|
34
|
+
attr_writer :navigation_menu_name
|
37
35
|
|
38
36
|
def navigation_menu_name
|
39
|
-
@navigation_menu_name ||= DEFAULT_MENU
|
40
|
-
case @navigation_menu_name
|
37
|
+
case @navigation_menu_name ||= DEFAULT_MENU
|
41
38
|
when Proc
|
42
39
|
controller.instance_eval(&@navigation_menu_name).to_sym
|
43
40
|
else
|
@@ -49,27 +46,17 @@ module ActiveAdmin
|
|
49
46
|
namespace.fetch_menu(navigation_menu_name)
|
50
47
|
end
|
51
48
|
|
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
49
|
def add_to_menu(menu_collection)
|
61
50
|
if include_in_menu?
|
62
|
-
@menu_item = menu_collection.add
|
51
|
+
@menu_item = menu_collection.add navigation_menu_name, menu_item_options
|
63
52
|
end
|
64
53
|
end
|
65
54
|
|
66
|
-
|
67
|
-
@menu_item
|
68
|
-
end
|
55
|
+
attr_reader :menu_item
|
69
56
|
|
70
57
|
# Should this resource be added to the menu system?
|
71
58
|
def include_in_menu?
|
72
|
-
@
|
59
|
+
@include_in_menu != false
|
73
60
|
end
|
74
61
|
|
75
62
|
end
|
@@ -17,12 +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
|
-
resource_name.translate :count => 1,
|
20
|
+
resource_name.translate :count => 1, :default => resource_name.gsub('::', ' ').titleize
|
21
21
|
end
|
22
22
|
|
23
23
|
# Returns the plural version of this resource such as "Bank Accounts"
|
24
|
-
def plural_resource_label
|
25
|
-
resource_name.translate :count => 1.1, :default => resource_label.pluralize.titleize
|
24
|
+
def plural_resource_label(options = {})
|
25
|
+
resource_name.translate ({:count => 1.1, :default => resource_label.pluralize.titleize}).merge(options)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -34,9 +34,9 @@ module ActiveAdmin
|
|
34
34
|
# @param [String] type The string specified in the presenters index_name method
|
35
35
|
# @returns [PagePresenter, nil]
|
36
36
|
def get_page_presenter(action, type=nil)
|
37
|
-
|
37
|
+
|
38
38
|
if action.to_s == "index" && type && page_presenters[:index].kind_of?(Hash)
|
39
|
-
page_presenters[:index][type.to_sym]
|
39
|
+
page_presenters[:index][type.to_sym]
|
40
40
|
elsif action.to_s == "index" && page_presenters[:index].kind_of?(Hash)
|
41
41
|
page_presenters[:index].default
|
42
42
|
else
|
@@ -1,6 +1,19 @@
|
|
1
1
|
module ActiveAdmin
|
2
2
|
class Resource
|
3
3
|
module Routes
|
4
|
+
# @params params [Hash] of params: {study_id: 3}
|
5
|
+
# @return [String] the path to this resource collection page
|
6
|
+
# @example "/admin/posts"
|
7
|
+
def route_collection_path(params = {})
|
8
|
+
RouteBuilder.new(self).collection_path(params)
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param resource [ActiveRecord::Base] the instance we want the path of
|
12
|
+
# @return [String] the path to this resource collection page
|
13
|
+
# @example "/admin/posts/1"
|
14
|
+
def route_instance_path(resource)
|
15
|
+
RouteBuilder.new(self).instance_path(resource)
|
16
|
+
end
|
4
17
|
|
5
18
|
# Returns the routes prefix for this config
|
6
19
|
def route_prefix
|
@@ -8,39 +21,79 @@ module ActiveAdmin
|
|
8
21
|
end
|
9
22
|
|
10
23
|
def route_uncountable?
|
11
|
-
controller.resources_configuration[:self]
|
12
|
-
|
24
|
+
config = controller.resources_configuration[:self]
|
25
|
+
|
26
|
+
config[:route_collection_name] == config[:route_instance_name]
|
13
27
|
end
|
14
28
|
|
15
|
-
|
16
|
-
# collection of this resource
|
17
|
-
def route_collection_path(params = {})
|
18
|
-
route, required_params = [], []
|
29
|
+
private
|
19
30
|
|
20
|
-
|
31
|
+
class RouteBuilder
|
32
|
+
def initialize(resource)
|
33
|
+
@resource = resource
|
34
|
+
end
|
21
35
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
36
|
+
def collection_path(params)
|
37
|
+
route_name = route_name(
|
38
|
+
resource.controller.resources_configuration[:self][:route_collection_name],
|
39
|
+
(resource.route_uncountable? ? 'index_path' : 'path')
|
40
|
+
)
|
41
|
+
|
42
|
+
routes.send(route_name, *route_collection_params(params))
|
26
43
|
end
|
27
44
|
|
28
|
-
|
45
|
+
# @return [String] the path to this resource collection page
|
46
|
+
# @param instance [ActiveRecord::Base] the instance we want the path of
|
47
|
+
# @example "/admin/posts/1"
|
48
|
+
def instance_path(instance)
|
49
|
+
route_name = route_name(resource.controller.resources_configuration[:self][:route_instance_name])
|
29
50
|
|
30
|
-
|
51
|
+
routes.send(route_name, *route_instance_params(instance))
|
52
|
+
end
|
31
53
|
|
32
|
-
|
54
|
+
private
|
33
55
|
|
34
|
-
|
35
|
-
routes.send(route_name, *route_params)
|
36
|
-
end
|
56
|
+
attr_reader :resource
|
37
57
|
|
38
|
-
|
58
|
+
def route_name(resource_path_name, suffix = 'path')
|
59
|
+
route = []
|
39
60
|
|
40
|
-
|
41
|
-
|
42
|
-
|
61
|
+
route << resource.route_prefix # "admin"
|
62
|
+
route << belongs_to_name if nested? # "category"
|
63
|
+
route << resource_path_name # "posts" or "post"
|
64
|
+
route << suffix # "path" or "index path"
|
43
65
|
|
66
|
+
route.compact.join('_').to_sym # :admin_category_posts_path
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# @return params to pass to instance path
|
71
|
+
def route_instance_params(instance)
|
72
|
+
if nested?
|
73
|
+
[instance.send(belongs_to_name).to_param, instance.to_param]
|
74
|
+
else
|
75
|
+
instance.to_param
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def route_collection_params(params)
|
80
|
+
if nested?
|
81
|
+
params[:"#{belongs_to_name}_id"]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def nested?
|
86
|
+
resource.belongs_to? && resource.belongs_to_config.required?
|
87
|
+
end
|
88
|
+
|
89
|
+
def belongs_to_name
|
90
|
+
resource.belongs_to_config.target.resource_name.singular if nested?
|
91
|
+
end
|
92
|
+
|
93
|
+
def routes
|
94
|
+
Rails.application.routes.url_helpers
|
95
|
+
end
|
96
|
+
end
|
44
97
|
end
|
45
98
|
end
|
46
99
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
class Resource
|
3
|
+
module ScopeTo
|
4
|
+
|
5
|
+
# Scope this controller to some object which has a relation
|
6
|
+
# to the resource. Can either accept a block or a symbol
|
7
|
+
# of a method to call.
|
8
|
+
#
|
9
|
+
# Eg:
|
10
|
+
#
|
11
|
+
# ActiveAdmin.register Post do
|
12
|
+
# scope_to :current_user
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# Then every time we instantiate and object, it would call
|
16
|
+
#
|
17
|
+
# current_user.posts.build
|
18
|
+
#
|
19
|
+
# By default Active Admin will use the resource name to build a
|
20
|
+
# method to call as the association. If its different, you can
|
21
|
+
# pass in the association_method as an option.
|
22
|
+
#
|
23
|
+
# scope_to :current_user, :association_method => :blog_posts
|
24
|
+
#
|
25
|
+
# will result in the following
|
26
|
+
#
|
27
|
+
# current_user.blog_posts.build
|
28
|
+
#
|
29
|
+
# To conditionally use this scope, you can use conditional procs
|
30
|
+
#
|
31
|
+
# scope_to :current_user, :if => proc{ admin_user_signed_in? }
|
32
|
+
#
|
33
|
+
# or
|
34
|
+
#
|
35
|
+
# scope_to :current_user, :unless => proc{ current_user.admin? }
|
36
|
+
#
|
37
|
+
def scope_to(*args, &block)
|
38
|
+
options = args.extract_options!
|
39
|
+
method = args.first
|
40
|
+
|
41
|
+
scope_to_config[:method] = block || method
|
42
|
+
scope_to_config[:association_method] = options[:association_method]
|
43
|
+
scope_to_config[:if] = options[:if]
|
44
|
+
scope_to_config[:unless] = options[:unless]
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def scope_to_association_method
|
49
|
+
scope_to_config[:association_method]
|
50
|
+
end
|
51
|
+
|
52
|
+
def scope_to_method
|
53
|
+
scope_to_config[:method]
|
54
|
+
end
|
55
|
+
|
56
|
+
def scope_to_config
|
57
|
+
@scope_to_config ||= {
|
58
|
+
:method => nil,
|
59
|
+
:association_method => nil,
|
60
|
+
:if => nil,
|
61
|
+
:unless => nil
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def scope_to?(context = nil)
|
66
|
+
return false if scope_to_method.nil?
|
67
|
+
return render_in_context(context, scope_to_config[:if]) unless scope_to_config[:if].nil?
|
68
|
+
return !render_in_context(context, scope_to_config[:unless]) unless scope_to_config[:unless].nil?
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -13,8 +13,14 @@ module ActiveAdmin
|
|
13
13
|
scopes.find{|s| s.id == id }
|
14
14
|
end
|
15
15
|
|
16
|
-
def default_scope
|
17
|
-
|
16
|
+
def default_scope(context = nil)
|
17
|
+
scopes.detect do |scope|
|
18
|
+
if scope.default_block.is_a?(Proc)
|
19
|
+
render_in_context(context, scope.default_block)
|
20
|
+
else
|
21
|
+
scope.default_block
|
22
|
+
end
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
# Create a new scope object for this resource.
|
@@ -36,8 +42,6 @@ module ActiveAdmin
|
|
36
42
|
self.scopes << scope
|
37
43
|
end
|
38
44
|
|
39
|
-
@default_scope = scope if options[:default]
|
40
|
-
|
41
45
|
scope
|
42
46
|
end
|
43
47
|
|
@@ -1,87 +1,41 @@
|
|
1
1
|
module ActiveAdmin
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# Holds on to a collection of Resources. Is an Enumerable object
|
6
|
-
# so it has some Array like qualities.
|
7
|
-
#
|
8
|
-
# Adding a resource assumes that the object responds to #resource_name
|
2
|
+
# This is a container for resources, which acts much like a Hash.
|
3
|
+
# It's assumed that an added resource responds to `resource_name`.
|
9
4
|
class ResourceCollection
|
10
5
|
include Enumerable
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :@resources, :empty?, :has_key?, :keys, :values, :[]=
|
11
8
|
|
12
9
|
def initialize
|
13
|
-
@
|
10
|
+
@resources = {}
|
14
11
|
end
|
15
12
|
|
16
|
-
# Add a new resource to the collection. If the resource_name already
|
17
|
-
# exists, the exiting resource is returned.
|
18
|
-
#
|
19
|
-
# @param [Resource, Page] resource The resource to add to the collection
|
20
|
-
#
|
21
|
-
# @returns [Resource, Page] Either the existing resource or the new one
|
22
13
|
def add(resource)
|
23
|
-
|
24
|
-
existing_resource = find_by_key(resource.resource_name)
|
25
|
-
ensure_resource_classes_match!(existing_resource, resource)
|
26
|
-
existing_resource
|
27
|
-
else
|
28
|
-
@resource_hash[resource.resource_name] = resource
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# @returns [Array] An array of all the resources
|
33
|
-
def resources
|
34
|
-
@resource_hash.values
|
14
|
+
@resources[resource.resource_name] ||= resource
|
35
15
|
end
|
36
16
|
|
37
|
-
#
|
17
|
+
# Changes `each` to pass in the value, instead of both the key and value.
|
38
18
|
def each(&block)
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
# @returns [Array] An array of all the keys registered in the collection
|
43
|
-
def keys
|
44
|
-
@resource_hash.keys
|
45
|
-
end
|
46
|
-
|
47
|
-
# @returns [Boolean] If the key has been registered in the collection
|
48
|
-
def has_key?(resource_name)
|
49
|
-
@resource_hash.has_key?(resource_name)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Finds a resource by a given key
|
53
|
-
def find_by_key(resource_name)
|
54
|
-
@resource_hash[resource_name]
|
19
|
+
values.each &block
|
55
20
|
end
|
56
21
|
|
57
|
-
# Finds a resource based on
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
match =
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
base_class_name = resource_class.base_class.to_s
|
66
|
-
resources_with_a_resource_class.find{|r| r.resource_class.to_s == base_class_name }
|
67
|
-
else
|
68
|
-
nil
|
22
|
+
# Finds a resource based on the resource name, the resource class, or the base class.
|
23
|
+
def [](klass)
|
24
|
+
if match = @resources[klass]
|
25
|
+
match
|
26
|
+
elsif match = real_resources.detect{ |r| [r.resource_name.to_s, r.resource_class.to_s].include? klass.to_s }
|
27
|
+
match
|
28
|
+
elsif klass.respond_to? :base_class
|
29
|
+
real_resources.detect{ |r| r.resource_class.to_s == klass.base_class.to_s }
|
69
30
|
end
|
70
31
|
end
|
71
32
|
|
72
33
|
private
|
73
34
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
def ensure_resource_classes_match!(existing_resource, resource)
|
79
|
-
return unless existing_resource.respond_to?(:resource_class) && resource.respond_to?(:resource_class)
|
80
|
-
|
81
|
-
if existing_resource.resource_class != resource.resource_class
|
82
|
-
raise ActiveAdmin::ResourceMismatchError,
|
83
|
-
"Tried to register #{resource.resource_class} as #{resource.resource_name} but already registered to #{existing_resource.resource_class}"
|
84
|
-
end
|
35
|
+
# REFACTOR: ResourceCollection currently stores Resource and Page objects. That doesn't
|
36
|
+
# make sense, because by definition a ResourceCollection is a collection of resources.
|
37
|
+
def real_resources
|
38
|
+
select{ |r| r.respond_to? :resource_class }
|
85
39
|
end
|
86
40
|
|
87
41
|
end
|