activeadmin 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activeadmin might be problematic. Click here for more details.

Files changed (196) hide show
  1. data/.travis.yml +8 -5
  2. data/CHANGELOG.md +151 -0
  3. data/Gemfile +16 -16
  4. data/LICENSE +1 -1
  5. data/activeadmin.gemspec +1 -0
  6. data/app/assets/images/active_admin/index_list_icons/block_icon.svg +10 -0
  7. data/app/assets/images/active_admin/index_list_icons/blog_icon.svg +4 -0
  8. data/app/assets/images/active_admin/index_list_icons/grid_icon.svg +13 -0
  9. data/app/assets/images/active_admin/index_list_icons/table_icon.svg +3 -0
  10. data/app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee +17 -44
  11. data/app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee +2 -4
  12. data/app/assets/javascripts/active_admin/components/jquery.aa.popover.js.coffee +0 -3
  13. data/app/assets/javascripts/active_admin/components/jquery.aa.table-checkbox-toggler.js.coffee +10 -12
  14. data/app/assets/javascripts/active_admin/pages/application.js.coffee +13 -10
  15. data/app/assets/javascripts/active_admin/pages/batch_actions.js.coffee +3 -3
  16. data/app/assets/stylesheets/active_admin/_base.css.scss +1 -0
  17. data/app/assets/stylesheets/active_admin/_header.css.scss +5 -2
  18. data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +2 -2
  19. data/app/assets/stylesheets/active_admin/components/_index_list.scss +12 -0
  20. data/app/assets/stylesheets/active_admin/components/_popovers.css.scss +2 -2
  21. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +2 -2
  22. data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +4 -4
  23. data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +5 -4
  24. data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +1 -1
  25. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +1 -1
  26. data/app/assets/stylesheets/active_admin/print.css.scss +2 -2
  27. data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +1 -1
  28. data/app/views/active_admin/devise/unlocks/new.html.erb +14 -12
  29. data/docs/1-general-configuration.md +13 -0
  30. data/docs/10-custom-pages.md +40 -28
  31. data/docs/11-decorators.md +6 -4
  32. data/docs/12-arbre-components.md +1 -1
  33. data/docs/13-authorization-adapter.md +206 -0
  34. data/docs/2-resource-customization.md +129 -14
  35. data/docs/3-index-pages.md +65 -0
  36. data/docs/3-index-pages/create-an-index.md +29 -0
  37. data/docs/3-index-pages/index-as-table.md +35 -11
  38. data/docs/5-forms.md +2 -2
  39. data/features/authorization.feature +64 -0
  40. data/features/authorization_cancan.feature +52 -0
  41. data/features/belongs_to.feature +41 -5
  42. data/features/index/batch_actions.feature +27 -3
  43. data/features/index/formats.feature +27 -0
  44. data/features/index/index_as_table.feature +74 -2
  45. data/features/index/index_parameters.feature +69 -0
  46. data/features/index/index_scopes.feature +7 -11
  47. data/features/index/page_title.feature +18 -0
  48. data/features/index/switch_index_view.feature +73 -0
  49. data/features/menu.feature +27 -0
  50. data/features/registering_pages.feature +21 -0
  51. data/features/step_definitions/additional_web_steps.rb +4 -0
  52. data/features/step_definitions/batch_action_steps.rb +16 -6
  53. data/features/step_definitions/index_scope_steps.rb +3 -3
  54. data/features/step_definitions/index_views_steps.rb +3 -0
  55. data/features/step_definitions/menu_steps.rb +4 -0
  56. data/features/support/env.rb +4 -0
  57. data/features/support/paths.rb +3 -0
  58. data/lib/active_admin.rb +4 -0
  59. data/lib/active_admin/application.rb +43 -76
  60. data/lib/active_admin/authorization_adapter.rb +128 -0
  61. data/lib/active_admin/base_controller.rb +18 -1
  62. data/lib/active_admin/base_controller/authorization.rb +153 -0
  63. data/lib/active_admin/base_controller/menu.rb +8 -3
  64. data/lib/active_admin/batch_actions/resource_extension.rb +8 -7
  65. data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -1
  66. data/lib/active_admin/cancan_adapter.rb +40 -0
  67. data/lib/active_admin/dashboards.rb +4 -5
  68. data/lib/active_admin/dashboards/dashboard_controller.rb +1 -1
  69. data/lib/active_admin/devise.rb +22 -7
  70. data/lib/active_admin/dsl.rb +18 -5
  71. data/lib/active_admin/engine.rb +1 -1
  72. data/lib/active_admin/filters/dsl.rb +1 -1
  73. data/lib/active_admin/filters/forms.rb +9 -7
  74. data/lib/active_admin/filters/resource_extension.rb +20 -15
  75. data/lib/active_admin/form_builder.rb +44 -49
  76. data/lib/active_admin/helpers/optional_display.rb +4 -8
  77. data/lib/active_admin/inputs/filter_boolean_input.rb +1 -1
  78. data/lib/active_admin/inputs/filter_string_input.rb +5 -1
  79. data/lib/active_admin/locales/bg.yml +1 -1
  80. data/lib/active_admin/locales/ca.yml +1 -1
  81. data/lib/active_admin/locales/cs.yml +26 -25
  82. data/lib/active_admin/locales/da.yml +1 -1
  83. data/lib/active_admin/locales/de.yml +1 -1
  84. data/lib/active_admin/locales/en.yml +11 -1
  85. data/lib/active_admin/locales/es.yml +16 -16
  86. data/lib/active_admin/locales/fr.yml +1 -1
  87. data/lib/active_admin/locales/he.yml +1 -1
  88. data/lib/active_admin/locales/hr.yml +1 -1
  89. data/lib/active_admin/locales/hu.yml +1 -1
  90. data/lib/active_admin/locales/it.yml +1 -1
  91. data/lib/active_admin/locales/ja.yml +4 -1
  92. data/lib/active_admin/locales/ko.yml +1 -1
  93. data/lib/active_admin/locales/lt.yml +1 -1
  94. data/lib/active_admin/locales/lv.yml +12 -1
  95. data/lib/active_admin/locales/nl.yml +2 -2
  96. data/lib/active_admin/locales/no-NB.yml +22 -1
  97. data/lib/active_admin/locales/pl.yml +1 -1
  98. data/lib/active_admin/locales/pt-BR.yml +1 -1
  99. data/lib/active_admin/locales/pt-PT.yml +81 -0
  100. data/lib/active_admin/locales/ro.yml +1 -1
  101. data/lib/active_admin/locales/ru.yml +1 -1
  102. data/lib/active_admin/locales/sv-SE.yml +1 -1
  103. data/lib/active_admin/locales/tr.yml +1 -1
  104. data/lib/active_admin/locales/vi.yml +1 -1
  105. data/lib/active_admin/locales/zh-CN.yml +1 -1
  106. data/lib/active_admin/locales/zh-TW.yml +1 -1
  107. data/lib/active_admin/menu.rb +76 -38
  108. data/lib/active_admin/menu_collection.rb +96 -0
  109. data/lib/active_admin/menu_item.rb +61 -71
  110. data/lib/active_admin/namespace.rb +67 -5
  111. data/lib/active_admin/page.rb +6 -0
  112. data/lib/active_admin/page_controller.rb +13 -3
  113. data/lib/active_admin/resource.rb +11 -20
  114. data/lib/active_admin/resource/action_items.rb +3 -3
  115. data/lib/active_admin/resource/controllers.rb +0 -17
  116. data/lib/active_admin/resource/menu.rb +52 -24
  117. data/lib/active_admin/resource/naming.rb +6 -10
  118. data/lib/active_admin/resource/page_presenters.rb +57 -3
  119. data/lib/active_admin/resource/routes.rb +46 -0
  120. data/lib/active_admin/resource_controller.rb +2 -17
  121. data/lib/active_admin/resource_controller/data_access.rb +299 -0
  122. data/lib/active_admin/resource_controller/decorators.rb +2 -1
  123. data/lib/active_admin/resource_dsl.rb +12 -14
  124. data/lib/active_admin/router.rb +61 -56
  125. data/lib/active_admin/scope.rb +28 -18
  126. data/lib/active_admin/version.rb +1 -1
  127. data/lib/active_admin/view_factory.rb +0 -1
  128. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +13 -19
  129. data/lib/active_admin/view_helpers/fields_for.rb +2 -0
  130. data/lib/active_admin/view_helpers/form_helper.rb +1 -1
  131. data/lib/active_admin/view_helpers/method_or_proc_helper.rb +66 -11
  132. data/lib/active_admin/views/components/attributes_table.rb +7 -4
  133. data/lib/active_admin/views/components/index_list.rb +68 -0
  134. data/lib/active_admin/views/components/paginated_collection.rb +13 -9
  135. data/lib/active_admin/views/components/scopes.rb +2 -8
  136. data/lib/active_admin/views/components/table_for.rb +1 -1
  137. data/lib/active_admin/views/footer.rb +1 -1
  138. data/lib/active_admin/views/header.rb +3 -2
  139. data/lib/active_admin/views/index_as_block.rb +4 -0
  140. data/lib/active_admin/views/index_as_blog.rb +4 -0
  141. data/lib/active_admin/views/index_as_grid.rb +4 -0
  142. data/lib/active_admin/views/index_as_table.rb +49 -7
  143. data/lib/active_admin/views/pages/index.rb +19 -4
  144. data/lib/active_admin/views/tabbed_navigation.rb +10 -54
  145. data/lib/generators/active_admin/install/install_generator.rb +5 -1
  146. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +58 -0
  147. data/spec/integration/{default_namespace.rb → default_namespace_spec.rb} +0 -16
  148. data/spec/spec_helper.rb +3 -0
  149. data/spec/support/detect_rails_version.rb +10 -3
  150. data/spec/support/rails_template.rb +1 -1
  151. data/spec/support/templates/post_decorator.rb +6 -6
  152. data/spec/unit/application_spec.rb +5 -5
  153. data/spec/unit/authorization/authorization_adapter_spec.rb +61 -0
  154. data/spec/unit/authorization/controller_authorization_spec.rb +47 -0
  155. data/spec/unit/base_controller_spec.rb +0 -2
  156. data/spec/unit/batch_actions/resource_spec.rb +1 -1
  157. data/spec/unit/breadcrumbs_spec.rb +3 -3
  158. data/spec/unit/cancan_adapter_spec.rb +35 -0
  159. data/spec/unit/config_shared_examples.rb +9 -30
  160. data/spec/unit/devise_spec.rb +29 -0
  161. data/spec/unit/dsl_spec.rb +61 -0
  162. data/spec/unit/filters/filter_form_builder_spec.rb +58 -4
  163. data/spec/unit/filters/resource_spec.rb +17 -5
  164. data/spec/unit/form_builder_spec.rb +15 -0
  165. data/spec/unit/menu_collection_spec.rb +62 -0
  166. data/spec/unit/menu_item_spec.rb +51 -37
  167. data/spec/unit/menu_spec.rb +33 -29
  168. data/spec/unit/namespace/authorization_spec.rb +31 -0
  169. data/spec/unit/namespace/register_page_spec.rb +6 -28
  170. data/spec/unit/namespace/register_resource_spec.rb +11 -34
  171. data/spec/unit/namespace_spec.rb +63 -2
  172. data/spec/unit/page_controller_spec.rb +0 -3
  173. data/spec/unit/reloader_spec.rb +5 -5
  174. data/spec/unit/resource/menu_spec.rb +1 -13
  175. data/spec/unit/resource/naming_spec.rb +20 -2
  176. data/spec/unit/resource/page_presenters_spec.rb +14 -2
  177. data/spec/unit/resource_controller/{collection_spec.rb → data_access_spec.rb} +31 -13
  178. data/spec/unit/resource_controller_spec.rb +4 -5
  179. data/spec/unit/resource_spec.rb +33 -11
  180. data/spec/unit/routing_spec.rb +43 -0
  181. data/spec/unit/scope_spec.rb +13 -0
  182. data/spec/unit/view_factory_spec.rb +0 -1
  183. data/spec/unit/view_helpers/fields_for_spec.rb +4 -0
  184. data/spec/unit/view_helpers/form_helper_spec.rb +6 -2
  185. data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +97 -0
  186. data/spec/unit/views/components/attributes_table_spec.rb +11 -0
  187. data/spec/unit/views/components/index_list_spec.rb +32 -0
  188. data/spec/unit/views/tabbed_navigation_spec.rb +42 -40
  189. data/tasks/test.rake +1 -1
  190. metadata +127 -40
  191. data/lib/active_admin/menu_builder.rb +0 -65
  192. data/lib/active_admin/resource_controller/callbacks.rb +0 -59
  193. data/lib/active_admin/resource_controller/collection.rb +0 -158
  194. data/lib/active_admin/views/utility_nav.rb +0 -41
  195. data/spec/unit/base_controller_shared_examples.rb +0 -25
  196. data/spec/unit/dsl_include_spec.rb +0 -20
@@ -1,7 +1,7 @@
1
1
  module ActiveAdmin
2
2
  class Scope
3
3
 
4
- attr_reader :name, :scope_method, :id, :scope_block, :display_if_block, :show_count
4
+ attr_reader :scope_method, :id, :scope_block, :display_if_block, :show_count
5
5
 
6
6
  # Create a Scope
7
7
  #
@@ -13,32 +13,42 @@ module ActiveAdmin
13
13
  # Scope.new('Published', :public)
14
14
  # # => Scope with name 'Published' and scope method :public
15
15
  #
16
- # Scope.new('Published', :public, :if => proc { current_admin_user.can?( :manage, active_admin_config.resource_class ) } ) { |articles| articles.where(:published => true) }
17
- # # => Scope with name 'Published' and scope method :public, optionally displaying the scope per the :if block, using a block
16
+ # Scope.new 'Published', :public, :if => proc { current_admin_user.can? :manage, resource_class } do |articles|
17
+ # articles.where :published => true
18
+ # end
19
+ # # => Scope with name 'Published' and scope method :public, optionally displaying the scope per the :if block
18
20
  #
19
21
  # Scope.new('Published') { |articles| articles.where(:published => true) }
20
22
  # # => Scope with name 'Published' using a block to scope
21
23
  #
24
+ # Scope.new ->{Date.today.strftime '%A'}, :published_today
25
+ # # => Scope with dynamic title using the :published_today scope method
26
+ #
22
27
  def initialize(name, method = nil, options = {}, &block)
23
- @name = name.is_a?( String ) ? name : name.to_s.titleize
24
- @scope_method = method
25
- # Scope ':all' means no scoping
26
- @scope_method ||= name.to_sym unless name.to_sym == :all
27
- @scope_method = nil if method && method.to_s == 'all'
28
- @id = @name.gsub(' ', '').underscore
29
- if block_given?
30
- @scope_method = nil
31
- @scope_block = block
28
+ @name, @scope_method = name, method.try(:to_sym)
29
+
30
+ if name.is_a? Proc
31
+ raise "A string/symbol is required as the second argument if your label is a proc." unless method
32
+ @id = method.to_s.gsub(' ', '').underscore
33
+ else
34
+ @scope_method ||= name.to_sym
35
+ @id = name.to_s.gsub(' ', '').underscore
32
36
  end
33
37
 
34
- @show_count = options[:show_count].nil? ? true : options[:show_count]
35
- @display_if_block = options[:if]
38
+ @scope_method = nil if @scope_method == :all
39
+ @scope_method, @scope_block = nil, block if block_given?
40
+
41
+ @show_count = options[:show_count].nil? ? true : options[:show_count]
42
+ @display_if_block = options[:if] || proc{ true }
36
43
  end
37
44
 
38
- # Returns the display if block. If the block was not explicitly defined
39
- # a default block always returning true will be returned.
40
- def display_if_block
41
- @display_if_block || proc{ true }
45
+ def name
46
+ case @name
47
+ when Proc then @name.call.to_s
48
+ when String then @name
49
+ when Symbol then @name.to_s.titleize
50
+ else @name.to_s
51
+ end
42
52
  end
43
53
 
44
54
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveAdmin
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -6,7 +6,6 @@ module ActiveAdmin
6
6
  # Register Helper Renderers
7
7
  register :global_navigation => ActiveAdmin::Views::TabbedNavigation,
8
8
  :site_title => ActiveAdmin::Views::SiteTitle,
9
- :utility_navigation => ActiveAdmin::Views::UtilityNav,
10
9
  :action_items => ActiveAdmin::Views::ActionItems,
11
10
  :title_bar => ActiveAdmin::Views::TitleBar,
12
11
  :header => ActiveAdmin::Views::Header,
@@ -3,28 +3,22 @@ module ActiveAdmin
3
3
  module BreadcrumbHelper
4
4
 
5
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 = nil
13
- if part =~ /^\d|^[a-f0-9]{24}$/ && (parent = parts[index - 1])
14
- begin
15
- parent_class = parent.singularize.camelcase.constantize
16
- obj = parent_class.find(part[/^[a-f0-9]{24}$/] ? part : part.to_i)
17
- name = display_name(obj)
18
- rescue
19
- # ignored
20
- end
21
- end
6
+ def breadcrumb_links(path = request.path)
7
+ parts = path[1..-1].split('/') # remove leading "/" and split up URL path
8
+ parts.pop unless params[:action] =~ /^create|update$/ # remove last if not create/update
22
9
 
23
- name ||= I18n.t("activerecord.models.#{part.singularize}", :count => 1.1, :default => part.titlecase)
10
+ parts.each_with_index.map do |part, index|
11
+ # If an object (users/23), look it up via ActiveRecord and capture its name.
12
+ # If name is nil, look up the model translation, using `titlecase` as the backup.
13
+ if part =~ /^\d|^[a-f0-9]{24}$/ && parent = parts[index-1]
14
+ klass = parent.singularize.camelcase.constantize rescue nil
15
+ obj = klass.find_by_id(part) if klass
16
+ name = display_name(obj) if obj
17
+ end
18
+ name ||= I18n.t "activerecord.models.#{part.singularize}", :count => 1.1, :default => part.titlecase
24
19
 
25
- crumbs << link_to( name, "/" + parts[0..index].join('/'))
20
+ link_to name, '/' + parts[0..index].join('/')
26
21
  end
27
- crumbs
28
22
  end
29
23
 
30
24
  end
@@ -38,6 +38,8 @@ module ActiveAdmin
38
38
  end
39
39
  when nil
40
40
  { k => '' }
41
+ when TrueClass,FalseClass
42
+ { k => v }
41
43
  else
42
44
  raise "I don't know what to do with #{v.class} params: #{v.inspect}"
43
45
  end
@@ -11,7 +11,7 @@ module ActiveAdmin
11
11
  def hidden_field_tags_for(params, options={})
12
12
  fields_for_params(params, options).map do |kv|
13
13
  k, v = kv.first
14
- hidden_field_tag k, v
14
+ hidden_field_tag k, v, :id => sanitize_to_id("hidden_active_admin_#{k}")
15
15
  end.join("\n").html_safe
16
16
  end
17
17
  end
@@ -1,24 +1,64 @@
1
1
  module MethodOrProcHelper
2
2
 
3
+ # This method will either call the symbol on self or instance_exec the Proc
4
+ # within self. Any args will be passed along to the method dispatch.
5
+ #
6
+ # Calling with a Symbol:
7
+ #
8
+ # call_method_or_exec_proc(:to_s) #=> will call #to_s
9
+ #
10
+ # Calling with a Proc
11
+ #
12
+ # my_proc = Proc.new{ to_s }
13
+ # call_method_or_exec_proc(my_proc) #=> will instance_exec in self
14
+ #
15
+ def call_method_or_exec_proc(symbol_or_proc, *args)
16
+ case symbol_or_proc
17
+ when Symbol, String
18
+ send(symbol_or_proc, *args)
19
+ when Proc
20
+ instance_exec(*args, &symbol_or_proc)
21
+ end
22
+ end
23
+
3
24
  # Many times throughout the views we want to either call a method on an object
4
25
  # or instance_exec a proc passing in the object as the first parameter. This
5
- # method takes care of this functionality.
26
+ # method wraps that pattern.
27
+ #
28
+ # Calling with a Symbol:
6
29
  #
7
- # call_method_or_proc_on(@my_obj, :size) same as @my_obj.size
8
- # OR
9
- # proc = Proc.new{|s| s.size }
10
- # call_method_or_proc_on(@my_obj, proc)
30
+ # call_method_or_proc_on(@my_obj, :size) same as @my_obj.size
11
31
  #
12
- def call_method_or_proc_on(obj, symbol_or_proc, options = {})
13
- exec = options[:exec].nil? ? true : options[:exec]
32
+ # Calling with a Proc:
33
+ #
34
+ # proc = Proc.new{|s| s.size }
35
+ # call_method_or_proc_on(@my_obj, proc)
36
+ #
37
+ # By default, the Proc will be instance_exec'd within self. If you would rather
38
+ # not instance exec, but just call the Proc, then pass along `:exec => false` in
39
+ # the options hash.
40
+ #
41
+ # proc = Proc.new{|s| s.size }
42
+ # call_method_or_proc_on(@my_obj, proc, :exec => false)
43
+ #
44
+ # You can pass along any necessary arguments to the method / Proc as arguments. For
45
+ # example:
46
+ #
47
+ # call_method_or_proc_on(@my_obj, :find, 1) #=> @my_obj.find(1)
48
+ #
49
+ def call_method_or_proc_on(receiver, *args)
50
+ options = { :exec => true }.merge(args.extract_options!)
51
+
52
+ symbol_or_proc = args.shift
53
+
14
54
  case symbol_or_proc
15
55
  when Symbol, String
16
- obj.send(symbol_or_proc.to_sym)
56
+ receiver.send(symbol_or_proc.to_sym, *args)
17
57
  when Proc
18
- if exec
19
- instance_exec(obj, &symbol_or_proc)
58
+ if options[:exec]
59
+ instance_exec(receiver, *args, &symbol_or_proc)
20
60
  else
21
- symbol_or_proc.call(obj)
61
+ symbol_or_proc.call(receiver, *args)
22
62
  end
23
63
  end
24
64
  end
@@ -35,4 +75,19 @@ module MethodOrProcHelper
35
75
  string_symbol_or_proc
36
76
  end
37
77
  end
78
+
79
+ # This method is different from the others in that it calls `instance_eval` on the reciever,
80
+ # passing it the proc. This evaluates the proc in the context of the reciever, thus changing
81
+ # what `self` means inside the proc.
82
+ def render_in_context(context, obj)
83
+ context ||= self # default to `self`
84
+ case obj
85
+ when Proc
86
+ context.instance_exec &obj
87
+ when Symbol
88
+ context.send obj
89
+ else
90
+ obj
91
+ end
92
+ end
38
93
  end
@@ -17,13 +17,16 @@ module ActiveAdmin
17
17
  attrs.each {|attr| row(attr) }
18
18
  end
19
19
 
20
- def row(attr, &block)
21
- @table << tr do
20
+ def row(*args, &block)
21
+ title = args[0]
22
+ options = args.extract_options!
23
+ options[:class] ||= :row
24
+ @table << tr(options) do
22
25
  th do
23
- header_content_for(attr)
26
+ header_content_for(title)
24
27
  end
25
28
  td do
26
- content_for(block || attr)
29
+ content_for(block || title)
27
30
  end
28
31
  end
29
32
  end
@@ -0,0 +1,68 @@
1
+ require 'active_admin/helpers/collection'
2
+
3
+ module ActiveAdmin
4
+ module Views
5
+
6
+ # Renders a collection of index views available to the resource
7
+ # as a list with a separator
8
+ class IndexList < ActiveAdmin::Component
9
+ builder_method :index_list_renderer
10
+
11
+ include ::ActiveAdmin::Helpers::Collection
12
+
13
+ def default_class_name
14
+ "indexes table_tools_segmented_control"
15
+ end
16
+
17
+ def tag_name
18
+ 'ul'
19
+ end
20
+
21
+ # Builds the links for presenting different index views to the user
22
+ #
23
+ # @param [Array] index_classes The class constants that represent index page presenters
24
+ def build(index_classes)
25
+ unless current_filter_search_empty?
26
+ index_classes.each do |index_class|
27
+ build_index_list(index_class)
28
+ end
29
+ end
30
+ end
31
+
32
+ protected
33
+
34
+ # Builds the individual link and HTML classes for each index page presenter
35
+ #
36
+ # @param [Class] index_class The class on which to build the link and html classes
37
+ def build_index_list(index_class)
38
+ li :class => classes_for_index(index_class) do
39
+ a :href => url_for(params.merge(:as => index_class.index_name.to_sym)), :class => "table_tools_button" do
40
+ name = index_class.index_name
41
+ I18n.t("active_admin.index_list.#{name}", :default => name.to_s.titleize)
42
+ end
43
+ end
44
+ end
45
+
46
+ def classes_for_index(index_class)
47
+ classes = ["index"]
48
+ classes << "selected" if current_index?(index_class)
49
+ classes.join(" ")
50
+ end
51
+
52
+ def current_index?(index_class)
53
+ if params[:as]
54
+ params[:as] == index_class.index_name
55
+ else
56
+ active_admin_config.default_index_class == index_class
57
+ end
58
+ end
59
+
60
+ def current_filter_search_empty?
61
+ params.include?(:q) && collection_is_empty?
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+
68
+
@@ -29,13 +29,12 @@ module ActiveAdmin
29
29
 
30
30
  # Builds a new paginated collection component
31
31
  #
32
- # @param [Array] collection A "paginated" collection from kaminari
33
- # @param [Hash] options These options will be passed on to the page_entries_info
34
- # method.
35
- # Useful keys:
36
- # :entry_name - The name to display for this resource collection
37
- # :param_name - Parameter name for page number in the links (:page by default)
38
- # :download_links - Set to false to skip download format links
32
+ # collection => A paginated collection from kaminari
33
+ # options => These options will be passed to `page_entries_info`
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 => Download links override (false or [:csv, :pdf])
37
+ #
39
38
  def build(collection, options = {})
40
39
  @collection = collection
41
40
  @param_name = options.delete(:param_name)
@@ -45,7 +44,6 @@ module ActiveAdmin
45
44
  raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
46
45
  end
47
46
 
48
-
49
47
  @contents = div(:class => "paginated_collection_contents")
50
48
  build_pagination_with_formats(options)
51
49
  @built = true
@@ -66,7 +64,13 @@ module ActiveAdmin
66
64
  div :id => "index_footer" do
67
65
  build_pagination
68
66
  div(page_entries_info(options).html_safe, :class => "pagination_information")
69
- build_download_format_links unless @download_links == false
67
+
68
+ if @download_links.is_a?(Array) && !@download_links.empty?
69
+ build_download_format_links @download_links
70
+ else
71
+ build_download_format_links unless @download_links == false
72
+ end
73
+
70
74
  end
71
75
  end
72
76
 
@@ -21,10 +21,8 @@ module ActiveAdmin
21
21
  end
22
22
 
23
23
  def build(scopes, options = {})
24
- unless current_filter_search_empty?
25
- scopes.each do |scope|
26
- build_scope(scope, options) if call_method_or_proc_on(self, scope.display_if_block)
27
- end
24
+ scopes.each do |scope|
25
+ build_scope(scope, options) if call_method_or_proc_on(self, scope.display_if_block)
28
26
  end
29
27
  end
30
28
 
@@ -57,10 +55,6 @@ module ActiveAdmin
57
55
  end
58
56
  end
59
57
 
60
- def current_filter_search_empty?
61
- params.include?(:q) && collection_is_empty?
62
- end
63
-
64
58
  # Return the count for the scope passed in.
65
59
  def get_scope_count(scope)
66
60
  collection_size(scope_chain(scope, collection_before_scope))
@@ -79,7 +79,7 @@ module ActiveAdmin
79
79
  def build_table_body
80
80
  @tbody = tbody do
81
81
  # Build enough rows for our collection
82
- @collection.each{|_| tr(:class => cycle('odd', 'even'), :id => dom_id(_)) }
82
+ @collection.each{|elem| tr(:class => cycle('odd', 'even'), :id => dom_id(elem)) }
83
83
  end
84
84
  end
85
85
 
@@ -10,7 +10,7 @@ module ActiveAdmin
10
10
  private
11
11
 
12
12
  def powered_by_message
13
- para t('active_admin.powered_by',
13
+ para I18n.t('active_admin.powered_by',
14
14
  :active_admin => link_to("Active Admin", "http://www.activeadmin.info"),
15
15
  :version => ActiveAdmin::VERSION).html_safe
16
16
  end
@@ -7,6 +7,7 @@ module ActiveAdmin
7
7
 
8
8
  @namespace = namespace
9
9
  @menu = menu
10
+ @utility_menu = @namespace.fetch_menu(:utility_navigation)
10
11
 
11
12
  build_site_title
12
13
  build_global_navigation
@@ -19,11 +20,11 @@ module ActiveAdmin
19
20
  end
20
21
 
21
22
  def build_global_navigation
22
- insert_tag view_factory.global_navigation, @menu, :class => 'header-item'
23
+ insert_tag view_factory.global_navigation, @menu, :class => 'header-item tabs'
23
24
  end
24
25
 
25
26
  def build_utility_navigation
26
- insert_tag view_factory.utility_navigation, @namespace
27
+ insert_tag view_factory.global_navigation, @utility_menu, :id => "utility_nav", :class => 'header-item tabs'
27
28
  end
28
29
 
29
30
  end
@@ -27,6 +27,10 @@ module ActiveAdmin
27
27
  end
28
28
  end
29
29
 
30
+ def self.index_name
31
+ "block"
32
+ end
33
+
30
34
  end
31
35
  end
32
36
  end