activeadmin 1.0.0.pre4 → 1.0.0.pre5

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.

Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -3
  3. data/.travis.yml +48 -26
  4. data/Appraisals +103 -0
  5. data/CHANGELOG.md +12 -1
  6. data/CONTRIBUTING.md +85 -32
  7. data/Gemfile +13 -38
  8. data/README.md +10 -26
  9. data/Rakefile +41 -9
  10. data/activeadmin.gemspec +7 -4
  11. data/app/assets/javascripts/active_admin/initializers/filters.js.coffee +10 -3
  12. data/app/assets/javascripts/active_admin/jquery_ui.js.erb +11 -4
  13. data/app/assets/javascripts/active_admin/lib/checkbox-toggler.js.coffee +8 -0
  14. data/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee +1 -1
  15. data/app/assets/javascripts/active_admin/lib/per_page.js.coffee +14 -3
  16. data/app/assets/stylesheets/active_admin/_forms.scss +1 -0
  17. data/app/views/active_admin/devise/registrations/new.html.erb +1 -1
  18. data/codecov.yml +23 -0
  19. data/config/locales/es-MX.yml +1 -1
  20. data/config/locales/es.yml +1 -1
  21. data/config/locales/ru.yml +1 -0
  22. data/config/locales/sk.yml +110 -0
  23. data/docs/0-installation.md +3 -0
  24. data/docs/1-general-configuration.md +11 -0
  25. data/docs/10-custom-pages.md +25 -0
  26. data/docs/11-decorators.md +3 -0
  27. data/docs/12-arbre-components.md +3 -0
  28. data/docs/13-authorization-adapter.md +3 -0
  29. data/docs/14-gotchas.md +19 -0
  30. data/docs/2-resource-customization.md +21 -2
  31. data/docs/3-index-pages.md +21 -0
  32. data/docs/3-index-pages/custom-index.md +3 -0
  33. data/docs/3-index-pages/index-as-block.md +3 -0
  34. data/docs/3-index-pages/index-as-blog.md +3 -0
  35. data/docs/3-index-pages/index-as-grid.md +3 -0
  36. data/docs/3-index-pages/index-as-table.md +22 -0
  37. data/docs/4-csv-format.md +15 -0
  38. data/docs/5-forms.md +7 -3
  39. data/docs/6-show-pages.md +3 -0
  40. data/docs/7-sidebars.md +3 -0
  41. data/docs/8-custom-actions.md +3 -0
  42. data/docs/9-batch-actions.md +4 -1
  43. data/docs/CNAME +1 -0
  44. data/docs/Gemfile +2 -0
  45. data/docs/_config.yml +2 -0
  46. data/docs/_includes/footer.html +8 -0
  47. data/docs/_includes/google-analytics.html +16 -0
  48. data/docs/_includes/head.html +7 -0
  49. data/docs/_includes/toc.html +97 -0
  50. data/docs/_includes/top-menu.html +9 -0
  51. data/docs/_layouts/default.html +21 -0
  52. data/docs/documentation.md +62 -0
  53. data/docs/images/activeadmin.png +0 -0
  54. data/docs/images/code-header.png +0 -0
  55. data/docs/images/divider.png +0 -0
  56. data/docs/images/features.png +0 -0
  57. data/docs/index.html +130 -0
  58. data/docs/stylesheets/main.css +1199 -0
  59. data/features/action_item.feature +2 -2
  60. data/features/authorization_cancan.feature +3 -3
  61. data/features/belongs_to.feature +60 -2
  62. data/features/comments/commenting.feature +7 -7
  63. data/features/development_reloading.feature +1 -1
  64. data/features/edit_page.feature +9 -9
  65. data/features/footer.feature +28 -0
  66. data/features/i18n.feature +11 -0
  67. data/features/index/batch_actions.feature +28 -6
  68. data/features/index/filters.feature +31 -11
  69. data/features/index/format_as_csv.feature +13 -13
  70. data/features/index/formats.feature +4 -4
  71. data/features/index/index_as_block.feature +1 -1
  72. data/features/index/index_as_blog.feature +6 -6
  73. data/features/index/index_as_grid.feature +3 -3
  74. data/features/index/index_as_table.feature +11 -11
  75. data/features/index/index_blank_slate.feature +4 -4
  76. data/features/index/index_parameters.feature +10 -10
  77. data/features/index/index_scope_to.feature +3 -3
  78. data/features/index/index_scopes.feature +37 -18
  79. data/features/index/page_title.feature +3 -3
  80. data/features/index/pagination.feature +1 -1
  81. data/features/index/switch_index_view.feature +8 -8
  82. data/features/menu.feature +3 -3
  83. data/features/new_page.feature +8 -8
  84. data/features/registering_assets.feature +1 -1
  85. data/features/registering_pages.feature +73 -2
  86. data/features/registering_resources.feature +1 -1
  87. data/features/renamed_resource.feature +1 -1
  88. data/features/show/page_title.feature +3 -3
  89. data/features/sidebar_sections.feature +6 -6
  90. data/features/specifying_actions.feature +29 -4
  91. data/features/step_definitions/factory_steps.rb +1 -1
  92. data/features/step_definitions/footer_steps.rb +11 -0
  93. data/features/step_definitions/i18n_steps.rb +8 -0
  94. data/features/step_definitions/index_scope_steps.rb +4 -0
  95. data/features/step_definitions/sidebar_steps.rb +1 -3
  96. data/features/step_definitions/table_steps.rb +1 -5
  97. data/features/step_definitions/user_steps.rb +7 -0
  98. data/features/support/env.rb +6 -33
  99. data/features/support/paths.rb +5 -0
  100. data/features/users/logging_in.feature +2 -0
  101. data/gemfiles/rails_32.gemfile +54 -0
  102. data/gemfiles/rails_40.gemfile +53 -0
  103. data/gemfiles/rails_41.gemfile +53 -0
  104. data/gemfiles/rails_42.gemfile +53 -0
  105. data/gemfiles/rails_50.gemfile +46 -0
  106. data/lib/active_admin.rb +1 -0
  107. data/lib/active_admin/application.rb +11 -0
  108. data/lib/active_admin/batch_actions/resource_extension.rb +0 -8
  109. data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -1
  110. data/lib/active_admin/batch_actions/views/batch_action_selector.rb +1 -1
  111. data/lib/active_admin/dsl.rb +0 -6
  112. data/lib/active_admin/filters/active.rb +9 -1
  113. data/lib/active_admin/filters/formtastic_addons.rb +1 -1
  114. data/lib/active_admin/filters/humanized.rb +1 -1
  115. data/lib/active_admin/filters/resource_extension.rb +2 -4
  116. data/lib/active_admin/form_builder.rb +12 -6
  117. data/lib/active_admin/helpers/collection.rb +2 -0
  118. data/lib/active_admin/inputs.rb +1 -0
  119. data/lib/active_admin/inputs/filters/date_range_input.rb +9 -4
  120. data/lib/active_admin/inputs/filters/text_input.rb +26 -0
  121. data/lib/active_admin/localizers.rb +11 -0
  122. data/lib/active_admin/localizers/resource_localizer.rb +35 -0
  123. data/lib/active_admin/namespace.rb +1 -1
  124. data/lib/active_admin/order_clause.rb +29 -7
  125. data/lib/active_admin/page.rb +18 -4
  126. data/lib/active_admin/page_dsl.rb +4 -0
  127. data/lib/active_admin/resource.rb +16 -1
  128. data/lib/active_admin/resource/action_items.rb +7 -4
  129. data/lib/active_admin/resource/belongs_to.rb +4 -0
  130. data/lib/active_admin/resource/menu.rb +1 -1
  131. data/lib/active_admin/resource/ordering.rb +11 -0
  132. data/lib/active_admin/resource/routes.rb +34 -13
  133. data/lib/active_admin/resource/scopes.rb +1 -0
  134. data/lib/active_admin/resource_controller/data_access.rb +3 -10
  135. data/lib/active_admin/resource_dsl.rb +28 -1
  136. data/lib/active_admin/router.rb +5 -3
  137. data/lib/active_admin/scope.rb +3 -3
  138. data/lib/active_admin/version.rb +1 -1
  139. data/lib/active_admin/view_helpers/auto_link_helper.rb +2 -2
  140. data/lib/active_admin/view_helpers/display_helper.rb +8 -3
  141. data/lib/active_admin/view_helpers/method_or_proc_helper.rb +5 -1
  142. data/lib/active_admin/views/components/active_admin_form.rb +11 -10
  143. data/lib/active_admin/views/components/attributes_table.rb +1 -1
  144. data/lib/active_admin/views/components/columns.rb +3 -3
  145. data/lib/active_admin/views/components/dropdown_menu.rb +2 -2
  146. data/lib/active_admin/views/components/index_list.rb +4 -1
  147. data/lib/active_admin/views/components/paginated_collection.rb +1 -0
  148. data/lib/active_admin/views/components/scopes.rb +8 -1
  149. data/lib/active_admin/views/components/site_title.rb +2 -2
  150. data/lib/active_admin/views/components/table_for.rb +3 -3
  151. data/lib/active_admin/views/footer.rb +17 -3
  152. data/lib/active_admin/views/index_as_table.rb +3 -3
  153. data/lib/active_admin/views/pages/base.rb +4 -2
  154. data/lib/active_admin/views/pages/form.rb +2 -3
  155. data/lib/active_admin/views/pages/show.rb +2 -1
  156. data/lib/bug_report_templates/rails_5_master.rb +120 -0
  157. data/lib/generators/active_admin/devise/devise_generator.rb +6 -3
  158. data/lib/generators/active_admin/install/install_generator.rb +1 -1
  159. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +15 -1
  160. data/lib/generators/active_admin/install/templates/migrations/{create_active_admin_comments.rb → create_active_admin_comments.rb.erb} +14 -1
  161. data/lib/ransack_ext.rb +2 -2
  162. data/spec/bug_report_templates_spec.rb +27 -0
  163. data/spec/javascripts/support/jasmine_runner.rb +4 -17
  164. data/spec/rails_helper.rb +20 -109
  165. data/spec/requests/default_namespace_spec.rb +16 -28
  166. data/spec/requests/javascript_spec.rb +1 -1
  167. data/spec/requests/memory_spec.rb +5 -1
  168. data/spec/requests/stylesheets_spec.rb +1 -1
  169. data/spec/spec_helper.rb +5 -10
  170. data/spec/support/active_admin_integration_spec_helper.rb +66 -0
  171. data/spec/support/active_admin_request_helpers.rb +12 -0
  172. data/spec/support/rails_template.rb +42 -15
  173. data/spec/support/rails_template_with_data.rb +24 -5
  174. data/spec/support/templates/manifest.js +3 -0
  175. data/spec/support/templates/policies/application_policy.rb +1 -1
  176. data/spec/unit/abstract_view_factory_spec.rb +1 -1
  177. data/spec/unit/action_builder_spec.rb +3 -12
  178. data/spec/unit/active_admin_spec.rb +1 -1
  179. data/spec/unit/application_spec.rb +5 -1
  180. data/spec/unit/asset_registration_spec.rb +1 -1
  181. data/spec/unit/authorization/authorization_adapter_spec.rb +1 -1
  182. data/spec/unit/authorization/controller_authorization_spec.rb +13 -9
  183. data/spec/unit/authorization/index_overriding_spec.rb +6 -6
  184. data/spec/unit/auto_link_spec.rb +48 -24
  185. data/spec/unit/batch_actions/resource_spec.rb +1 -14
  186. data/spec/unit/batch_actions/settings_spec.rb +1 -1
  187. data/spec/unit/belongs_to_spec.rb +9 -1
  188. data/spec/unit/cancan_adapter_spec.rb +1 -1
  189. data/spec/unit/comments_spec.rb +26 -19
  190. data/spec/unit/component_spec.rb +1 -1
  191. data/spec/unit/config_shared_examples.rb +1 -1
  192. data/spec/unit/controller_filters_spec.rb +1 -1
  193. data/spec/unit/csv_builder_spec.rb +5 -5
  194. data/spec/unit/dependency_spec.rb +1 -1
  195. data/spec/unit/devise_spec.rb +17 -3
  196. data/spec/unit/dsl_spec.rb +2 -2
  197. data/spec/unit/filters/active_spec.rb +21 -0
  198. data/spec/unit/filters/filter_form_builder_spec.rb +98 -31
  199. data/spec/unit/filters/humanized_spec.rb +9 -1
  200. data/spec/unit/filters/resource_spec.rb +5 -4
  201. data/spec/unit/form_builder_spec.rb +180 -33
  202. data/spec/unit/generators/install_spec.rb +12 -5
  203. data/spec/unit/helpers/collection_spec.rb +10 -7
  204. data/spec/unit/helpers/scope_chain_spec.rb +1 -1
  205. data/spec/unit/helpers/settings_spec.rb +1 -1
  206. data/spec/unit/i18n_spec.rb +1 -1
  207. data/spec/unit/localizers/resource_localizer_spec.rb +36 -0
  208. data/spec/unit/menu_collection_spec.rb +1 -1
  209. data/spec/unit/menu_item_spec.rb +1 -1
  210. data/spec/unit/menu_spec.rb +1 -1
  211. data/spec/unit/namespace/authorization_spec.rb +1 -1
  212. data/spec/unit/namespace/register_page_spec.rb +28 -2
  213. data/spec/unit/namespace/register_resource_spec.rb +3 -1
  214. data/spec/unit/namespace_spec.rb +23 -1
  215. data/spec/unit/order_clause_spec.rb +7 -7
  216. data/spec/unit/page_controller_spec.rb +1 -1
  217. data/spec/unit/page_spec.rb +55 -2
  218. data/spec/unit/pretty_format_spec.rb +8 -7
  219. data/spec/unit/pundit_adapter_spec.rb +1 -1
  220. data/spec/unit/resource/action_items_spec.rb +1 -1
  221. data/spec/unit/resource/includes_spec.rb +1 -1
  222. data/spec/unit/resource/menu_spec.rb +1 -1
  223. data/spec/unit/resource/naming_spec.rb +1 -1
  224. data/spec/unit/resource/ordering_spec.rb +38 -0
  225. data/spec/unit/resource/page_presenters_spec.rb +1 -1
  226. data/spec/unit/resource/pagination_spec.rb +1 -1
  227. data/spec/unit/resource/routes_spec.rb +101 -53
  228. data/spec/unit/resource/scopes_spec.rb +1 -1
  229. data/spec/unit/resource/sidebars_spec.rb +1 -1
  230. data/spec/unit/resource_collection_spec.rb +1 -1
  231. data/spec/unit/resource_controller/data_access_spec.rb +50 -1
  232. data/spec/unit/resource_controller/decorators_spec.rb +2 -2
  233. data/spec/unit/resource_controller/sidebars_spec.rb +16 -17
  234. data/spec/unit/resource_controller_spec.rb +50 -56
  235. data/spec/unit/resource_registration_spec.rb +9 -4
  236. data/spec/unit/resource_spec.rb +9 -1
  237. data/spec/unit/routing_spec.rb +30 -2
  238. data/spec/unit/scope_spec.rb +26 -2
  239. data/spec/unit/settings_spec.rb +2 -2
  240. data/spec/unit/view_factory_spec.rb +1 -1
  241. data/spec/unit/view_helpers/breadcrumbs_spec.rb +1 -1
  242. data/spec/unit/view_helpers/display_helper_spec.rb +18 -3
  243. data/spec/unit/view_helpers/download_format_links_helper_spec.rb +1 -1
  244. data/spec/unit/view_helpers/fields_for_spec.rb +1 -1
  245. data/spec/unit/view_helpers/flash_helper_spec.rb +1 -1
  246. data/spec/unit/view_helpers/form_helper_spec.rb +1 -1
  247. data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +1 -1
  248. data/spec/unit/views/components/attributes_table_spec.rb +1 -1
  249. data/spec/unit/views/components/batch_action_selector_spec.rb +1 -1
  250. data/spec/unit/views/components/blank_slate_spec.rb +1 -1
  251. data/spec/unit/views/components/columns_spec.rb +1 -1
  252. data/spec/unit/views/components/index_list_spec.rb +18 -4
  253. data/spec/unit/views/components/index_table_for_spec.rb +1 -1
  254. data/spec/unit/views/components/paginated_collection_spec.rb +1 -1
  255. data/spec/unit/views/components/panel_spec.rb +1 -1
  256. data/spec/unit/views/components/sidebar_section_spec.rb +1 -1
  257. data/spec/unit/views/components/site_title_spec.rb +1 -1
  258. data/spec/unit/views/components/status_tag_spec.rb +1 -1
  259. data/spec/unit/views/components/table_for_spec.rb +9 -7
  260. data/spec/unit/views/components/tabs_spec.rb +1 -1
  261. data/spec/unit/views/components/unsupported_browser_spec.rb +3 -3
  262. data/spec/unit/views/index_as_blog_spec.rb +1 -1
  263. data/spec/unit/views/pages/form_spec.rb +1 -1
  264. data/spec/unit/views/pages/index_spec.rb +1 -1
  265. data/spec/unit/views/pages/layout_spec.rb +1 -1
  266. data/spec/unit/views/pages/show_spec.rb +1 -1
  267. data/spec/unit/views/tabbed_navigation_spec.rb +2 -2
  268. data/tasks/local.rake +25 -0
  269. data/tasks/parallel_tests.rake +4 -4
  270. data/tasks/test.rake +8 -53
  271. metadata +61 -18
  272. data/Guardfile +0 -8
  273. data/script/local +0 -53
  274. data/script/travis_cache +0 -107
  275. data/script/use_rails +0 -53
  276. data/spec/javascripts/support/jasmine_config.rb +0 -23
  277. data/spec/support/detect_rails_version.rb +0 -34
@@ -64,7 +64,8 @@ module ActiveAdmin
64
64
  def add_default_new_action_item
65
65
  add_action_item :new, only: :index do
66
66
  if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
67
- link_to I18n.t('active_admin.new_model', model: active_admin_config.resource_label), new_resource_path
67
+ localizer = ActiveAdmin::Localizers.resource(active_admin_config)
68
+ link_to localizer.t(:new_model), new_resource_path
68
69
  end
69
70
  end
70
71
  end
@@ -73,7 +74,8 @@ module ActiveAdmin
73
74
  def add_default_edit_action_item
74
75
  add_action_item :edit, only: :show do
75
76
  if controller.action_methods.include?('edit') && authorized?(ActiveAdmin::Auth::UPDATE, resource)
76
- link_to I18n.t('active_admin.edit_model', model: active_admin_config.resource_label), edit_resource_path(resource)
77
+ localizer = ActiveAdmin::Localizers.resource(active_admin_config)
78
+ link_to localizer.t(:edit_model), edit_resource_path(resource)
77
79
  end
78
80
  end
79
81
  end
@@ -82,8 +84,9 @@ module ActiveAdmin
82
84
  def add_default_show_action_item
83
85
  add_action_item :destroy, only: :show do
84
86
  if controller.action_methods.include?('destroy') && authorized?(ActiveAdmin::Auth::DESTROY, resource)
85
- link_to I18n.t('active_admin.delete_model', model: active_admin_config.resource_label), resource_path(resource),
86
- method: :delete, data: {confirm: I18n.t('active_admin.delete_confirmation')}
87
+ localizer = ActiveAdmin::Localizers.resource(active_admin_config)
88
+ link_to localizer.t(:delete_model), resource_path(resource), method: :delete,
89
+ data: {confirm: localizer.t(:delete_confirmation)}
87
90
  end
88
91
  end
89
92
  end
@@ -39,6 +39,10 @@ module ActiveAdmin
39
39
  def required?
40
40
  !optional?
41
41
  end
42
+
43
+ def to_param
44
+ :"#{@target_name}_id"
45
+ end
42
46
  end
43
47
  end
44
48
  end
@@ -26,7 +26,7 @@ module ActiveAdmin
26
26
  {
27
27
  id: resource_name.plural,
28
28
  label: proc{ resource.plural_resource_label },
29
- url: proc{ resource.route_collection_path(params) },
29
+ url: proc{ resource.route_collection_path(params, url_options) },
30
30
  if: proc{ authorized?(Auth::READ, menu_resource_class) }
31
31
  }
32
32
  end
@@ -0,0 +1,11 @@
1
+ module ActiveAdmin
2
+ class Resource
3
+ module Ordering
4
+
5
+ def ordering
6
+ @ordering ||= {}.with_indifferent_access
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -4,19 +4,23 @@ module ActiveAdmin
4
4
  # @param params [Hash] of params: { study_id: 3 }
5
5
  # @return [String] the path to this resource collection page
6
6
  # @example "/admin/posts"
7
- def route_collection_path(params = {})
8
- RouteBuilder.new(self).collection_path(params)
7
+ def route_collection_path(params = {}, additional_params = {})
8
+ route_builder.collection_path(params, additional_params)
9
+ end
10
+
11
+ def route_batch_action_path(params = {}, additional_params = {})
12
+ route_builder.batch_action_path(params, additional_params)
9
13
  end
10
14
 
11
15
  # @param resource [ActiveRecord::Base] the instance we want the path of
12
16
  # @return [String] the path to this resource collection page
13
17
  # @example "/admin/posts/1"
14
- def route_instance_path(resource)
15
- RouteBuilder.new(self).instance_path(resource)
18
+ def route_instance_path(resource, additional_params = {})
19
+ route_builder.instance_path(resource, additional_params)
16
20
  end
17
21
 
18
- def route_edit_instance_path(resource)
19
- RouteBuilder.new(self).edit_instance_path(resource)
22
+ def route_edit_instance_path(resource, additional_params = {})
23
+ route_builder.edit_instance_path(resource, additional_params)
20
24
  end
21
25
 
22
26
  # Returns the routes prefix for this config
@@ -24,6 +28,10 @@ module ActiveAdmin
24
28
  namespace.module_name.try(:underscore)
25
29
  end
26
30
 
31
+ def route_builder
32
+ @route_builder ||= RouteBuilder.new(self)
33
+ end
34
+
27
35
  def route_uncountable?
28
36
  config = resources_configuration[:self]
29
37
 
@@ -37,32 +45,45 @@ module ActiveAdmin
37
45
  @resource = resource
38
46
  end
39
47
 
40
- def collection_path(params)
48
+ def collection_path(params, additional_params = {})
49
+ route_name = route_name(
50
+ resource.resources_configuration[:self][:route_collection_name],
51
+ suffix: (resource.route_uncountable? ? "index_path" : "path")
52
+ )
53
+
54
+ routes.public_send route_name, *route_collection_params(params), additional_params
55
+ end
56
+
57
+ def batch_action_path(params, additional_params = {})
41
58
  route_name = route_name(
42
59
  resource.resources_configuration[:self][:route_collection_name],
60
+ action: :batch_action,
43
61
  suffix: (resource.route_uncountable? ? "index_path" : "path")
44
62
  )
45
63
 
46
- routes.public_send route_name, *route_collection_params(params)
64
+ query = params.slice(:q, :scope)
65
+ query = query.permit! if query.respond_to? :permit!
66
+ query = query.to_h if Rails::VERSION::MAJOR >= 5
67
+ routes.public_send route_name, *route_collection_params(params), additional_params.merge(query)
47
68
  end
48
69
 
49
70
  # @return [String] the path to this resource collection page
50
71
  # @param instance [ActiveRecord::Base] the instance we want the path of
51
72
  # @example "/admin/posts/1"
52
- def instance_path(instance)
73
+ def instance_path(instance, additional_params = {})
53
74
  route_name = route_name(resource.resources_configuration[:self][:route_instance_name])
54
75
 
55
- routes.public_send route_name, *route_instance_params(instance)
76
+ routes.public_send route_name, *route_instance_params(instance), additional_params
56
77
  end
57
78
 
58
79
  # @return [String] the path to the edit page of this resource
59
80
  # @param instance [ActiveRecord::Base] the instance we want the path of
60
81
  # @example "/admin/posts/1/edit"
61
- def edit_instance_path(instance)
82
+ def edit_instance_path(instance, additional_params = {})
62
83
  path = resource.resources_configuration[:self][:route_instance_name]
63
84
  route_name = route_name(path, action: :edit)
64
85
 
65
- routes.public_send route_name, *route_instance_params(instance)
86
+ routes.public_send route_name, *route_instance_params(instance), additional_params
66
87
  end
67
88
 
68
89
  private
@@ -73,7 +94,7 @@ module ActiveAdmin
73
94
  suffix = options[:suffix] || "path"
74
95
  route = []
75
96
 
76
- route << options[:action] # "edit" or "new"
97
+ route << options[:action] # "batch_action", "edit" or "new"
77
98
  route << resource.route_prefix # "admin"
78
99
  route << belongs_to_name if nested? # "category"
79
100
  route << resource_path_name # "posts" or "post"
@@ -31,6 +31,7 @@ module ActiveAdmin
31
31
  title = args[0] rescue nil
32
32
  method = args[1] rescue nil
33
33
 
34
+ options[:localizer] ||= ActiveAdmin::Localizers.resource(self)
34
35
  scope = ActiveAdmin::Scope.new(title, method, options, &block)
35
36
 
36
37
  # Finds and replaces a scope by the same name if it already exists
@@ -209,11 +209,10 @@ module ActiveAdmin
209
209
 
210
210
  def apply_sorting(chain)
211
211
  params[:order] ||= active_admin_config.sort_order
212
-
213
- order_clause = OrderClause.new params[:order]
212
+ order_clause = active_admin_config.order_clause.new(active_admin_config, params[:order])
214
213
 
215
214
  if order_clause.valid?
216
- chain.reorder(order_clause.to_sql(active_admin_config))
215
+ order_clause.apply(chain)
217
216
  else
218
217
  chain # just return the chain
219
218
  end
@@ -222,16 +221,10 @@ module ActiveAdmin
222
221
  # Applies any Ransack search methods to the currently scoped collection.
223
222
  # Both `search` and `ransack` are provided, but we use `ransack` to prevent conflicts.
224
223
  def apply_filtering(chain)
225
- @search = chain.ransack clean_search_params
224
+ @search = chain.ransack(params[:q] || {})
226
225
  @search.result
227
226
  end
228
227
 
229
- def clean_search_params
230
- q = params[:q] || {}
231
- q = q.to_unsafe_h if q.respond_to? :to_unsafe_h
232
- q.delete_if{ |key, value| value.blank? }
233
- end
234
-
235
228
  def apply_scoping(chain)
236
229
  @collection_before_scope = chain
237
230
 
@@ -8,6 +8,25 @@ module ActiveAdmin
8
8
 
9
9
  private
10
10
 
11
+ # Redefine sort behaviour for column
12
+ #
13
+ # For example:
14
+ #
15
+ # # nulls last
16
+ # order_by(:age) do |order_clause|
17
+ # [order_clause.to_sql, 'NULLS LAST'].join(' ') if order_clause.order == 'desc'
18
+ # end
19
+ #
20
+ # # by last_name but in the case that there is no last name, by first_name.
21
+ # order_by(:full_name) do |order_clause|
22
+ # ['COALESCE(NULLIF(last_name, ''), first_name), first_name', order_clause.order].join(' ')
23
+ # end
24
+ #
25
+ #
26
+ def order_by(column, &block)
27
+ config.ordering[column] = block
28
+ end
29
+
11
30
  def belongs_to(target, options = {})
12
31
  config.belongs_to(target, options)
13
32
  end
@@ -49,10 +68,11 @@ module ActiveAdmin
49
68
  #
50
69
  def permit_params(*args, &block)
51
70
  param_key = config.param_key.to_sym
71
+ belongs_to_param = config.belongs_to_param
52
72
 
53
73
  controller do
54
74
  define_method :permitted_params do
55
- params.permit *active_admin_namespace.permitted_params,
75
+ params.permit *(active_admin_namespace.permitted_params + Array.wrap(belongs_to_param)),
56
76
  param_key => block ? instance_exec(&block) : args
57
77
  end
58
78
  end
@@ -130,6 +150,13 @@ module ActiveAdmin
130
150
  action config.collection_actions, name, options, &block
131
151
  end
132
152
 
153
+ def decorate_with(decorator_class)
154
+ # Force storage as a string. This will help us with reloading issues.
155
+ # Assuming decorator_class.to_s will return the name of the class allows
156
+ # us to handle a string or a class.
157
+ config.decorator_class_name = "::#{ decorator_class }"
158
+ end
159
+
133
160
  # Defined Callbacks
134
161
  #
135
162
  # == After Build
@@ -23,7 +23,7 @@ module ActiveAdmin
23
23
  if namespace.root?
24
24
  root namespace.root_to_options.merge(to: namespace.root_to)
25
25
  else
26
- namespace namespace.name do
26
+ namespace namespace.name, namespace.route_options.dup do
27
27
  root namespace.root_to_options.merge(to: namespace.root_to, as: :root)
28
28
  end
29
29
  end
@@ -57,7 +57,7 @@ module ActiveAdmin
57
57
  unless config.namespace.root?
58
58
  nested = routes
59
59
  routes = Proc.new do
60
- namespace config.namespace.name do
60
+ namespace config.namespace.name, config.namespace.route_options.dup do
61
61
  instance_exec &nested
62
62
  end
63
63
  end
@@ -94,7 +94,9 @@ module ActiveAdmin
94
94
  page = config.underscored_resource_name
95
95
  get "/#{page}" => "#{page}#index"
96
96
  config.page_actions.each do |action|
97
- build_route.call action.http_verb, "/#{page}/#{action.name}" => "#{page}##{action.name}"
97
+ Array.wrap(action.http_verb).each do |verb|
98
+ build_route.call verb, "/#{page}/#{action.name}" => "#{page}##{action.name}"
99
+ end
98
100
  end
99
101
  else
100
102
  raise "Unsupported config class: #{config.class}"
@@ -38,6 +38,7 @@ module ActiveAdmin
38
38
  @scope_method = nil if @scope_method == :all
39
39
  @scope_method, @scope_block = nil, block if block_given?
40
40
 
41
+ @localizer = options[:localizer]
41
42
  @show_count = options.fetch(:show_count, true)
42
43
  @display_if_block = options[:if] || proc{ true }
43
44
  @default_block = options[:default] || proc{ false }
@@ -45,10 +46,9 @@ module ActiveAdmin
45
46
 
46
47
  def name
47
48
  case @name
48
- when Proc then @name.call.to_s
49
49
  when String then @name
50
- when Symbol then @name.to_s.titleize
51
- else @name.to_s
50
+ when Symbol then @localizer ? @localizer.t(@name, scope: 'scopes') : @name.to_s.titleize
51
+ else @name
52
52
  end
53
53
  end
54
54
 
@@ -1,3 +1,3 @@
1
1
  module ActiveAdmin
2
- VERSION = '1.0.0.pre4'
2
+ VERSION = '1.0.0.pre5'
3
3
  end
@@ -26,10 +26,10 @@ module ActiveAdmin
26
26
 
27
27
  if config.controller.action_methods.include?("show") &&
28
28
  authorized?(ActiveAdmin::Auth::READ, resource)
29
- url_for config.route_instance_path resource
29
+ url_for config.route_instance_path resource, url_options
30
30
  elsif config.controller.action_methods.include?("edit") &&
31
31
  authorized?(ActiveAdmin::Auth::UPDATE, resource)
32
- url_for config.route_edit_instance_path resource
32
+ url_for config.route_edit_instance_path resource, url_options
33
33
  end
34
34
  end
35
35
 
@@ -42,9 +42,14 @@ module ActiveAdmin
42
42
 
43
43
  def format_attribute(resource, attr)
44
44
  value = find_value resource, attr
45
- value = pretty_format value if attr.is_a? Symbol
46
- value = Arbre::Context.new{ status_tag value } if boolean_attr? resource, attr
47
- value
45
+
46
+ if value.is_a?(Arbre::Element)
47
+ value
48
+ elsif boolean_attr?(resource, attr)
49
+ Arbre::Context.new { status_tag value }
50
+ else
51
+ pretty_format value
52
+ end
48
53
  end
49
54
 
50
55
  def find_value(resource, attr)
@@ -18,6 +18,8 @@ module MethodOrProcHelper
18
18
  send(symbol_or_proc, *args)
19
19
  when Proc
20
20
  instance_exec(*args, &symbol_or_proc)
21
+ else
22
+ symbol_or_proc
21
23
  end
22
24
  end
23
25
 
@@ -60,6 +62,8 @@ module MethodOrProcHelper
60
62
  else
61
63
  symbol_or_proc.call(receiver, *args)
62
64
  end
65
+ else
66
+ symbol_or_proc
63
67
  end
64
68
  end
65
69
 
@@ -71,7 +75,7 @@ module MethodOrProcHelper
71
75
  case string_symbol_or_proc
72
76
  when Symbol, Proc
73
77
  call_method_or_proc_on(obj, string_symbol_or_proc, options)
74
- when String
78
+ else
75
79
  string_symbol_or_proc
76
80
  end
77
81
  end
@@ -19,7 +19,7 @@ module ActiveAdmin
19
19
  opening_tag << children.to_s << closing_tag
20
20
  end
21
21
  end
22
-
22
+
23
23
  class ActiveAdminForm < FormtasticProxy
24
24
  builder_method :active_admin_form_for
25
25
 
@@ -27,7 +27,7 @@ module ActiveAdmin
27
27
  @resource = resource
28
28
  options = options.deep_dup
29
29
  options[:builder] ||= ActiveAdmin::FormBuilder
30
- form_string = semantic_form_for(resource, options) do |f|
30
+ form_string = helpers.semantic_form_for(resource, options) do |f|
31
31
  @form_builder = f
32
32
  end
33
33
 
@@ -43,7 +43,7 @@ module ActiveAdmin
43
43
 
44
44
  def inputs(*args, &block)
45
45
  if block_given?
46
- form_builder.template.assign(has_many_block: true)
46
+ form_builder.template.assigns[:has_many_block] = true
47
47
  end
48
48
  if block_given? && block.arity == 0
49
49
  wrapped_block = proc do
@@ -95,14 +95,15 @@ module ActiveAdmin
95
95
 
96
96
  class SemanticInputsProxy < FormtasticProxy
97
97
  def build(form_builder, *args, &block)
98
- options = args.extract_options!
99
- legend = args.shift
98
+ html_options = args.extract_options!
99
+ html_options[:class] ||= "inputs"
100
+ legend = args.shift if args.first.is_a?(::String)
101
+ legend = html_options.delete(:name) if html_options.key?(:name)
100
102
  legend_tag = legend ? "<legend><span>#{legend}</span></legend>" : ""
101
- klasses = ["inputs"]
102
- klasses << options[:class] if options[:class]
103
- @opening_tag = "<fieldset class=\"#{klasses.join(" ")}\">#{legend_tag}<ol>"
103
+ fieldset_attrs = html_options.map {|k,v| %Q{#{k}="#{v}"} }.join(" ")
104
+ @opening_tag = "<fieldset #{fieldset_attrs}>#{legend_tag}<ol>"
104
105
  @closing_tag = "</ol></fieldset>"
105
- super(*(args << options), &block)
106
+ super(*(args << html_options), &block)
106
107
  end
107
108
  end
108
109
 
@@ -120,4 +121,4 @@ module ActiveAdmin
120
121
  end
121
122
  end
122
123
  end
123
- end
124
+ end
@@ -79,7 +79,7 @@ module ActiveAdmin
79
79
  end
80
80
 
81
81
  def content_for(record, attr)
82
- value = format_attribute record, attr
82
+ value = helpers.format_attribute record, attr
83
83
  value.blank? && current_arbre_element.children.to_s.empty? ? empty_value : value
84
84
  # Don't add the same Arbre twice, while still allowing format_attribute to call status_tag
85
85
  current_arbre_element << value unless current_arbre_element.children.include? value
@@ -14,7 +14,7 @@ module ActiveAdmin
14
14
  #
15
15
  # To create a two column layout:
16
16
  #
17
- # colums do
17
+ # columns do
18
18
  # column do
19
19
  # span "Column # 1
20
20
  # end
@@ -28,7 +28,7 @@ module ActiveAdmin
28
28
  #
29
29
  # To make a column span multiple, pass the :span option to the column method:
30
30
  #
31
- # colums do
31
+ # columns do
32
32
  # column span: 2 do
33
33
  # span "Column # 1
34
34
  # end
@@ -49,7 +49,7 @@ module ActiveAdmin
49
49
  #
50
50
  # To overcome this, columns include a :max_width and :min_width option.
51
51
  #
52
- # colums do
52
+ # columns do
53
53
  # column max_width: "200px", min_width: "100px" do
54
54
  # span "Column # 1
55
55
  # end