activeadmin 0.3.4 → 0.4.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.

Files changed (244) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +164 -5
  4. data/CONTRIBUTING.md +113 -0
  5. data/Gemfile +7 -9
  6. data/LICENSE +1 -1
  7. data/README.rdoc +19 -20
  8. data/activeadmin.gemspec +4 -2
  9. data/app/assets/javascripts/active_admin/application.js +9 -0
  10. data/app/assets/javascripts/active_admin/base.js +4 -12
  11. data/app/assets/stylesheets/active_admin/_base.css.scss +17 -341
  12. data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -7
  13. data/app/assets/stylesheets/active_admin/_header.css.scss +23 -4
  14. data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
  15. data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
  16. data/app/assets/stylesheets/active_admin/components/_buttons.scss +12 -0
  17. data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +2 -0
  18. data/app/assets/stylesheets/active_admin/components/_grid.scss +9 -0
  19. data/app/assets/stylesheets/active_admin/components/_links.scss +5 -0
  20. data/app/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
  21. data/app/assets/stylesheets/active_admin/components/_panels.scss +6 -0
  22. data/app/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
  23. data/app/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
  24. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +101 -0
  25. data/app/assets/stylesheets/active_admin/components/_tables.css.scss +43 -2
  26. data/app/assets/stylesheets/active_admin/mixins/_all.css.scss +2 -1
  27. data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +50 -13
  28. data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +9 -1
  29. data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +7 -5
  30. data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +1 -0
  31. data/app/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
  32. data/app/assets/stylesheets/active_admin/mixins/_utilities.scss +9 -0
  33. data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +1 -0
  34. data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
  35. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
  36. data/app/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
  37. data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
  38. data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
  39. data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
  40. data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
  41. data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
  42. data/app/views/active_admin/devise/shared/_links.erb +1 -1
  43. data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
  44. data/app/views/active_admin/page/index.html.arb +1 -0
  45. data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
  46. data/cucumber.yml +3 -2
  47. data/docs/1-general-configuration.md +46 -10
  48. data/docs/6-show-screens.md +7 -0
  49. data/docs/8-custom-actions.md +12 -2
  50. data/docs/9-custom-pages.md +84 -0
  51. data/features/belongs_to.feature +27 -0
  52. data/features/comments/commenting.feature +3 -2
  53. data/features/dashboard.feature +18 -0
  54. data/features/development_reloading.feature +43 -0
  55. data/features/index/filter_with_check_boxes.feature +25 -0
  56. data/features/index/index_as_table.feature +14 -0
  57. data/features/index/index_scopes.feature +59 -0
  58. data/features/index/pagination.feature +19 -1
  59. data/features/menu.feature +22 -2
  60. data/features/registering_assets.feature +2 -2
  61. data/features/registering_pages.feature +66 -0
  62. data/features/specifying_actions.feature +5 -0
  63. data/features/step_definitions/action_item_steps.rb +2 -6
  64. data/features/step_definitions/action_link_steps.rb +7 -0
  65. data/features/step_definitions/additional_web_steps.rb +11 -3
  66. data/features/step_definitions/asset_steps.rb +5 -1
  67. data/features/step_definitions/breadcrumb_steps.rb +5 -0
  68. data/features/step_definitions/comment_steps.rb +3 -3
  69. data/features/step_definitions/configuration_steps.rb +69 -13
  70. data/features/step_definitions/dashboard_steps.rb +7 -3
  71. data/features/step_definitions/factory_steps.rb +9 -2
  72. data/features/step_definitions/flash_steps.rb +9 -1
  73. data/features/step_definitions/format_steps.rb +9 -1
  74. data/features/step_definitions/index_scope_steps.rb +18 -6
  75. data/features/step_definitions/member_link_steps.rb +7 -0
  76. data/features/step_definitions/pagination_steps.rb +2 -2
  77. data/features/step_definitions/site_title_steps.rb +15 -0
  78. data/features/step_definitions/tab_steps.rb +1 -1
  79. data/features/step_definitions/user_steps.rb +1 -1
  80. data/features/step_definitions/web_steps.rb +4 -4
  81. data/features/support/paths.rb +6 -0
  82. data/features/users/logging_out.feature +11 -0
  83. data/lib/active_admin.rb +26 -10
  84. data/lib/active_admin/application.rb +64 -22
  85. data/lib/active_admin/arbre.rb +0 -1
  86. data/lib/active_admin/arbre/builder.rb +8 -5
  87. data/lib/active_admin/arbre/context.rb +1 -1
  88. data/lib/active_admin/arbre/html/attributes.rb +1 -1
  89. data/lib/active_admin/arbre/html/class_list.rb +0 -4
  90. data/lib/active_admin/arbre/html/collection.rb +2 -2
  91. data/lib/active_admin/arbre/html/document.rb +1 -1
  92. data/lib/active_admin/arbre/html/element.rb +19 -9
  93. data/lib/active_admin/arbre/html/tag.rb +3 -3
  94. data/lib/active_admin/arbre/html/text_node.rb +2 -2
  95. data/lib/active_admin/asset_registration.rb +15 -2
  96. data/lib/active_admin/base_controller.rb +61 -0
  97. data/lib/active_admin/{resource_controller → base_controller}/menu.rb +1 -1
  98. data/lib/active_admin/callbacks.rb +16 -18
  99. data/lib/active_admin/comments.rb +48 -54
  100. data/lib/active_admin/comments/comment.rb +13 -2
  101. data/lib/active_admin/comments/namespace_helper.rb +1 -1
  102. data/lib/active_admin/comments/views/active_admin_comments.rb +7 -3
  103. data/lib/active_admin/dashboards.rb +4 -0
  104. data/lib/active_admin/dashboards/dashboard_controller.rb +21 -5
  105. data/lib/active_admin/dsl.rb +6 -159
  106. data/lib/active_admin/event.rb +5 -3
  107. data/lib/active_admin/filter_form_builder.rb +53 -0
  108. data/lib/active_admin/form_builder.rb +25 -19
  109. data/lib/active_admin/helpers/settings.rb +6 -10
  110. data/lib/active_admin/inputs.rb +14 -0
  111. data/lib/active_admin/inputs/datepicker_input.rb +11 -0
  112. data/lib/active_admin/inputs/filter_base.rb +46 -0
  113. data/lib/active_admin/inputs/filter_check_boxes_input.rb +40 -0
  114. data/lib/active_admin/inputs/filter_date_range_input.rb +34 -0
  115. data/lib/active_admin/inputs/filter_numeric_input.rb +55 -0
  116. data/lib/active_admin/inputs/filter_select_input.rb +23 -0
  117. data/lib/active_admin/inputs/filter_string_input.rb +22 -0
  118. data/lib/active_admin/locales/ca.yml +44 -0
  119. data/lib/active_admin/locales/cs.yml +14 -10
  120. data/lib/active_admin/locales/de.yml +44 -0
  121. data/lib/active_admin/locales/en.yml +5 -0
  122. data/lib/active_admin/locales/hr.yml +40 -0
  123. data/lib/active_admin/locales/hu.yml +45 -0
  124. data/lib/active_admin/locales/it.yml +11 -6
  125. data/lib/active_admin/locales/ko.yml +40 -0
  126. data/lib/active_admin/locales/lv.yml +43 -0
  127. data/lib/active_admin/locales/nl.yml +40 -0
  128. data/lib/active_admin/locales/no-NB.yml +40 -0
  129. data/lib/active_admin/locales/pl.yml +7 -1
  130. data/lib/active_admin/locales/pt-BR.yml +6 -2
  131. data/lib/active_admin/menu_item.rb +25 -17
  132. data/lib/active_admin/namespace.rb +48 -33
  133. data/lib/active_admin/page.rb +65 -0
  134. data/lib/active_admin/page_controller.rb +15 -0
  135. data/lib/active_admin/page_dsl.rb +21 -0
  136. data/lib/active_admin/page_presenter.rb +30 -0
  137. data/lib/active_admin/reloader.rb +109 -42
  138. data/lib/active_admin/resource.rb +38 -44
  139. data/lib/active_admin/resource/action_items.rb +5 -0
  140. data/lib/active_admin/resource/belongs_to.rb +4 -2
  141. data/lib/active_admin/resource/controllers.rb +35 -0
  142. data/lib/active_admin/resource/menu.rb +1 -2
  143. data/lib/active_admin/resource/naming.rb +53 -31
  144. data/lib/active_admin/resource/page_presenters.rb +28 -0
  145. data/lib/active_admin/resource/scopes.rb +16 -3
  146. data/lib/active_admin/resource/sidebars.rb +4 -0
  147. data/lib/active_admin/resource_collection.rb +88 -0
  148. data/lib/active_admin/resource_controller.rb +18 -54
  149. data/lib/active_admin/resource_controller/action_builder.rb +1 -1
  150. data/lib/active_admin/resource_controller/actions.rb +8 -8
  151. data/lib/active_admin/resource_controller/callbacks.rb +1 -1
  152. data/lib/active_admin/resource_controller/collection.rb +8 -4
  153. data/lib/active_admin/resource_controller/filters.rb +1 -1
  154. data/lib/active_admin/resource_controller/resource_class_methods.rb +24 -0
  155. data/lib/active_admin/resource_controller/scoping.rb +1 -1
  156. data/lib/active_admin/resource_controller/sidebars.rb +1 -1
  157. data/lib/active_admin/resource_dsl.rb +157 -0
  158. data/lib/active_admin/router.rb +21 -14
  159. data/lib/active_admin/scope.rb +15 -3
  160. data/lib/active_admin/version.rb +1 -1
  161. data/lib/active_admin/view_factory.rb +4 -3
  162. data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -10
  163. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +25 -21
  164. data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -150
  165. data/lib/active_admin/views/components/attributes_table.rb +1 -1
  166. data/lib/active_admin/views/components/columns.rb +4 -4
  167. data/lib/active_admin/views/components/paginated_collection.rb +42 -13
  168. data/lib/active_admin/views/components/panel.rb +8 -0
  169. data/lib/active_admin/views/components/scopes.rb +24 -18
  170. data/lib/active_admin/views/components/status_tag.rb +6 -5
  171. data/lib/active_admin/views/components/table_for.rb +6 -2
  172. data/lib/active_admin/views/header_renderer.rb +31 -12
  173. data/lib/active_admin/views/index_as_block.rb +2 -2
  174. data/lib/active_admin/views/index_as_blog.rb +3 -3
  175. data/lib/active_admin/views/index_as_grid.rb +4 -4
  176. data/lib/active_admin/views/index_as_table.rb +13 -6
  177. data/lib/active_admin/views/pages/base.rb +4 -4
  178. data/lib/active_admin/views/pages/form.rb +49 -0
  179. data/lib/active_admin/views/pages/index.rb +18 -6
  180. data/lib/active_admin/views/pages/page.rb +24 -0
  181. data/lib/active_admin/views/pages/show.rb +1 -1
  182. data/lib/generators/active_admin/assets/assets_generator.rb +19 -1
  183. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +38 -12
  184. data/lib/generators/active_admin/install/templates/dashboards.rb +6 -0
  185. data/script/use_rails +14 -7
  186. data/spec/spec_helper.rb +9 -14
  187. data/spec/spec_helper_without_rails.rb +10 -0
  188. data/spec/support/detect_rails_version.rb +22 -3
  189. data/spec/support/integration_example_group.rb +5 -7
  190. data/spec/support/rails_template.rb +11 -0
  191. data/spec/support/rails_template_with_data.rb +25 -0
  192. data/spec/support/templates/cucumber_with_reloading.rb +5 -0
  193. data/spec/unit/active_admin_spec.rb +8 -0
  194. data/spec/unit/application_spec.rb +48 -2
  195. data/spec/unit/arbre/context_spec.rb +1 -1
  196. data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
  197. data/spec/unit/arbre/html/element_spec.rb +18 -5
  198. data/spec/unit/arbre/html/tag_attributes_spec.rb +3 -3
  199. data/spec/unit/arbre/html/tag_spec.rb +1 -1
  200. data/spec/unit/arbre/html_spec.rb +32 -22
  201. data/spec/unit/asset_registration_spec.rb +9 -3
  202. data/spec/unit/auto_link_spec.rb +2 -2
  203. data/spec/unit/base_controller_shared_examples.rb +28 -0
  204. data/spec/unit/base_controller_spec.rb +8 -0
  205. data/spec/unit/belongs_to_spec.rb +30 -33
  206. data/spec/unit/comments_spec.rb +45 -15
  207. data/spec/unit/config_shared_examples.rb +119 -0
  208. data/spec/unit/dashboard_controller_spec.rb +44 -0
  209. data/spec/unit/event_spec.rb +6 -0
  210. data/spec/unit/filter_form_builder_spec.rb +9 -0
  211. data/spec/unit/form_builder_spec.rb +8 -14
  212. data/spec/unit/menu_item_spec.rb +25 -20
  213. data/spec/unit/namespace/register_page_spec.rb +102 -0
  214. data/spec/unit/namespace/register_resource_spec.rb +188 -0
  215. data/spec/unit/namespace_spec.rb +11 -183
  216. data/spec/unit/page_controller_spec.rb +8 -0
  217. data/spec/unit/page_spec.rb +60 -0
  218. data/spec/unit/reloader_spec.rb +82 -38
  219. data/spec/unit/resource/menu_spec.rb +1 -51
  220. data/spec/unit/resource/naming_spec.rb +25 -20
  221. data/spec/unit/resource/page_presenters_spec.rb +32 -0
  222. data/spec/unit/resource/scopes_spec.rb +13 -0
  223. data/spec/unit/resource_collection_spec.rb +101 -0
  224. data/spec/unit/resource_controller_spec.rb +40 -32
  225. data/spec/unit/{registration_spec.rb → resource_registration_spec.rb} +0 -0
  226. data/spec/unit/resource_spec.rb +8 -24
  227. data/spec/unit/routing_spec.rb +50 -1
  228. data/spec/unit/scope_spec.rb +18 -4
  229. data/spec/unit/views/components/paginated_collection_spec.rb +163 -0
  230. data/spec/unit/views/components/panel_spec.rb +9 -0
  231. data/spec/unit/views/components/status_tag_spec.rb +9 -0
  232. data/spec/unit/views/tabbed_navigation_spec.rb +2 -1
  233. data/tasks/test.rake +44 -26
  234. metadata +176 -69
  235. data/app/assets/javascripts/active_admin/vendor.js +0 -382
  236. data/lib/active_admin/arbre/core_extensions.rb +0 -5
  237. data/lib/active_admin/comments/configuration.rb +0 -18
  238. data/lib/active_admin/page_config.rb +0 -15
  239. data/lib/active_admin/resource_controller/form.rb +0 -42
  240. data/lib/active_admin/resource_controller/page_configurations.rb +0 -53
  241. data/lib/active_admin/views/pages/edit.rb +0 -28
  242. data/lib/active_admin/views/pages/new.rb +0 -28
  243. data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +0 -427
  244. data/spec/integration/belongs_to_spec.rb +0 -42
@@ -2,27 +2,31 @@ module ActiveAdmin
2
2
  module ViewHelpers
3
3
  module BreadcrumbHelper
4
4
 
5
- # Returns an array of links to use in a breadcrumb
6
- def breadcrumb_links(path = nil)
7
- path ||= request.fullpath
8
- parts = path.gsub(/^\//, '').split('/')
9
- parts.pop unless %w{ create update }.include?(params[:action])
10
- crumbs = []
11
- parts.each_with_index do |part, index|
12
- name = ""
13
- if part =~ /^\d/ && parent = parts[index - 1]
14
- begin
15
- parent_class = parent.singularize.camelcase.constantize
16
- obj = parent_class.find(part.to_i)
17
- name = obj.display_name if obj.respond_to?(:display_name)
18
- rescue
19
- end
20
- end
21
- name = part.titlecase if name == ""
22
- crumbs << link_to(name, "/" + parts[0..index].join('/'))
23
- end
24
- crumbs
25
- end
5
+ # Returns an array of links to use in a breadcrumb
6
+ def breadcrumb_links(path = nil)
7
+ path ||= request.fullpath
8
+ parts = path.gsub(/^\//, '').split('/')
9
+ parts.pop unless %w{ create update }.include?(params[:action])
10
+ crumbs = []
11
+ parts.each_with_index do |part, index|
12
+ name = ""
13
+ if part =~ /^\d/ && parent = parts[index - 1]
14
+ begin
15
+ parent_class = parent.singularize.camelcase.constantize
16
+ obj = parent_class.find(part.to_i)
17
+ name = obj.display_name if obj.respond_to?(:display_name)
18
+ rescue
19
+ end
20
+ end
21
+ name = part.titlecase if name == ""
22
+ begin
23
+ crumbs << link_to( I18n.translate!("activerecord.models.#{part.singularize}", :count => 2), "/" + parts[0..index].join('/'))
24
+ rescue I18n::MissingTranslationData
25
+ crumbs << link_to( name, "/" + parts[0..index].join('/'))
26
+ end
27
+ end
28
+ crumbs
29
+ end
26
30
 
27
31
  end
28
32
  end
@@ -33,154 +33,4 @@ module ActiveAdmin
33
33
  end
34
34
  end
35
35
 
36
- # This form builder defines methods to build filter forms such
37
- # as the one found in the sidebar of the index page of a standard resource.
38
- class FilterFormBuilder < FormBuilder
39
-
40
- def filter(method, options = {})
41
- return "" if method.nil? || method == ""
42
- options[:as] ||= default_filter_type(method)
43
- return "" unless options[:as]
44
- field_type = options.delete(:as)
45
- options[:label] ||= default_filter_label(method)
46
- content = with_new_form_buffer do
47
- send("filter_#{field_type}_input", method, options)
48
- end
49
- @form_buffers.last << template.content_tag(:div, content, :class => "filter_form_field filter_#{field_type}")
50
- end
51
-
52
- protected
53
-
54
- def filter_string_input(method, options = {})
55
- field_name = "#{method}_contains"
56
-
57
- [ label(field_name, I18n.t('active_admin.search_field', :field => options[:label])),
58
- text_field(field_name)
59
- ].join("\n").html_safe
60
- end
61
-
62
- def filter_date_range_input(method, options = {})
63
- gt_field_name = "#{method}_gte"
64
- lt_field_name = "#{method}_lte"
65
-
66
- [ label(gt_field_name, options[:label]),
67
- filter_date_text_field(gt_field_name),
68
- template.content_tag(:span, "-", :class => "seperator"),
69
- filter_date_text_field(lt_field_name)
70
- ].join("\n").html_safe
71
- end
72
-
73
- def filter_date_text_field(method)
74
- current_value = @object.send(method)
75
- text_field(method, :size => 12, :class => "datepicker", :max => 10, :value => current_value.respond_to?(:strftime) ? current_value.strftime("%Y-%m-%d") : "")
76
- end
77
-
78
- def filter_numeric_input(method, options = {})
79
- filters = numeric_filters_for_method(method, options.delete(:filters) || default_numeric_filters)
80
- current_filter = current_numeric_scope(filters)
81
- filter_select = @template.select_tag '', @template.options_for_select(filters, current_filter),
82
- :onchange => "document.getElementById('#{method}_numeric').name = 'q[' + this.value + ']';"
83
- filter_input = text_field current_filter, :size => 10, :id => "#{method}_numeric"
84
-
85
- [ label(method, options[:label]),
86
- filter_select,
87
- " ",
88
- filter_input
89
- ].join("\n").html_safe
90
- end
91
-
92
- def numeric_filters_for_method(method, filters)
93
- filters.collect{|scope| [scope[0], [method,scope[1]].join("_") ] }
94
- end
95
-
96
- # Returns the scope for which we are currently searching. If no search is available
97
- # it returns the first scope
98
- def current_numeric_scope(filters)
99
- filters[1..-1].inject(filters.first){|a,b| object.send(b[1].to_sym) ? b : a }[1]
100
- end
101
-
102
- def default_numeric_filters
103
- [[I18n.t('active_admin.equal_to'), 'eq'], [I18n.t('active_admin.greater_than'), 'gt'], [I18n.t('active_admin.less_than'), 'lt']]
104
- end
105
-
106
- def filter_select_input(method, options = {})
107
- association_name = method.to_s.gsub(/_id$/, '').to_sym
108
- input_name = (generate_association_input_name(method).to_s + "_eq").to_sym
109
- collection = find_collection_for_column(association_name, options)
110
-
111
- [ label(input_name, options[:label]),
112
- select(input_name, collection, options.merge(:include_blank => I18n.t('active_admin.any')))
113
- ].join("\n").html_safe
114
- end
115
-
116
- def filter_check_boxes_input(method, options = {})
117
- input_name = (generate_association_input_name(method).to_s + "_in").to_sym
118
- collection = find_collection_for_column(method, options)
119
- selected_values = @object.send(input_name) || []
120
- checkboxes = template.content_tag :div, :class => "check_boxes_wrapper" do
121
- collection.map do |c|
122
- label = c.is_a?(Array) ? c.first : c
123
- value = c.is_a?(Array) ? c.last : c
124
- "<label><input type=\"checkbox\" name=\"q[#{input_name}][]\" value=\"#{value}\" #{selected_values.include?(value) ? "checked" : ""}/> #{label}</label>"
125
- end.join("\n").html_safe
126
- end
127
-
128
- [ label(input_name, options[:label]),
129
- checkboxes
130
- ].join("\n").html_safe
131
- end
132
-
133
- # Override the standard finder to accept a proc
134
- def find_collection_for_column(method, options = {})
135
- options = options.dup
136
- case options[:collection]
137
- when Proc
138
- options[:collection] = options[:collection].call
139
- end
140
- super(method, options)
141
- end
142
-
143
- # Returns the default filter type for a given attribute
144
- def default_filter_type(method)
145
- if column = column_for(method)
146
- case column.type
147
- when :date, :datetime
148
- return :date_range
149
- when :string, :text
150
- return :string
151
- when :integer
152
- return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
153
- return :numeric
154
- when :float, :decimal
155
- return :numeric
156
- end
157
- end
158
-
159
- if reflection = reflection_for(method)
160
- return :select if reflection.macro == :belongs_to && !reflection.options[:polymorphic]
161
- end
162
- end
163
-
164
- # Returns the default label for a given attribute
165
- # Will use ActiveModel I18n if possible
166
- def default_filter_label(method)
167
- if @object.base.respond_to?(:human_attribute_name)
168
- @object.base.human_attribute_name(method)
169
- else
170
- method.to_s.titlecase
171
- end
172
- end
173
-
174
- # Returns the column for an attribute on the object being searched
175
- # if it exists. Otherwise returns nil
176
- def column_for(method)
177
- @object.base.columns_hash[method.to_s] if @object.base.respond_to?(:columns_hash)
178
- end
179
-
180
- # Returns the association reflection for the method if it exists
181
- def reflection_for(method)
182
- @object.base.reflect_on_association(method) if @object.base.respond_to?(:reflect_on_association)
183
- end
184
-
185
- end
186
36
  end
@@ -45,7 +45,7 @@ module ActiveAdmin
45
45
  def content_for(attr_or_proc)
46
46
  value = case attr_or_proc
47
47
  when Proc
48
- attr_or_proc.call
48
+ attr_or_proc.call(@record)
49
49
  else
50
50
  content_for_attribute(attr_or_proc)
51
51
  end
@@ -14,6 +14,10 @@ module ActiveAdmin
14
14
  calculate_columns!
15
15
  end
16
16
 
17
+ def to_s
18
+ super.to_s + "<div style=\"clear:both;\"></div>".html_safe
19
+ end
20
+
17
21
  protected
18
22
 
19
23
  def margin_size
@@ -35,10 +39,6 @@ module ActiveAdmin
35
39
  end
36
40
  end
37
41
 
38
- def to_html
39
- super.to_s + "<div style=\"clear:both;\"></div>".html_safe
40
- end
41
-
42
42
  end
43
43
 
44
44
  class Column < ActiveAdmin::Component
@@ -23,6 +23,7 @@ module ActiveAdmin
23
23
  class PaginatedCollection < ActiveAdmin::Component
24
24
  builder_method :paginated_collection
25
25
 
26
+ attr_reader :collection
26
27
 
27
28
  # Builds a new paginated collection component
28
29
  #
@@ -30,12 +31,21 @@ module ActiveAdmin
30
31
  # @param [Hash] options These options will be passed on to the page_entries_info
31
32
  # method.
32
33
  # Useful keys:
33
- # :entry_name - The name to display for this resource collection
34
+ # :entry_name - The name to display for this resource collection
35
+ # :param_name - Parameter name for page number in the links (:page by default)
36
+ # :download_links - Set to false to skip download format links
34
37
  def build(collection, options = {})
35
38
  @collection = collection
36
- div(page_entries_info(options).html_safe, :class => "pagination_information")
39
+ @param_name = options.delete(:param_name)
40
+ @download_links = options.delete(:download_links)
41
+
42
+ unless collection.respond_to?(:num_pages)
43
+ raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
44
+ end
45
+
46
+
37
47
  @contents = div(:class => "paginated_collection_contents")
38
- build_pagination_with_formats
48
+ build_pagination_with_formats(options)
39
49
  @built = true
40
50
  end
41
51
 
@@ -50,15 +60,19 @@ module ActiveAdmin
50
60
 
51
61
  protected
52
62
 
53
- def build_pagination_with_formats
63
+ def build_pagination_with_formats(options)
54
64
  div :id => "index_footer" do
55
- build_download_format_links
56
65
  build_pagination
66
+ div(page_entries_info(options).html_safe, :class => "pagination_information")
67
+ build_download_format_links unless @download_links == false
57
68
  end
58
69
  end
59
70
 
60
71
  def build_pagination
61
- text_node paginate(collection)
72
+ options = request.query_parameters.except(:commit, :format)
73
+ options[:param_name] = @param_name if @param_name
74
+
75
+ text_node paginate(collection, options.symbolize_keys)
62
76
  end
63
77
 
64
78
  # TODO: Refactor to new HTML DSL
@@ -66,24 +80,39 @@ module ActiveAdmin
66
80
  links = formats.collect do |format|
67
81
  link_to format.to_s.upcase, { :format => format}.merge(request.query_parameters.except(:commit, :format))
68
82
  end
69
- text_node [I18n.t('active_admin.download'), links].flatten.join("&nbsp;").html_safe
83
+ div :class => "download_links" do
84
+ text_node [I18n.t('active_admin.download'), links].flatten.join("&nbsp;").html_safe
85
+ end
70
86
  end
71
87
 
72
88
  # modified from will_paginate
73
89
  def page_entries_info(options = {})
74
- entry_name = options[:entry_name] ||
75
- (collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' '))
90
+ if options[:entry_name]
91
+ entry_name = options[:entry_name]
92
+ entries_name = options[:entries_name]
93
+ elsif collection.empty?
94
+ entry_name = I18n.translate("active_admin.pagination.entry", :count => 1, :default => 'entry')
95
+ entries_name = I18n.translate("active_admin.pagination.entry", :count => 2, :default => 'entries')
96
+ else
97
+ begin
98
+ entry_name = I18n.translate!("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => 1)
99
+ entries_name = I18n.translate!("activerecord.models.#{collection.first.class.model_name.i18n_key}", :count => collection.size)
100
+ rescue I18n::MissingTranslationData
101
+ entry_name = collection.first.class.name.underscore.sub('_', ' ')
102
+ end
103
+ end
104
+ entries_name = entry_name.pluralize unless entries_name
76
105
 
77
106
  if collection.num_pages < 2
78
107
  case collection.size
79
- when 0; I18n.t('active_admin.pagination.empty', :model => entry_name.pluralize)
108
+ when 0; I18n.t('active_admin.pagination.empty', :model => entries_name)
80
109
  when 1; I18n.t('active_admin.pagination.one', :model => entry_name)
81
- else; I18n.t('active_admin.pagination.one_page', :model => entry_name.pluralize, :n => collection.size)
110
+ else; I18n.t('active_admin.pagination.one_page', :model => entries_name, :n => collection.total_count)
82
111
  end
83
112
  else
84
- offset = collection.current_page * active_admin_application.default_per_page
113
+ offset = collection.current_page * collection.size
85
114
  total = collection.total_count
86
- I18n.t('active_admin.pagination.multiple', :model => entry_name.pluralize, :from => (offset - active_admin_application.default_per_page + 1), :to => offset > total ? total : offset, :total => total)
115
+ I18n.t('active_admin.pagination.multiple', :model => entries_name, :from => (offset - collection.size + 1), :to => offset > total ? total : offset, :total => total)
87
116
  end
88
117
  end
89
118
 
@@ -20,6 +20,14 @@ module ActiveAdmin
20
20
  super
21
21
  end
22
22
  end
23
+
24
+ # Override children? to only report children when the panel's
25
+ # contents have been added to. This ensures that the panel
26
+ # correcly appends string values, etc.
27
+ def children?
28
+ @contents.children?
29
+ end
30
+
23
31
  end
24
32
 
25
33
  end
@@ -6,30 +6,40 @@ module ActiveAdmin
6
6
  class Scopes < ActiveAdmin::Component
7
7
  builder_method :scopes_renderer
8
8
 
9
+ include ActiveAdmin::ScopeChain
10
+
11
+ def default_class_name
12
+ "scopes table_tools_segmented_control"
13
+ end
14
+
15
+ def tag_name
16
+ 'ul'
17
+ end
18
+
9
19
  def build(scopes)
10
- scopes.each do |scope|
11
- build_scope(scope)
20
+ unless current_filter_search_empty?
21
+ scopes.each do |scope|
22
+ build_scope(scope) if call_method_or_proc_on(self, scope.display_if_block)
23
+ end
12
24
  end
13
25
  end
14
26
 
15
27
  protected
16
28
 
17
29
  def build_scope(scope)
18
- span :class => classes_for_scope(scope) do
30
+ li :class => classes_for_scope(scope) do
19
31
  begin
20
- scope_name = I18n.t!("active_admin.scopes.#{scope.scope_method}")
32
+ scope_name = I18n.t!("active_admin.scopes.#{scope.id}")
21
33
  rescue I18n::MissingTranslationData
22
34
  scope_name = scope.name
23
35
  end
24
36
 
25
- if current_scope?(scope)
26
- em(scope_name)
27
- else
28
- a(scope_name, :href => url_for(params.merge(:scope => scope.id, :page => 1)))
37
+ a :href => url_for(params.merge(:scope => scope.id, :page => 1)), :class => "table_tools_button" do
38
+ text_node scope_name
39
+ span :class => 'count' do
40
+ "(" + get_scope_count(scope).to_s + ")"
41
+ end
29
42
  end
30
- text_node(" ")
31
- scope_count(scope)
32
- text_node(" ")
33
43
  end
34
44
  end
35
45
 
@@ -47,21 +57,17 @@ module ActiveAdmin
47
57
  end
48
58
  end
49
59
 
50
- def scope_count(scope)
51
- span :class => 'count' do
52
- "(" + get_scope_count(scope).to_s + ")"
53
- end
60
+ def current_filter_search_empty?
61
+ collection.empty? && params.include?(:q)
54
62
  end
55
63
 
56
- include ActiveAdmin::ScopeChain
57
-
58
64
  # Return the count for the scope passed in.
59
65
  def get_scope_count(scope)
60
66
  scope_chain(scope, scoping_class).count
61
67
  end
62
68
 
63
69
  def scoping_class
64
- assigns["before_scope_collection"] || active_admin_config.resource
70
+ assigns["before_scope_collection"] || active_admin_config.resource_class
65
71
  end
66
72
 
67
73
  end
@@ -16,7 +16,7 @@ module ActiveAdmin
16
16
  #
17
17
  # @param [String] status the status to display. One of the span classes will be an underscored version of the status.
18
18
  # @param [Symbol] type type of status. Will become a class of the span. ActiveAdmin provide style for :ok, :warning and :error.
19
- # @param [Hash] options such as :class, :id etc
19
+ # @param [Hash] options such as :class, :id and :label to override the default label
20
20
  #
21
21
  # @return [ActiveAdmin::Views::StatusTag]
22
22
  #
@@ -27,18 +27,19 @@ module ActiveAdmin
27
27
  # status_tag('active', :ok)
28
28
  # # => <span class='status active ok'>Active</span>
29
29
  #
30
- # status_tag('active', :ok, :class => 'important', :id => 'status_123')
31
- # # => <span class='status active ok important' id='status_123'>Active</span>
30
+ # status_tag('active', :ok, :class => 'important', :id => 'status_123', :label => 'on')
31
+ # # => <span class='status active ok important' id='status_123'>on</span>
32
32
  #
33
33
  def build(*args)
34
34
  options = args.extract_options!
35
35
  status = args[0]
36
36
  type = args[1]
37
+ label = options.delete(:label)
37
38
  classes = options.delete(:class)
38
39
 
39
- status = status.titleize if status
40
+ content = label || status.titleize if status
40
41
 
41
- super(status, options)
42
+ super(content, options)
42
43
 
43
44
  add_class(status_to_class(status)) if status
44
45
  add_class(type.to_s) if type