activeadmin 1.0.0.pre2 → 1.0.0.pre3

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 (162) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +7 -4
  3. data/.travis.yml +17 -15
  4. data/CHANGELOG.md +5 -1
  5. data/CODE_OF_CONDUCT.md +22 -0
  6. data/Gemfile +26 -12
  7. data/README.md +24 -4
  8. data/activeadmin.gemspec +1 -0
  9. data/app/assets/javascripts/active_admin/base.js.coffee +1 -1
  10. data/app/assets/javascripts/active_admin/initializers/batch_actions.js.coffee +7 -0
  11. data/app/assets/javascripts/active_admin/initializers/datepicker.js.coffee +10 -0
  12. data/app/assets/javascripts/active_admin/initializers/filters.js.coffee +15 -0
  13. data/app/assets/javascripts/active_admin/initializers/tabs.js.coffee +3 -0
  14. data/app/assets/javascripts/active_admin/lib/batch_actions.js.coffee +1 -1
  15. data/app/assets/javascripts/active_admin/lib/dropdown-menu.js.coffee +1 -1
  16. data/app/assets/stylesheets/active_admin/_forms.scss +1 -1
  17. data/config/locales/ar.yml +47 -43
  18. data/config/locales/de.yml +2 -1
  19. data/config/locales/en.yml +2 -1
  20. data/config/locales/es-MX.yml +3 -3
  21. data/config/locales/es.yml +5 -4
  22. data/config/locales/fr.yml +2 -1
  23. data/config/locales/hu.yml +1 -1
  24. data/config/locales/id.yml +2 -1
  25. data/config/locales/it.yml +19 -0
  26. data/config/locales/ja.yml +2 -1
  27. data/config/locales/ko.yml +2 -1
  28. data/config/locales/nb.yml +6 -1
  29. data/config/locales/nl.yml +1 -1
  30. data/config/locales/pt-BR.yml +5 -1
  31. data/config/locales/ru.yml +4 -3
  32. data/config/locales/sv-SE.yml +3 -2
  33. data/config/locales/tr.yml +83 -44
  34. data/config/locales/uk.yml +13 -12
  35. data/config/locales/zh-CN.yml +2 -1
  36. data/config/locales/zh-TW.yml +10 -1
  37. data/cucumber.yml +1 -1
  38. data/docs/0-installation.md +24 -10
  39. data/docs/1-general-configuration.md +22 -0
  40. data/docs/12-arbre-components.md +1 -1
  41. data/docs/13-authorization-adapter.md +1 -1
  42. data/docs/14-gotchas.md +11 -3
  43. data/docs/2-resource-customization.md +16 -3
  44. data/docs/3-index-pages.md +1 -1
  45. data/docs/3-index-pages/index-as-table.md +13 -1
  46. data/docs/4-csv-format.md +19 -0
  47. data/docs/5-forms.md +14 -2
  48. data/docs/6-show-pages.md +1 -1
  49. data/features/decorators.feature +2 -0
  50. data/features/development_reloading.feature +1 -1
  51. data/features/edit_page.feature +4 -4
  52. data/features/index/batch_actions.feature +13 -0
  53. data/features/index/page_title.feature +2 -1
  54. data/features/new_page.feature +4 -4
  55. data/features/renamed_resource.feature +1 -1
  56. data/features/show/default_content.feature +1 -1
  57. data/features/show/page_title.feature +2 -1
  58. data/features/step_definitions/attribute_steps.rb +2 -2
  59. data/features/step_definitions/factory_steps.rb +2 -2
  60. data/features/step_definitions/filter_steps.rb +2 -2
  61. data/features/step_definitions/format_steps.rb +1 -1
  62. data/features/sti_resource.feature +2 -2
  63. data/features/strong_parameters.feature +3 -3
  64. data/features/support/env.rb +21 -4
  65. data/lib/active_admin/application.rb +11 -4
  66. data/lib/active_admin/authorization_adapter.rb +1 -1
  67. data/lib/active_admin/base_controller.rb +12 -2
  68. data/lib/active_admin/base_controller/authorization.rb +4 -7
  69. data/lib/active_admin/base_controller/menu.rb +5 -1
  70. data/lib/active_admin/batch_actions/controller.rb +0 -1
  71. data/lib/active_admin/batch_actions/resource_extension.rb +3 -2
  72. data/lib/active_admin/batch_actions/views/batch_action_selector.rb +1 -0
  73. data/lib/active_admin/csv_builder.rb +18 -15
  74. data/lib/active_admin/dependency.rb +74 -1
  75. data/lib/active_admin/error.rb +1 -1
  76. data/lib/active_admin/filters/active.rb +4 -3
  77. data/lib/active_admin/filters/resource_extension.rb +7 -3
  78. data/lib/active_admin/generators/boilerplate.rb +8 -0
  79. data/lib/active_admin/inputs/filters/base.rb +3 -1
  80. data/lib/active_admin/inputs/filters/base/search_method_select.rb +3 -3
  81. data/lib/active_admin/inputs/filters/date_range_input.rb +2 -2
  82. data/lib/active_admin/inputs/filters/select_input.rb +3 -2
  83. data/lib/active_admin/orm/active_record/comments.rb +13 -8
  84. data/lib/active_admin/page_controller.rb +5 -1
  85. data/lib/active_admin/reloader.rb +25 -0
  86. data/lib/active_admin/resource/menu.rb +1 -1
  87. data/lib/active_admin/resource_controller/data_access.rb +33 -20
  88. data/lib/active_admin/resource_controller/decorators.rb +2 -2
  89. data/lib/active_admin/resource_controller/streaming.rb +7 -1
  90. data/lib/active_admin/resource_dsl.rb +15 -9
  91. data/lib/active_admin/router.rb +1 -1
  92. data/lib/active_admin/scope.rb +2 -3
  93. data/lib/active_admin/version.rb +1 -1
  94. data/lib/active_admin/view_helpers/display_helper.rb +31 -0
  95. data/lib/active_admin/view_helpers/fields_for.rb +3 -2
  96. data/lib/active_admin/views/components/attributes_table.rb +5 -23
  97. data/lib/active_admin/views/components/index_list.rb +1 -1
  98. data/lib/active_admin/views/components/paginated_collection.rb +3 -3
  99. data/lib/active_admin/views/components/site_title.rb +1 -1
  100. data/lib/active_admin/views/components/table_for.rb +8 -27
  101. data/lib/active_admin/views/index_as_grid.rb +2 -2
  102. data/lib/active_admin/views/index_as_table.rb +24 -2
  103. data/lib/active_admin/views/pages/base.rb +1 -1
  104. data/lib/active_admin/views/pages/form.rb +6 -2
  105. data/lib/active_admin/views/title_bar.rb +1 -1
  106. data/lib/generators/active_admin/assets/templates/active_admin.scss +1 -1
  107. data/lib/generators/active_admin/install/install_generator.rb +1 -1
  108. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +14 -4
  109. data/lib/generators/active_admin/resource/templates/admin.rb +8 -2
  110. data/lib/ransack_ext.rb +8 -0
  111. data/script/local +15 -6
  112. data/spec/rails_helper.rb +12 -1
  113. data/spec/requests/javascript_spec.rb +15 -13
  114. data/spec/requests/stylesheets_spec.rb +1 -1
  115. data/spec/support/detect_rails_version.rb +1 -1
  116. data/spec/support/rails_template.rb +117 -104
  117. data/spec/support/rails_template_with_data.rb +5 -9
  118. data/spec/support/templates/admin/stores.rb +1 -1
  119. data/spec/unit/action_builder_spec.rb +58 -56
  120. data/spec/unit/authorization/authorization_adapter_spec.rb +5 -5
  121. data/spec/unit/authorization/index_overriding_spec.rb +2 -1
  122. data/spec/unit/auto_link_spec.rb +1 -1
  123. data/spec/unit/batch_actions/resource_spec.rb +2 -2
  124. data/spec/unit/batch_actions/settings_spec.rb +13 -13
  125. data/spec/unit/comments_spec.rb +5 -5
  126. data/spec/unit/csv_builder_spec.rb +59 -0
  127. data/spec/unit/dsl_spec.rb +1 -1
  128. data/spec/unit/filters/filter_form_builder_spec.rb +5 -4
  129. data/spec/unit/filters/resource_spec.rb +7 -0
  130. data/spec/unit/form_builder_spec.rb +4 -1
  131. data/spec/unit/generators/install_spec.rb +4 -4
  132. data/spec/unit/helpers/collection_spec.rb +4 -4
  133. data/spec/unit/menu_collection_spec.rb +3 -3
  134. data/spec/unit/namespace/register_page_spec.rb +17 -18
  135. data/spec/unit/namespace/register_resource_spec.rb +20 -21
  136. data/spec/unit/namespace_spec.rb +4 -4
  137. data/spec/unit/pundit_adapter_spec.rb +3 -3
  138. data/spec/unit/resource/action_items_spec.rb +1 -1
  139. data/spec/unit/resource/naming_spec.rb +1 -1
  140. data/spec/unit/resource/routes_spec.rb +6 -2
  141. data/spec/unit/resource/scopes_spec.rb +2 -2
  142. data/spec/unit/resource_controller/decorators_spec.rb +11 -0
  143. data/spec/unit/resource_controller/sidebars_spec.rb +17 -24
  144. data/spec/unit/resource_spec.rb +14 -12
  145. data/spec/unit/routing_spec.rb +19 -14
  146. data/spec/unit/scope_spec.rb +28 -33
  147. data/spec/unit/view_helpers/display_helper_spec.rb +165 -0
  148. data/spec/unit/view_helpers/download_format_links_helper_spec.rb +9 -9
  149. data/spec/unit/views/components/attributes_table_spec.rb +1 -1
  150. data/spec/unit/views/components/blank_slate_spec.rb +3 -3
  151. data/spec/unit/views/components/index_table_for_spec.rb +82 -1
  152. data/spec/unit/views/components/paginated_collection_spec.rb +0 -1
  153. data/spec/unit/views/components/table_for_spec.rb +13 -8
  154. data/spec/unit/views/components/unsupported_browser_spec.rb +2 -8
  155. data/spec/unit/views/index_as_blog_spec.rb +76 -0
  156. data/spec/unit/views/pages/form_spec.rb +9 -0
  157. data/tasks/test.rake +13 -5
  158. metadata +27 -10
  159. data/app/assets/javascripts/active_admin/application.js.coffee +0 -37
  160. data/spec/support/templates/cucumber.rb +0 -24
  161. data/spec/support/templates/cucumber_with_reloading.rb +0 -5
  162. data/spec/unit/view_helpers/display_name_spec.rb +0 -71
@@ -28,7 +28,7 @@ module ActiveAdmin
28
28
 
29
29
  def decorate?
30
30
  case action_name
31
- when 'new', 'edit'
31
+ when 'new', 'edit', 'create', 'update'
32
32
  form = active_admin_config.get_page_presenter :form
33
33
  form && form.options[:decorate] && decorator_class.present?
34
34
  else
@@ -67,7 +67,7 @@ module ActiveAdmin
67
67
  def self.wrap!(parent, name)
68
68
  ::Class.new parent do
69
69
  delegate :reorder, :page, :current_page, :total_pages, :limit_value,
70
- :total_count, :num_pages, :to_key, :group_values, :except,
70
+ :total_count, :total_pages, :to_key, :group_values, :except,
71
71
  :find_each, :ransack
72
72
 
73
73
  define_singleton_method(:name) { name }
@@ -20,7 +20,12 @@ module ActiveAdmin
20
20
  def stream_resource(&block)
21
21
  headers['X-Accel-Buffering'] = 'no'
22
22
  headers['Cache-Control'] = 'no-cache'
23
- self.response_body = Enumerator.new &block
23
+
24
+ if ActiveAdmin.application.disable_streaming_in.include? Rails.env
25
+ self.response_body = block['']
26
+ else
27
+ self.response_body = Enumerator.new &block
28
+ end
24
29
  end
25
30
 
26
31
  def csv_filename
@@ -28,6 +33,7 @@ module ActiveAdmin
28
33
  end
29
34
 
30
35
  def stream_csv
36
+ headers['Content-Type'] = 'text/csv; charset=utf-8' # In Rails 5 it's set to HTML??
31
37
  headers['Content-Disposition'] = %{attachment; filename="#{csv_filename}"}
32
38
  stream_resource &active_admin_config.csv_builder.method(:build).to_proc.curry[self]
33
39
  end
@@ -116,7 +116,8 @@ module ActiveAdmin
116
116
  title = options.delete(:title)
117
117
 
118
118
  controller do
119
- before_filter(only: [name]) { @page_title = title } if title
119
+ callback = ActiveAdmin::Dependency.rails >= 4 ? :before_action : :before_filter
120
+ send(callback, only: [name]) { @page_title = title } if title
120
121
  define_method(name, &block || Proc.new{})
121
122
  end
122
123
  end
@@ -159,14 +160,19 @@ module ActiveAdmin
159
160
  delegate :before_save, :after_save, to: :controller
160
161
  delegate :before_destroy, :after_destroy, to: :controller
161
162
 
162
- # Standard rails filters
163
- delegate :before_filter, :skip_before_filter, to: :controller
164
- delegate :after_filter, :skip_after_filter, to: :controller
165
- delegate :around_filter, :skip_filter, to: :controller
166
- if Rails::VERSION::MAJOR == 4
167
- delegate :before_action, :skip_before_action, to: :controller
168
- delegate :after_action, :skip_after_action, to: :controller
169
- delegate :around_action, :skip_action, to: :controller
163
+ # This code defines both *_filter and *_action for Rails 3.2 to Rails 5.
164
+ actions = [
165
+ :before, :skip_before,
166
+ :after, :skip_after,
167
+ :around, :skip
168
+ ]
169
+ destination = ActiveAdmin::Dependency.rails >= 4 ? :action : :filter
170
+ [:action, :filter].each do |name|
171
+ actions.each do |action|
172
+ define_method "#{action}_#{name}" do |*args, &block|
173
+ controller.public_send "#{action}_#{destination}", *args, &block
174
+ end
175
+ end
170
176
  end
171
177
 
172
178
  # Specify which actions to create in the controller
@@ -24,7 +24,7 @@ module ActiveAdmin
24
24
  root namespace.root_to_options.merge(to: namespace.root_to)
25
25
  else
26
26
  namespace namespace.name do
27
- root namespace.root_to_options.merge(to: namespace.root_to)
27
+ root namespace.root_to_options.merge(to: namespace.root_to, as: :root)
28
28
  end
29
29
  end
30
30
  end
@@ -29,10 +29,10 @@ module ActiveAdmin
29
29
 
30
30
  if name.is_a? Proc
31
31
  raise "A string/symbol is required as the second argument if your label is a proc." unless method
32
- @id = method.to_s.parameterize("_")
32
+ @id = ActiveAdmin::Dependency.rails.parameterize method.to_s
33
33
  else
34
34
  @scope_method ||= name.to_sym
35
- @id = name.to_s.parameterize("_")
35
+ @id = ActiveAdmin::Dependency.rails.parameterize name.to_s
36
36
  end
37
37
 
38
38
  @scope_method = nil if @scope_method == :all
@@ -41,7 +41,6 @@ module ActiveAdmin
41
41
  @show_count = options.fetch(:show_count, true)
42
42
  @display_if_block = options[:if] || proc{ true }
43
43
  @default_block = options[:default] || proc{ false }
44
-
45
44
  end
46
45
 
47
46
  def name
@@ -1,3 +1,3 @@
1
1
  module ActiveAdmin
2
- VERSION = '1.0.0.pre2'
2
+ VERSION = '1.0.0.pre3'
3
3
  end
@@ -40,6 +40,25 @@ module ActiveAdmin
40
40
  resource.class.reflect_on_all_associations.map(&:name)
41
41
  end
42
42
 
43
+ def format_attribute(resource, attr)
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
48
+ end
49
+
50
+ def find_value(resource, attr)
51
+ if attr.is_a? Proc
52
+ attr.call resource
53
+ elsif attr =~ /\A(.+)_id\z/ && reflection_for(resource, $1.to_sym)
54
+ resource.public_send $1
55
+ elsif resource.respond_to? attr
56
+ resource.public_send attr
57
+ elsif resource.respond_to? :[]
58
+ resource[attr]
59
+ end
60
+ end
61
+
43
62
  # Attempts to create a human-readable string for any object
44
63
  def pretty_format(object)
45
64
  case object
@@ -56,6 +75,18 @@ module ActiveAdmin
56
75
  end
57
76
  end
58
77
  end
78
+
79
+ def reflection_for(resource, method)
80
+ klass = resource.class
81
+ klass.reflect_on_association method if klass.respond_to? :reflect_on_association
82
+ end
83
+
84
+ def boolean_attr?(resource, attr)
85
+ if resource.class.respond_to? :columns_hash
86
+ column = resource.class.columns_hash[attr.to_s] and column.type == :boolean
87
+ end
88
+ end
89
+
59
90
  end
60
91
  end
61
92
  end
@@ -15,11 +15,12 @@ module ActiveAdmin
15
15
  #
16
16
  def fields_for_params(params, options = {})
17
17
  namespace = options[:namespace]
18
- except = options[:except].is_a?(Array) ? options[:except] : [options[:except]]
18
+ except = Array.wrap(options[:except]).map &:to_s
19
+ params = params.respond_to?(:to_unsafe_h) ? params.to_unsafe_h : params
19
20
 
20
21
  params.flat_map do |k, v|
21
22
  next if namespace.nil? && %w(controller action commit utf8).include?(k.to_s)
22
- next if except.map(&:to_s).include?(k.to_s)
23
+ next if except.include?(k.to_s)
23
24
 
24
25
  if namespace
25
26
  k = "#{namespace}[#{k}]"
@@ -5,7 +5,7 @@ module ActiveAdmin
5
5
  builder_method :attributes_table_for
6
6
 
7
7
  def build(obj, *attrs)
8
- @collection = is_array?(obj) ? obj : [obj]
8
+ @collection = Array.wrap(obj)
9
9
  @resource_class = @collection.first.class
10
10
  options = { }
11
11
  options[:for] = @collection.first if single_record?
@@ -26,7 +26,7 @@ module ActiveAdmin
26
26
  if options[:class]
27
27
  classes << options[:class]
28
28
  elsif title.present?
29
- classes << "row-#{title.to_s.parameterize('_')}"
29
+ classes << "row-#{ActiveAdmin::Dependency.rails.parameterize(title.to_s)}"
30
30
  end
31
31
  options[:class] = classes.join(' ')
32
32
 
@@ -79,33 +79,15 @@ module ActiveAdmin
79
79
  end
80
80
 
81
81
  def content_for(record, attr)
82
- value = pretty_format find_attr_value(record, attr)
82
+ value = format_attribute record, attr
83
83
  value.blank? && current_arbre_element.children.to_s.empty? ? empty_value : value
84
- end
85
-
86
- def find_attr_value(record, attr)
87
- if attr.is_a?(Proc)
88
- attr.call(record)
89
- elsif attr =~ /\A(.+)_id\z/ && reflection_for(record.class, $1.to_sym)
90
- record.public_send $1
91
- elsif record.respond_to? attr
92
- record.public_send attr
93
- elsif record.respond_to? :[]
94
- record[attr]
95
- end
96
- end
97
-
98
- def reflection_for(klass, method)
99
- klass.reflect_on_association method if klass.respond_to? :reflect_on_association
84
+ # Don't add the same Arbre twice, while still allowing format_attribute to call status_tag
85
+ current_arbre_element << value unless current_arbre_element.children.include? value
100
86
  end
101
87
 
102
88
  def single_record?
103
89
  @single_record ||= @collection.size == 1
104
90
  end
105
-
106
- def is_array?(obj)
107
- obj.respond_to?(:each) && obj.respond_to?(:first) && !obj.is_a?(Hash)
108
- end
109
91
  end
110
92
 
111
93
  end
@@ -36,7 +36,7 @@ module ActiveAdmin
36
36
  # @param [Class] index_class The class on which to build the link and html classes
37
37
  def build_index_list(index_class)
38
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
39
+ a href: url_for(as: index_class.index_name.to_sym), class: "table_tools_button" do
40
40
  name = index_class.index_name
41
41
  I18n.t("active_admin.index_list.#{name}", default: name.to_s.titleize)
42
42
  end
@@ -44,7 +44,7 @@ module ActiveAdmin
44
44
  @display_total = options.delete(:pagination_total) { true }
45
45
  @per_page = options.delete(:per_page)
46
46
 
47
- unless collection.respond_to?(:num_pages)
47
+ unless collection.respond_to?(:total_pages)
48
48
  raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
49
49
  end
50
50
 
@@ -132,7 +132,7 @@ module ActiveAdmin
132
132
  end
133
133
 
134
134
  if @display_total
135
- if collection.num_pages < 2
135
+ if collection.total_pages < 2
136
136
  case collection_size
137
137
  when 0; I18n.t("active_admin.pagination.empty", model: entries_name)
138
138
  when 1; I18n.t("active_admin.pagination.one", model: entry_name)
@@ -149,7 +149,7 @@ module ActiveAdmin
149
149
  end
150
150
  else
151
151
  # Do not display total count, in order to prevent a `SELECT count(*)`.
152
- # To do so we must not call `collection.num_pages`
152
+ # To do so we must not call `collection.total_pages`
153
153
  offset = (collection.current_page - 1) * collection.limit_value
154
154
  I18n.t "active_admin.pagination.multiple_without_total",
155
155
  model: entries_name,
@@ -46,7 +46,7 @@ module ActiveAdmin
46
46
 
47
47
  def title_image
48
48
  path = helpers.render_or_call_method_or_proc_on(self, @namespace.site_title_image)
49
- helpers.image_tag(path, id: "site_title_image", alt: @namespace.site_title)
49
+ helpers.image_tag(path, id: "site_title_image", alt: title_text)
50
50
  end
51
51
 
52
52
  end
@@ -39,9 +39,9 @@ module ActiveAdmin
39
39
  end
40
40
 
41
41
  # Add a table cell for each item
42
- @collection.each_with_index do |item, i|
43
- within @tbody.children[i] do
44
- build_table_cell col, item
42
+ @collection.each_with_index do |resource, index|
43
+ within @tbody.children[index] do
44
+ build_table_cell col, resource
45
45
  end
46
46
  end
47
47
  end
@@ -96,30 +96,11 @@ module ActiveAdmin
96
96
  end
97
97
  end
98
98
 
99
- def build_table_cell(col, item)
99
+ def build_table_cell(col, resource)
100
100
  td class: col.html_class do
101
- render_data col.data, item
102
- end
103
- end
104
-
105
- def render_data(data, item)
106
- value = if data.is_a? Proc
107
- data.call item
108
- elsif item.respond_to? data
109
- item.public_send data
110
- elsif item.respond_to? :[]
111
- item[data]
112
- end
113
- value = pretty_format(value) if data.is_a?(Symbol)
114
- value = status_tag value if is_boolean? data, item
115
- value
116
- end
117
-
118
- def is_boolean?(data, item)
119
- if item.respond_to? :has_attribute?
120
- item.has_attribute?(data) &&
121
- item.column_for_attribute(data) &&
122
- item.column_for_attribute(data).type == :boolean
101
+ html = format_attribute(resource, col.data)
102
+ # Don't add the same Arbre twice, while still allowing format_attribute to call status_tag
103
+ current_arbre_element << html unless current_arbre_element.children.include? html
123
104
  end
124
105
  end
125
106
 
@@ -166,7 +147,7 @@ module ActiveAdmin
166
147
  if @options.has_key?(:class)
167
148
  html_classes << @options.delete(:class)
168
149
  elsif @title.present?
169
- html_classes << "col-#{@title.to_s.parameterize('_')}"
150
+ html_classes << "col-#{ActiveAdmin::Dependency.rails.parameterize(@title.to_s)}"
170
151
  end
171
152
  @html_class = html_classes.join(' ')
172
153
  @data = args[1] || args[0]
@@ -29,7 +29,7 @@ module ActiveAdmin
29
29
 
30
30
  def build(page_presenter, collection)
31
31
  @page_presenter = page_presenter
32
- @collection = collection
32
+ @collection = collection.to_a
33
33
  add_class "index"
34
34
  build_table
35
35
  end
@@ -47,7 +47,7 @@ module ActiveAdmin
47
47
  def build_table
48
48
  resource_selection_toggle_panel if active_admin_config.batch_actions.any?
49
49
  table class: "index_grid" do
50
- collection.in_groups_of(number_of_columns).each do |group|
50
+ @collection.in_groups_of(number_of_columns).each do |group|
51
51
  build_row(group)
52
52
  end
53
53
  end
@@ -52,6 +52,8 @@ module ActiveAdmin
52
52
  # end
53
53
  # ```
54
54
  #
55
+ # ## Defining Actions
56
+ #
55
57
  # To setup links to View, Edit and Delete a resource, use the `actions` method:
56
58
  #
57
59
  # ```ruby
@@ -108,6 +110,18 @@ module ActiveAdmin
108
110
  # end
109
111
  # ```
110
112
  #
113
+ # In addition, you can insert the position of the row in the greater collection by using the index_column special command:
114
+ #
115
+ # ```ruby
116
+ # index do
117
+ # selectable_column
118
+ # index_column
119
+ # column :title
120
+ # end
121
+ # ```
122
+ #
123
+ # index_column take an optional offset parameter to allow a developer to set the starting number for the index (default is 1).
124
+ #
111
125
  # ## Sorting
112
126
  #
113
127
  # When a column is generated from an Active Record attribute, the table is
@@ -218,7 +232,7 @@ module ActiveAdmin
218
232
  def default_table
219
233
  proc do
220
234
  selectable_column
221
- id_column if resource_class.primary_key # View based Models have no primary_key
235
+ id_column if resource_class.primary_key
222
236
  resource_class.content_columns.each do |col|
223
237
  column col.name.to_sym
224
238
  end
@@ -244,12 +258,20 @@ module ActiveAdmin
244
258
  end
245
259
  end
246
260
 
261
+ def index_column(start_value = 1)
262
+ column '#', class: 'col-index', sortable: false do |resource|
263
+ @collection.offset_value + @collection.index(resource) + start_value
264
+ end
265
+ end
266
+
247
267
  # Display a column for the id
248
268
  def id_column
249
- raise "#{resource_class.name} as no primary_key!" unless resource_class.primary_key
269
+ raise "#{resource_class.name} has no primary_key!" unless resource_class.primary_key
250
270
  column(resource_class.human_attribute_name(resource_class.primary_key), sortable: resource_class.primary_key) do |resource|
251
271
  if controller.action_methods.include?('show')
252
272
  link_to resource.id, resource_path(resource), class: "resource_id_link"
273
+ elsif controller.action_methods.include?('edit')
274
+ link_to resource.id, edit_resource_path(resource), class: "resource_id_link"
253
275
  else
254
276
  resource.id
255
277
  end
@@ -56,7 +56,7 @@ module ActiveAdmin
56
56
  end
57
57
 
58
58
  def build_unsupported_browser
59
- if active_admin_namespace.unsupported_browser_matcher =~ env["HTTP_USER_AGENT"]
59
+ if active_admin_namespace.unsupported_browser_matcher =~ request.user_agent
60
60
  insert_tag view_factory.unsupported_browser
61
61
  end
62
62
  end
@@ -5,8 +5,12 @@ module ActiveAdmin
5
5
  class Form < Base
6
6
 
7
7
  def title
8
- assigns[:page_title] || I18n.t("active_admin.#{normalized_action}_model",
9
- model: active_admin_config.resource_label)
8
+ if form_presenter[:title]
9
+ render_or_call_method_or_proc_on(resource, form_presenter[:title])
10
+ else
11
+ assigns[:page_title] || I18n.t("active_admin.#{normalized_action}_model",
12
+ model: active_admin_config.resource_label)
13
+ end
10
14
  end
11
15
 
12
16
  def form_presenter
@@ -47,7 +47,7 @@ module ActiveAdmin
47
47
  end
48
48
 
49
49
  def build_action_items
50
- insert_tag(view_factory.action_items, @action_items) if @action_items.any?
50
+ insert_tag(view_factory.action_items, @action_items)
51
51
  end
52
52
 
53
53
  end
@@ -1,7 +1,7 @@
1
1
  // SASS variable overrides must be declared before loading up Active Admin's styles.
2
2
  //
3
3
  // To view the variables that Active Admin provides, take a look at
4
- // `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the
4
+ // `app/assets/stylesheets/active_admin/mixins/_variables.scss` in the
5
5
  // Active Admin source.
6
6
  //
7
7
  // For example, to change the sidebar width: