andrewroth_activeadmin 0.3.4 → 0.3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. data/CHANGELOG.md +159 -3
  2. data/CONTRIBUTING.md +113 -0
  3. data/LICENSE +1 -1
  4. data/README.rdoc +19 -20
  5. data/activeadmin.gemspec +3 -1
  6. data/app/assets/javascripts/active_admin/application.js +9 -0
  7. data/app/assets/javascripts/active_admin/base.js +4 -12
  8. data/app/assets/stylesheets/active_admin/_base.css.scss +16 -340
  9. data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -7
  10. data/app/assets/stylesheets/active_admin/_header.css.scss +23 -4
  11. data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
  12. data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
  13. data/app/assets/stylesheets/active_admin/components/_buttons.scss +12 -0
  14. data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +2 -0
  15. data/app/assets/stylesheets/active_admin/components/_grid.scss +9 -0
  16. data/app/assets/stylesheets/active_admin/components/_links.scss +5 -0
  17. data/app/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
  18. data/app/assets/stylesheets/active_admin/components/_panels.scss +6 -0
  19. data/app/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
  20. data/app/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
  21. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +101 -0
  22. data/app/assets/stylesheets/active_admin/mixins/_all.css.scss +2 -1
  23. data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +50 -13
  24. data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +9 -1
  25. data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +7 -5
  26. data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +1 -0
  27. data/app/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
  28. data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +1 -0
  29. data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
  30. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
  31. data/app/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
  32. data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
  33. data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
  34. data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
  35. data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
  36. data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
  37. data/app/views/active_admin/devise/shared/_links.erb +1 -1
  38. data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
  39. data/app/views/active_admin/page/index.html.arb +1 -0
  40. data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
  41. data/cucumber.yml +3 -2
  42. data/docs/1-general-configuration.md +46 -10
  43. data/docs/6-show-screens.md +7 -0
  44. data/docs/8-custom-actions.md +12 -2
  45. data/docs/9-custom-pages.md +84 -0
  46. data/features/belongs_to.feature +27 -0
  47. data/features/comments/commenting.feature +3 -2
  48. data/features/dashboard.feature +18 -0
  49. data/features/development_reloading.feature +19 -0
  50. data/features/index/filter_with_check_boxes.feature +25 -0
  51. data/features/index/index_as_table.feature +14 -0
  52. data/features/index/index_scopes.feature +42 -0
  53. data/features/index/pagination.feature +19 -1
  54. data/features/menu.feature +22 -2
  55. data/features/registering_assets.feature +2 -2
  56. data/features/registering_pages.feature +66 -0
  57. data/features/specifying_actions.feature +5 -0
  58. data/features/step_definitions/action_item_steps.rb +2 -6
  59. data/features/step_definitions/action_link_steps.rb +7 -0
  60. data/features/step_definitions/additional_web_steps.rb +8 -0
  61. data/features/step_definitions/asset_steps.rb +5 -1
  62. data/features/step_definitions/breadcrumb_steps.rb +5 -0
  63. data/features/step_definitions/configuration_steps.rb +56 -8
  64. data/features/step_definitions/dashboard_steps.rb +5 -1
  65. data/features/step_definitions/factory_steps.rb +9 -2
  66. data/features/step_definitions/flash_steps.rb +9 -1
  67. data/features/step_definitions/index_scope_steps.rb +16 -4
  68. data/features/step_definitions/member_link_steps.rb +7 -0
  69. data/features/step_definitions/site_title_steps.rb +15 -0
  70. data/features/support/paths.rb +6 -0
  71. data/features/users/logging_out.feature +11 -0
  72. data/lib/active_admin.rb +25 -10
  73. data/lib/active_admin/application.rb +63 -20
  74. data/lib/active_admin/arbre/html/element.rb +10 -0
  75. data/lib/active_admin/asset_registration.rb +15 -2
  76. data/lib/active_admin/base_controller.rb +61 -0
  77. data/lib/active_admin/{resource_controller → base_controller}/menu.rb +1 -1
  78. data/lib/active_admin/comments.rb +48 -54
  79. data/lib/active_admin/comments/comment.rb +13 -2
  80. data/lib/active_admin/comments/namespace_helper.rb +1 -1
  81. data/lib/active_admin/comments/views/active_admin_comments.rb +7 -3
  82. data/lib/active_admin/dashboards.rb +4 -0
  83. data/lib/active_admin/dashboards/dashboard_controller.rb +20 -4
  84. data/lib/active_admin/dsl.rb +6 -159
  85. data/lib/active_admin/event.rb +5 -3
  86. data/lib/active_admin/filter_form_builder.rb +53 -0
  87. data/lib/active_admin/form_builder.rb +25 -19
  88. data/lib/active_admin/inputs.rb +14 -0
  89. data/lib/active_admin/inputs/datepicker_input.rb +11 -0
  90. data/lib/active_admin/inputs/filter_base.rb +46 -0
  91. data/lib/active_admin/inputs/filter_check_boxes_input.rb +40 -0
  92. data/lib/active_admin/inputs/filter_date_range_input.rb +34 -0
  93. data/lib/active_admin/inputs/filter_numeric_input.rb +55 -0
  94. data/lib/active_admin/inputs/filter_select_input.rb +23 -0
  95. data/lib/active_admin/inputs/filter_string_input.rb +22 -0
  96. data/lib/active_admin/locales/ca.yml +44 -0
  97. data/lib/active_admin/locales/cs.yml +14 -10
  98. data/lib/active_admin/locales/de.yml +43 -0
  99. data/lib/active_admin/locales/en.yml +5 -0
  100. data/lib/active_admin/locales/hr.yml +40 -0
  101. data/lib/active_admin/locales/ko.yml +40 -0
  102. data/lib/active_admin/locales/lv.yml +43 -0
  103. data/lib/active_admin/locales/nl.yml +40 -0
  104. data/lib/active_admin/locales/no-NB.yml +40 -0
  105. data/lib/active_admin/locales/pl.yml +7 -1
  106. data/lib/active_admin/locales/pt-BR.yml +6 -2
  107. data/lib/active_admin/namespace.rb +48 -33
  108. data/lib/active_admin/page.rb +54 -0
  109. data/lib/active_admin/page_controller.rb +15 -0
  110. data/lib/active_admin/page_dsl.rb +21 -0
  111. data/lib/active_admin/page_presenter.rb +30 -0
  112. data/lib/active_admin/resource.rb +38 -44
  113. data/lib/active_admin/resource/action_items.rb +5 -0
  114. data/lib/active_admin/resource/belongs_to.rb +4 -2
  115. data/lib/active_admin/resource/controllers.rb +35 -0
  116. data/lib/active_admin/resource/menu.rb +1 -2
  117. data/lib/active_admin/resource/naming.rb +43 -31
  118. data/lib/active_admin/resource/page_presenters.rb +28 -0
  119. data/lib/active_admin/resource/scopes.rb +16 -3
  120. data/lib/active_admin/resource/sidebars.rb +4 -0
  121. data/lib/active_admin/resource_collection.rb +88 -0
  122. data/lib/active_admin/resource_controller.rb +18 -54
  123. data/lib/active_admin/resource_controller/action_builder.rb +1 -1
  124. data/lib/active_admin/resource_controller/actions.rb +1 -1
  125. data/lib/active_admin/resource_controller/callbacks.rb +1 -1
  126. data/lib/active_admin/resource_controller/collection.rb +8 -4
  127. data/lib/active_admin/resource_controller/filters.rb +1 -1
  128. data/lib/active_admin/resource_controller/resource_class_methods.rb +24 -0
  129. data/lib/active_admin/resource_controller/scoping.rb +1 -1
  130. data/lib/active_admin/resource_controller/sidebars.rb +1 -1
  131. data/lib/active_admin/resource_dsl.rb +157 -0
  132. data/lib/active_admin/router.rb +21 -14
  133. data/lib/active_admin/scope.rb +15 -3
  134. data/lib/active_admin/version.rb +1 -1
  135. data/lib/active_admin/view_factory.rb +4 -3
  136. data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -10
  137. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +25 -21
  138. data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -150
  139. data/lib/active_admin/views/components/attributes_table.rb +1 -1
  140. data/lib/active_admin/views/components/paginated_collection.rb +42 -13
  141. data/lib/active_admin/views/components/scopes.rb +17 -17
  142. data/lib/active_admin/views/components/status_tag.rb +6 -5
  143. data/lib/active_admin/views/components/table_for.rb +6 -2
  144. data/lib/active_admin/views/header_renderer.rb +31 -12
  145. data/lib/active_admin/views/index_as_block.rb +2 -2
  146. data/lib/active_admin/views/index_as_blog.rb +3 -3
  147. data/lib/active_admin/views/index_as_grid.rb +4 -4
  148. data/lib/active_admin/views/index_as_table.rb +13 -6
  149. data/lib/active_admin/views/pages/base.rb +4 -4
  150. data/lib/active_admin/views/pages/form.rb +49 -0
  151. data/lib/active_admin/views/pages/index.rb +18 -6
  152. data/lib/active_admin/views/pages/page.rb +24 -0
  153. data/lib/active_admin/views/pages/show.rb +1 -1
  154. data/lib/generators/active_admin/assets/assets_generator.rb +19 -1
  155. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +38 -12
  156. data/lib/generators/active_admin/install/templates/dashboards.rb +6 -0
  157. data/spec/spec_helper.rb +4 -0
  158. data/spec/support/rails_template.rb +11 -0
  159. data/spec/support/templates/cucumber_with_reloading.rb +5 -0
  160. data/spec/unit/active_admin_spec.rb +8 -0
  161. data/spec/unit/application_spec.rb +48 -2
  162. data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
  163. data/spec/unit/asset_registration_spec.rb +9 -3
  164. data/spec/unit/auto_link_spec.rb +2 -2
  165. data/spec/unit/base_controller_shared_examples.rb +28 -0
  166. data/spec/unit/base_controller_spec.rb +8 -0
  167. data/spec/unit/belongs_to_spec.rb +30 -33
  168. data/spec/unit/comments_spec.rb +45 -15
  169. data/spec/unit/config_shared_examples.rb +108 -0
  170. data/spec/unit/dashboard_controller_spec.rb +44 -0
  171. data/spec/unit/event_spec.rb +6 -0
  172. data/spec/unit/filter_form_builder_spec.rb +9 -0
  173. data/spec/unit/form_builder_spec.rb +8 -14
  174. data/spec/unit/namespace/register_page_spec.rb +102 -0
  175. data/spec/unit/namespace/register_resource_spec.rb +188 -0
  176. data/spec/unit/namespace_spec.rb +11 -183
  177. data/spec/unit/page_controller_spec.rb +8 -0
  178. data/spec/unit/page_spec.rb +60 -0
  179. data/spec/unit/resource/menu_spec.rb +1 -51
  180. data/spec/unit/resource/naming_spec.rb +24 -19
  181. data/spec/unit/resource/page_presenters_spec.rb +32 -0
  182. data/spec/unit/resource/scopes_spec.rb +13 -0
  183. data/spec/unit/resource_collection_spec.rb +101 -0
  184. data/spec/unit/resource_controller_spec.rb +40 -32
  185. data/spec/unit/{registration_spec.rb → resource_registration_spec.rb} +0 -0
  186. data/spec/unit/resource_spec.rb +8 -24
  187. data/spec/unit/routing_spec.rb +50 -1
  188. data/spec/unit/scope_spec.rb +18 -4
  189. data/spec/unit/views/components/paginated_collection_spec.rb +150 -0
  190. data/spec/unit/views/components/status_tag_spec.rb +9 -0
  191. data/tasks/test.rake +43 -27
  192. metadata +140 -31
  193. data/app/assets/javascripts/active_admin/vendor.js +0 -382
  194. data/lib/active_admin/comments/configuration.rb +0 -18
  195. data/lib/active_admin/page_config.rb +0 -15
  196. data/lib/active_admin/resource_controller/form.rb +0 -42
  197. data/lib/active_admin/resource_controller/page_configurations.rb +0 -53
  198. data/lib/active_admin/views/pages/edit.rb +0 -28
  199. data/lib/active_admin/views/pages/new.rb +0 -28
  200. data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +0 -427
  201. data/spec/integration/belongs_to_spec.rb +0 -42
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
- class ResourceController < ::InheritedResources::Base
2
+ class BaseController < ::InheritedResources::Base
3
3
  module Menu
4
4
  extend ActiveSupport::Concern
5
5
 
@@ -1,4 +1,3 @@
1
- require 'active_admin/comments/configuration'
2
1
  require 'active_admin/comments/comment'
3
2
  require 'active_admin/comments/views'
4
3
  require 'active_admin/comments/show_page_helper'
@@ -6,7 +5,7 @@ require 'active_admin/comments/namespace_helper'
6
5
  require 'active_admin/comments/resource_helper'
7
6
 
8
7
  # Add the comments configuration
9
- ActiveAdmin::Application.send :include, ActiveAdmin::Comments::Configuration
8
+ ActiveAdmin::Application.inheritable_setting :allow_comments, true
10
9
 
11
10
  # Add the comments module to ActiveAdmin::Namespace
12
11
  ActiveAdmin::Namespace.send :include, ActiveAdmin::Comments::NamespaceHelper
@@ -18,71 +17,66 @@ ActiveAdmin::Resource.send :include, ActiveAdmin::Comments::ResourceHelper
18
17
  ActiveAdmin.application.view_factory.show_page.send :include, ActiveAdmin::Comments::ShowPageHelper
19
18
 
20
19
  # Generate a Comment resource when namespaces are registered
21
- ActiveAdmin::Event.subscribe ActiveAdmin::Namespace::RegisterEvent do |namespace|
22
- if namespace.comments?
23
- namespace.register ActiveAdmin::Comment, :as => 'Comment' do
24
- actions :index, :show, :create
20
+ ActiveAdmin::Event.subscribe ActiveAdmin::Application::LoadEvent do |app|
21
+ app.namespaces.values.each do |namespace|
22
+ if namespace.comments?
23
+ namespace.register ActiveAdmin::Comment, :as => 'Comment' do
24
+ actions :index, :show, :create
25
25
 
26
- # Don't display in the menu
27
- menu false
26
+ # Don't display in the menu
27
+ menu false
28
28
 
29
- # Don't allow comments on comments
30
- config.comments = false
29
+ # Don't allow comments on comments
30
+ config.comments = false
31
31
 
32
- # Filter Comments by date
33
- filter :resource_type
34
- filter :body
35
- filter :created_at
32
+ # Filter Comments by date
33
+ filter :resource_type
34
+ filter :body
35
+ filter :created_at
36
36
 
37
- # Only view comments in this namespace
38
- scope :all, :default => true do |comments|
39
- comments.where(:namespace => active_admin_config.namespace.name.to_s)
40
- end
37
+ # Only view comments in this namespace
38
+ scope :all, :default => true do |comments|
39
+ comments.where(:namespace => active_admin_config.namespace.name.to_s)
40
+ end
41
41
 
42
- # Always redirect to the resource on show
43
- before_filter :only => :show do
44
- flash[:notice] = flash[:notice].dup if flash[:notice]
45
- comment = ActiveAdmin::Comment.find(params[:id])
46
- resource_config = active_admin_config.namespace.resource_for(comment.resource.class)
47
- redirect_to send(resource_config.route_instance_path, comment.resource)
48
- end
42
+ # Always redirect to the resource on show
43
+ before_filter :only => :show do
44
+ flash[:notice] = flash[:notice].dup if flash[:notice]
45
+ comment = ActiveAdmin::Comment.find(params[:id])
46
+ resource_config = active_admin_config.namespace.resource_for(comment.resource.class)
47
+ redirect_to send(resource_config.route_instance_path, comment.resource)
48
+ end
49
49
 
50
- # Store the author and namespace
51
- before_save do |comment|
52
- comment.namespace = active_admin_config.namespace.name
53
- comment.author = current_active_admin_user
54
- end
50
+ # Store the author and namespace
51
+ before_save do |comment|
52
+ comment.namespace = active_admin_config.namespace.name
53
+ comment.author = current_active_admin_user
54
+ end
55
55
 
56
- # Redirect to the resource show page when failing to add a comment
57
- # TODO: Provide helpers to make such kind of customization much simpler
58
- controller do
59
- def create
60
- create! do |success, failure|
61
- failure.html do
62
- resource_config = active_admin_config.namespace.resource_for(@comment.resource.class)
63
- flash[:error] = "Comment wasn't saved, text was empty."
64
- redirect_to send(resource_config.route_instance_path, @comment.resource)
56
+ # Redirect to the resource show page when failing to add a comment
57
+ # TODO: Provide helpers to make such kind of customization much simpler
58
+ controller do
59
+ def create
60
+ create! do |success, failure|
61
+ failure.html do
62
+ resource_config = active_admin_config.namespace.resource_for(@comment.resource.class)
63
+ flash[:error] = "Comment wasn't saved, text was empty."
64
+ redirect_to send(resource_config.route_instance_path, @comment.resource)
65
+ end
65
66
  end
66
67
  end
67
68
  end
68
- end
69
-
70
69
 
71
- # Display as a table
72
- index do
73
- column("Resource"){|comment| auto_link(comment.resource) }
74
- column("Author"){|comment| auto_link(comment.author) }
75
- column :body
70
+ # Display as a table
71
+ index do
72
+ column("Resource"){|comment| auto_link(comment.resource) }
73
+ column("Author"){|comment| auto_link(comment.author) }
74
+ column :body
75
+ end
76
76
  end
77
77
  end
78
78
  end
79
79
  end
80
80
 
81
- # Register for comments when new resources are registered
82
- ActiveAdmin::Event.subscribe ActiveAdmin::Resource::RegisterEvent do |resource|
83
- if resource.comments?
84
- resource.resource.has_many :active_admin_comments, :class_name => "ActiveAdmin::Comment",
85
- :as => :resource,
86
- :dependent => :destroy
87
- end
88
- end
81
+ # @deprecated #allow_comments_on - Remove in 0.5.0
82
+ ActiveAdmin::Application.deprecated_setting :allow_comments_in, [], 'The "allow_comments_in = []" setting is deprecated and will be remove by Active Admin 0.5.0. Please use "allow_comments = true|false" instead.'
@@ -11,10 +11,21 @@ module ActiveAdmin
11
11
  belongs_to :resource, :polymorphic => true
12
12
  belongs_to :author, :polymorphic => true
13
13
 
14
- validates_presence_of :resource_id
15
- validates_presence_of :resource_type
14
+ validates_presence_of :resource
16
15
  validates_presence_of :body
17
16
  validates_presence_of :namespace
17
+
18
+ # @returns [String] The name of the record to use for the polymorphic relationship
19
+ def self.resource_type(record)
20
+ record.class.base_class.name.to_s
21
+ end
22
+
23
+ def self.find_for_resource_in_namespace(resource, namespace)
24
+ where(:resource_type => resource_type(resource),
25
+ :resource_id => resource.id,
26
+ :namespace => namespace.to_s)
27
+ end
28
+
18
29
  end
19
30
 
20
31
  end
@@ -5,7 +5,7 @@ module ActiveAdmin
5
5
 
6
6
  # Returns true of the namespace allows comments
7
7
  def comments?
8
- application.allow_comments_in && application.allow_comments_in.include?(name)
8
+ allow_comments == true
9
9
  end
10
10
 
11
11
  end
@@ -21,7 +21,7 @@ module ActiveAdmin
21
21
  end
22
22
 
23
23
  def record_comments
24
- @record_comments ||= @record.active_admin_comments.where(:namespace => active_admin_namespace.name.to_s)
24
+ @record_comments ||= ActiveAdmin::Comment.find_for_resource_in_namespace(@record, active_admin_namespace.name)
25
25
  end
26
26
 
27
27
  def build_comments
@@ -56,13 +56,17 @@ module ActiveAdmin
56
56
  end
57
57
 
58
58
  def comment_form_url
59
- send(:"#{active_admin_namespace.name}_comments_path")
59
+ if active_admin_namespace.root?
60
+ comments_path
61
+ else
62
+ send(:"#{active_admin_namespace.name}_comments_path")
63
+ end
60
64
  end
61
65
 
62
66
  def build_comment_form
63
67
  self << active_admin_form_for(ActiveAdmin::Comment.new, :url => comment_form_url, :html => {:class => "inline_form"}) do |form|
64
68
  form.inputs do
65
- form.input :resource_type, :value => @record.class.base_class.name.to_s, :as => :hidden
69
+ form.input :resource_type, :value => ActiveAdmin::Comment.resource_type(@record), :as => :hidden
66
70
  form.input :resource_id, :value => @record.id, :as => :hidden
67
71
  form.input :body, :input_html => {:size => "80x8"}, :label => false
68
72
  end
@@ -26,6 +26,10 @@ module ActiveAdmin
26
26
 
27
27
  # Add a new dashboard section to a namespace. If no namespace is given
28
28
  # it will be added to the default namespace.
29
+ #
30
+ # Options include:
31
+ # :namespace => only display for specified namespace.
32
+ # :if => specify a method or block to determine whether the section is rendered at run time.
29
33
  def add_section(name, options = {}, &block)
30
34
  namespace = options.delete(:namespace) || ActiveAdmin.application.default_namespace || :root
31
35
  self.sections[namespace] ||= []
@@ -9,16 +9,28 @@ module ActiveAdmin
9
9
  render 'active_admin/dashboard/index.html.arb'
10
10
  end
11
11
 
12
- protected
12
+ private
13
13
 
14
14
  def set_current_tab
15
15
  @current_tab = I18n.t("active_admin.dashboard")
16
16
  end
17
17
 
18
18
  def find_sections
19
- ActiveAdmin::Dashboards.sections_for_namespace(namespace)
19
+ sections = ActiveAdmin::Dashboards.sections_for_namespace(namespace)
20
+ sections.select do |section|
21
+ if section.options.has_key?(:if)
22
+ symbol_or_proc = section.options[:if]
23
+ case symbol_or_proc
24
+ when Symbol, String then self.send(symbol_or_proc)
25
+ when Proc then instance_exec(&symbol_or_proc)
26
+ else symbol_or_proc
27
+ end
28
+ else
29
+ true
30
+ end
31
+ end
20
32
  end
21
-
33
+
22
34
  def namespace
23
35
  class_name = self.class.name
24
36
  if class_name.include?('::')
@@ -30,7 +42,11 @@ module ActiveAdmin
30
42
 
31
43
  # Return the current menu for the view. This is a helper method
32
44
  def current_menu
33
- ActiveAdmin.application.namespaces[namespace].menu
45
+ active_admin_namespace.menu
46
+ end
47
+
48
+ def active_admin_namespace
49
+ ActiveAdmin.application.namespace(namespace)
34
50
  end
35
51
 
36
52
  end
@@ -15,14 +15,14 @@ module ActiveAdmin
15
15
 
16
16
  private
17
17
 
18
- # The instance of ActiveAdmin::Resource that's being registered
18
+ # The instance of ActiveAdmin::Config that's being registered
19
19
  # currently. You can use this within your registration blocks to
20
20
  # modify options:
21
21
  #
22
22
  # eg:
23
- #
23
+ #
24
24
  # ActiveAdmin.register Post do
25
- # config.admin_notes = false
25
+ # config.sort_order = "id_desc"
26
26
  # end
27
27
  #
28
28
  def config
@@ -33,7 +33,7 @@ module ActiveAdmin
33
33
  # block, it will be eval'd in the controller
34
34
  #
35
35
  # Example:
36
- #
36
+ #
37
37
  # ActiveAdmin.register Post do
38
38
  #
39
39
  # controller do
@@ -49,51 +49,6 @@ module ActiveAdmin
49
49
  @config.controller
50
50
  end
51
51
 
52
- def belongs_to(target, options = {})
53
- config.belongs_to(target, options)
54
- end
55
-
56
- def menu(options = {})
57
- config.menu(options)
58
- end
59
-
60
- # Scope this controller to some object which has a relation
61
- # to the resource. Can either accept a block or a symbol
62
- # of a method to call.
63
- #
64
- # Eg:
65
- #
66
- # ActiveAdmin.register Post do
67
- # scope_to :current_user
68
- # end
69
- #
70
- # Then every time we instantiate and object, it would call
71
- #
72
- # current_user.posts.build
73
- #
74
- # By default Active Admin will use the resource name to build a
75
- # method to call as the association. If its different, you can
76
- # pass in the association_method as an option.
77
- #
78
- # scope_to :current_user, :association_method => :blog_posts
79
- #
80
- # will result in the following
81
- #
82
- # current_user.blog_posts.build
83
- #
84
- def scope_to(*args, &block)
85
- options = args.extract_options!
86
- method = args.first
87
-
88
- config.scope_to = block_given? ? block : method
89
- config.scope_to_association_method = options[:association_method]
90
- end
91
-
92
- # Create a scope
93
- def scope(*args, &block)
94
- config.scope(*args, &block)
95
- end
96
-
97
52
  # Add a new action item to the resource
98
53
  #
99
54
  # @param [Hash] options valid keys include:
@@ -105,120 +60,12 @@ module ActiveAdmin
105
60
  config.add_action_item(options, &block)
106
61
  end
107
62
 
108
- # Configure the index page for the resource
109
- def index(options = {}, &block)
110
- options[:as] ||= :table
111
- controller.set_page_config :index, options, &block
112
- end
113
-
114
- # Configure the show page for the resource
115
- def show(options = {}, &block)
116
- # TODO: controller.set_page_config just sets page_configs on the Resource (config) obj
117
- controller.set_page_config :show, options, &block
118
- end
119
-
120
- def form(options = {}, &block)
121
- options[:block] = block
122
- controller.form_config = options
63
+ def menu(options = {})
64
+ config.menu(options)
123
65
  end
124
66
 
125
67
  def sidebar(name, options = {}, &block)
126
68
  config.sidebar_sections << ActiveAdmin::SidebarSection.new(name, options, &block)
127
69
  end
128
-
129
- # Configure the CSV format
130
- #
131
- # For example:
132
- #
133
- # csv do
134
- # column :name
135
- # column("Author") { |post| post.author.full_name }
136
- # end
137
- #
138
- def csv(&block)
139
- config.csv_builder = CSVBuilder.new(&block)
140
- end
141
-
142
- # Member Actions give you the functionality of defining both the
143
- # action and the route directly from your ActiveAdmin registration
144
- # block.
145
- #
146
- # For example:
147
- #
148
- # ActiveAdmin.register Post do
149
- # member_action :comments do
150
- # @post = Post.find(params[:id]
151
- # @comments = @post.comments
152
- # end
153
- # end
154
- #
155
- # Will create a new controller action comments and will hook it up to
156
- # the named route (comments_admin_post_path) /admin/posts/:id/comments
157
- #
158
- # You can treat everything within the block as a standard Rails controller
159
- # action.
160
- #
161
- def member_action(name, options = {}, &block)
162
- config.member_actions << ControllerAction.new(name, options)
163
- controller do
164
- define_method(name, &block || Proc.new{})
165
- end
166
- end
167
-
168
- def collection_action(name, options = {}, &block)
169
- config.collection_actions << ControllerAction.new(name, options)
170
- controller do
171
- define_method(name, &block || Proc.new{})
172
- end
173
- end
174
-
175
- # Defined Callbacks
176
- #
177
- # == After Build
178
- # Called after the resource is built in the new and create actions.
179
- #
180
- # ActiveAdmin.register Post do
181
- # after_build do |post|
182
- # post.author = current_user
183
- # end
184
- # end
185
- #
186
- # == Before / After Create
187
- # Called before and after a resource is saved to the db on the create action.
188
- #
189
- # == Before / After Update
190
- # Called before and after a resource is saved to the db on the update action.
191
- #
192
- # == Before / After Save
193
- # Called before and after the object is saved in the create and update action.
194
- # Note: Gets called after the create and update callbacks
195
- #
196
- # == Before / After Destroy
197
- # Called before and after the object is destroyed from the database.
198
- #
199
- delegate :before_build, :after_build, :to => :controller
200
- delegate :before_create, :after_create, :to => :controller
201
- delegate :before_update, :after_update, :to => :controller
202
- delegate :before_save, :after_save, :to => :controller
203
- delegate :before_destroy, :after_destroy, :to => :controller
204
-
205
- # Filters
206
- delegate :filter, :to => :controller
207
-
208
-
209
- # Standard rails filters
210
- delegate :before_filter, :skip_before_filter, :after_filter, :around_filter, :to => :controller
211
-
212
- # Specify which actions to create in the controller
213
- #
214
- # Eg:
215
- #
216
- # ActiveAdmin.register Post do
217
- # actions :index, :show
218
- # end
219
- #
220
- # Will only create the index and show actions (no create, update or delete)
221
- delegate :actions, :to => :controller
222
-
223
70
  end
224
71
  end