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.
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +164 -5
- data/CONTRIBUTING.md +113 -0
- data/Gemfile +7 -9
- data/LICENSE +1 -1
- data/README.rdoc +19 -20
- data/activeadmin.gemspec +4 -2
- data/app/assets/javascripts/active_admin/application.js +9 -0
- data/app/assets/javascripts/active_admin/base.js +4 -12
- data/app/assets/stylesheets/active_admin/_base.css.scss +17 -341
- data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -7
- data/app/assets/stylesheets/active_admin/_header.css.scss +23 -4
- data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
- data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
- data/app/assets/stylesheets/active_admin/components/_buttons.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +2 -0
- data/app/assets/stylesheets/active_admin/components/_grid.scss +9 -0
- data/app/assets/stylesheets/active_admin/components/_links.scss +5 -0
- data/app/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
- data/app/assets/stylesheets/active_admin/components/_panels.scss +6 -0
- data/app/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
- data/app/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +101 -0
- data/app/assets/stylesheets/active_admin/components/_tables.css.scss +43 -2
- data/app/assets/stylesheets/active_admin/mixins/_all.css.scss +2 -1
- data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +50 -13
- data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +9 -1
- data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +7 -5
- data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
- data/app/assets/stylesheets/active_admin/mixins/_utilities.scss +9 -0
- data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
- data/app/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
- data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
- data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
- data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
- data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
- data/app/views/active_admin/devise/shared/_links.erb +1 -1
- data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
- data/app/views/active_admin/page/index.html.arb +1 -0
- data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
- data/cucumber.yml +3 -2
- data/docs/1-general-configuration.md +46 -10
- data/docs/6-show-screens.md +7 -0
- data/docs/8-custom-actions.md +12 -2
- data/docs/9-custom-pages.md +84 -0
- data/features/belongs_to.feature +27 -0
- data/features/comments/commenting.feature +3 -2
- data/features/dashboard.feature +18 -0
- data/features/development_reloading.feature +43 -0
- data/features/index/filter_with_check_boxes.feature +25 -0
- data/features/index/index_as_table.feature +14 -0
- data/features/index/index_scopes.feature +59 -0
- data/features/index/pagination.feature +19 -1
- data/features/menu.feature +22 -2
- data/features/registering_assets.feature +2 -2
- data/features/registering_pages.feature +66 -0
- data/features/specifying_actions.feature +5 -0
- data/features/step_definitions/action_item_steps.rb +2 -6
- data/features/step_definitions/action_link_steps.rb +7 -0
- data/features/step_definitions/additional_web_steps.rb +11 -3
- data/features/step_definitions/asset_steps.rb +5 -1
- data/features/step_definitions/breadcrumb_steps.rb +5 -0
- data/features/step_definitions/comment_steps.rb +3 -3
- data/features/step_definitions/configuration_steps.rb +69 -13
- data/features/step_definitions/dashboard_steps.rb +7 -3
- data/features/step_definitions/factory_steps.rb +9 -2
- data/features/step_definitions/flash_steps.rb +9 -1
- data/features/step_definitions/format_steps.rb +9 -1
- data/features/step_definitions/index_scope_steps.rb +18 -6
- data/features/step_definitions/member_link_steps.rb +7 -0
- data/features/step_definitions/pagination_steps.rb +2 -2
- data/features/step_definitions/site_title_steps.rb +15 -0
- data/features/step_definitions/tab_steps.rb +1 -1
- data/features/step_definitions/user_steps.rb +1 -1
- data/features/step_definitions/web_steps.rb +4 -4
- data/features/support/paths.rb +6 -0
- data/features/users/logging_out.feature +11 -0
- data/lib/active_admin.rb +26 -10
- data/lib/active_admin/application.rb +64 -22
- data/lib/active_admin/arbre.rb +0 -1
- data/lib/active_admin/arbre/builder.rb +8 -5
- data/lib/active_admin/arbre/context.rb +1 -1
- data/lib/active_admin/arbre/html/attributes.rb +1 -1
- data/lib/active_admin/arbre/html/class_list.rb +0 -4
- data/lib/active_admin/arbre/html/collection.rb +2 -2
- data/lib/active_admin/arbre/html/document.rb +1 -1
- data/lib/active_admin/arbre/html/element.rb +19 -9
- data/lib/active_admin/arbre/html/tag.rb +3 -3
- data/lib/active_admin/arbre/html/text_node.rb +2 -2
- data/lib/active_admin/asset_registration.rb +15 -2
- data/lib/active_admin/base_controller.rb +61 -0
- data/lib/active_admin/{resource_controller → base_controller}/menu.rb +1 -1
- data/lib/active_admin/callbacks.rb +16 -18
- data/lib/active_admin/comments.rb +48 -54
- data/lib/active_admin/comments/comment.rb +13 -2
- data/lib/active_admin/comments/namespace_helper.rb +1 -1
- data/lib/active_admin/comments/views/active_admin_comments.rb +7 -3
- data/lib/active_admin/dashboards.rb +4 -0
- data/lib/active_admin/dashboards/dashboard_controller.rb +21 -5
- data/lib/active_admin/dsl.rb +6 -159
- data/lib/active_admin/event.rb +5 -3
- data/lib/active_admin/filter_form_builder.rb +53 -0
- data/lib/active_admin/form_builder.rb +25 -19
- data/lib/active_admin/helpers/settings.rb +6 -10
- data/lib/active_admin/inputs.rb +14 -0
- data/lib/active_admin/inputs/datepicker_input.rb +11 -0
- data/lib/active_admin/inputs/filter_base.rb +46 -0
- data/lib/active_admin/inputs/filter_check_boxes_input.rb +40 -0
- data/lib/active_admin/inputs/filter_date_range_input.rb +34 -0
- data/lib/active_admin/inputs/filter_numeric_input.rb +55 -0
- data/lib/active_admin/inputs/filter_select_input.rb +23 -0
- data/lib/active_admin/inputs/filter_string_input.rb +22 -0
- data/lib/active_admin/locales/ca.yml +44 -0
- data/lib/active_admin/locales/cs.yml +14 -10
- data/lib/active_admin/locales/de.yml +44 -0
- data/lib/active_admin/locales/en.yml +5 -0
- data/lib/active_admin/locales/hr.yml +40 -0
- data/lib/active_admin/locales/hu.yml +45 -0
- data/lib/active_admin/locales/it.yml +11 -6
- data/lib/active_admin/locales/ko.yml +40 -0
- data/lib/active_admin/locales/lv.yml +43 -0
- data/lib/active_admin/locales/nl.yml +40 -0
- data/lib/active_admin/locales/no-NB.yml +40 -0
- data/lib/active_admin/locales/pl.yml +7 -1
- data/lib/active_admin/locales/pt-BR.yml +6 -2
- data/lib/active_admin/menu_item.rb +25 -17
- data/lib/active_admin/namespace.rb +48 -33
- data/lib/active_admin/page.rb +65 -0
- data/lib/active_admin/page_controller.rb +15 -0
- data/lib/active_admin/page_dsl.rb +21 -0
- data/lib/active_admin/page_presenter.rb +30 -0
- data/lib/active_admin/reloader.rb +109 -42
- data/lib/active_admin/resource.rb +38 -44
- data/lib/active_admin/resource/action_items.rb +5 -0
- data/lib/active_admin/resource/belongs_to.rb +4 -2
- data/lib/active_admin/resource/controllers.rb +35 -0
- data/lib/active_admin/resource/menu.rb +1 -2
- data/lib/active_admin/resource/naming.rb +53 -31
- data/lib/active_admin/resource/page_presenters.rb +28 -0
- data/lib/active_admin/resource/scopes.rb +16 -3
- data/lib/active_admin/resource/sidebars.rb +4 -0
- data/lib/active_admin/resource_collection.rb +88 -0
- data/lib/active_admin/resource_controller.rb +18 -54
- data/lib/active_admin/resource_controller/action_builder.rb +1 -1
- data/lib/active_admin/resource_controller/actions.rb +8 -8
- data/lib/active_admin/resource_controller/callbacks.rb +1 -1
- data/lib/active_admin/resource_controller/collection.rb +8 -4
- data/lib/active_admin/resource_controller/filters.rb +1 -1
- data/lib/active_admin/resource_controller/resource_class_methods.rb +24 -0
- data/lib/active_admin/resource_controller/scoping.rb +1 -1
- data/lib/active_admin/resource_controller/sidebars.rb +1 -1
- data/lib/active_admin/resource_dsl.rb +157 -0
- data/lib/active_admin/router.rb +21 -14
- data/lib/active_admin/scope.rb +15 -3
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +4 -3
- data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -10
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +25 -21
- data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -150
- data/lib/active_admin/views/components/attributes_table.rb +1 -1
- data/lib/active_admin/views/components/columns.rb +4 -4
- data/lib/active_admin/views/components/paginated_collection.rb +42 -13
- data/lib/active_admin/views/components/panel.rb +8 -0
- data/lib/active_admin/views/components/scopes.rb +24 -18
- data/lib/active_admin/views/components/status_tag.rb +6 -5
- data/lib/active_admin/views/components/table_for.rb +6 -2
- data/lib/active_admin/views/header_renderer.rb +31 -12
- data/lib/active_admin/views/index_as_block.rb +2 -2
- data/lib/active_admin/views/index_as_blog.rb +3 -3
- data/lib/active_admin/views/index_as_grid.rb +4 -4
- data/lib/active_admin/views/index_as_table.rb +13 -6
- data/lib/active_admin/views/pages/base.rb +4 -4
- data/lib/active_admin/views/pages/form.rb +49 -0
- data/lib/active_admin/views/pages/index.rb +18 -6
- data/lib/active_admin/views/pages/page.rb +24 -0
- data/lib/active_admin/views/pages/show.rb +1 -1
- data/lib/generators/active_admin/assets/assets_generator.rb +19 -1
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +38 -12
- data/lib/generators/active_admin/install/templates/dashboards.rb +6 -0
- data/script/use_rails +14 -7
- data/spec/spec_helper.rb +9 -14
- data/spec/spec_helper_without_rails.rb +10 -0
- data/spec/support/detect_rails_version.rb +22 -3
- data/spec/support/integration_example_group.rb +5 -7
- data/spec/support/rails_template.rb +11 -0
- data/spec/support/rails_template_with_data.rb +25 -0
- data/spec/support/templates/cucumber_with_reloading.rb +5 -0
- data/spec/unit/active_admin_spec.rb +8 -0
- data/spec/unit/application_spec.rb +48 -2
- data/spec/unit/arbre/context_spec.rb +1 -1
- data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
- data/spec/unit/arbre/html/element_spec.rb +18 -5
- data/spec/unit/arbre/html/tag_attributes_spec.rb +3 -3
- data/spec/unit/arbre/html/tag_spec.rb +1 -1
- data/spec/unit/arbre/html_spec.rb +32 -22
- data/spec/unit/asset_registration_spec.rb +9 -3
- data/spec/unit/auto_link_spec.rb +2 -2
- data/spec/unit/base_controller_shared_examples.rb +28 -0
- data/spec/unit/base_controller_spec.rb +8 -0
- data/spec/unit/belongs_to_spec.rb +30 -33
- data/spec/unit/comments_spec.rb +45 -15
- data/spec/unit/config_shared_examples.rb +119 -0
- data/spec/unit/dashboard_controller_spec.rb +44 -0
- data/spec/unit/event_spec.rb +6 -0
- data/spec/unit/filter_form_builder_spec.rb +9 -0
- data/spec/unit/form_builder_spec.rb +8 -14
- data/spec/unit/menu_item_spec.rb +25 -20
- data/spec/unit/namespace/register_page_spec.rb +102 -0
- data/spec/unit/namespace/register_resource_spec.rb +188 -0
- data/spec/unit/namespace_spec.rb +11 -183
- data/spec/unit/page_controller_spec.rb +8 -0
- data/spec/unit/page_spec.rb +60 -0
- data/spec/unit/reloader_spec.rb +82 -38
- data/spec/unit/resource/menu_spec.rb +1 -51
- data/spec/unit/resource/naming_spec.rb +25 -20
- data/spec/unit/resource/page_presenters_spec.rb +32 -0
- data/spec/unit/resource/scopes_spec.rb +13 -0
- data/spec/unit/resource_collection_spec.rb +101 -0
- data/spec/unit/resource_controller_spec.rb +40 -32
- data/spec/unit/{registration_spec.rb → resource_registration_spec.rb} +0 -0
- data/spec/unit/resource_spec.rb +8 -24
- data/spec/unit/routing_spec.rb +50 -1
- data/spec/unit/scope_spec.rb +18 -4
- data/spec/unit/views/components/paginated_collection_spec.rb +163 -0
- data/spec/unit/views/components/panel_spec.rb +9 -0
- data/spec/unit/views/components/status_tag_spec.rb +9 -0
- data/spec/unit/views/tabbed_navigation_spec.rb +2 -1
- data/tasks/test.rake +44 -26
- metadata +176 -69
- data/app/assets/javascripts/active_admin/vendor.js +0 -382
- data/lib/active_admin/arbre/core_extensions.rb +0 -5
- data/lib/active_admin/comments/configuration.rb +0 -18
- data/lib/active_admin/page_config.rb +0 -15
- data/lib/active_admin/resource_controller/form.rb +0 -42
- data/lib/active_admin/resource_controller/page_configurations.rb +0 -53
- data/lib/active_admin/views/pages/edit.rb +0 -28
- data/lib/active_admin/views/pages/new.rb +0 -28
- data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +0 -427
- data/spec/integration/belongs_to_spec.rb +0 -42
@@ -1,5 +1,5 @@
|
|
1
1
|
module ActiveAdmin
|
2
|
-
class ResourceController <
|
2
|
+
class ResourceController < BaseController
|
3
3
|
|
4
4
|
# Override the InheritedResources actions to use the
|
5
5
|
# Active Admin templates.
|
@@ -10,11 +10,11 @@ module ActiveAdmin
|
|
10
10
|
def index(options={}, &block)
|
11
11
|
super(options) do |format|
|
12
12
|
block.call(format) if block
|
13
|
-
format.html { render active_admin_template('index
|
13
|
+
format.html { render active_admin_template('index') }
|
14
14
|
format.csv do
|
15
15
|
headers['Content-Type'] = 'text/csv; charset=utf-8'
|
16
16
|
headers['Content-Disposition'] = %{attachment; filename="#{csv_filename}"}
|
17
|
-
render active_admin_template('index
|
17
|
+
render active_admin_template('index')
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -23,7 +23,7 @@ module ActiveAdmin
|
|
23
23
|
def show(options={}, &block)
|
24
24
|
super do |format|
|
25
25
|
block.call(format) if block
|
26
|
-
format.html { render active_admin_template('show
|
26
|
+
format.html { render active_admin_template('show') }
|
27
27
|
end
|
28
28
|
end
|
29
29
|
alias :show! :show
|
@@ -31,7 +31,7 @@ module ActiveAdmin
|
|
31
31
|
def new(options={}, &block)
|
32
32
|
super do |format|
|
33
33
|
block.call(format) if block
|
34
|
-
format.html { render active_admin_template('new
|
34
|
+
format.html { render active_admin_template('new') }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
alias :new! :new
|
@@ -39,7 +39,7 @@ module ActiveAdmin
|
|
39
39
|
def edit(options={}, &block)
|
40
40
|
super do |format|
|
41
41
|
block.call(format) if block
|
42
|
-
format.html { render active_admin_template('edit
|
42
|
+
format.html { render active_admin_template('edit') }
|
43
43
|
end
|
44
44
|
end
|
45
45
|
alias :edit! :edit
|
@@ -47,7 +47,7 @@ module ActiveAdmin
|
|
47
47
|
def create(options={}, &block)
|
48
48
|
super(options) do |success, failure|
|
49
49
|
block.call(success, failure) if block
|
50
|
-
failure.html { render active_admin_template('new
|
50
|
+
failure.html { render active_admin_template('new') }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
alias :create! :create
|
@@ -55,7 +55,7 @@ module ActiveAdmin
|
|
55
55
|
def update(options={}, &block)
|
56
56
|
super do |success, failure|
|
57
57
|
block.call(success, failure) if block
|
58
|
-
failure.html { render active_admin_template('edit
|
58
|
+
failure.html { render active_admin_template('edit') }
|
59
59
|
end
|
60
60
|
end
|
61
61
|
alias :update! :update
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module ActiveAdmin
|
2
|
-
class ResourceController <
|
2
|
+
class ResourceController < BaseController
|
3
3
|
|
4
4
|
# This module deals with the retrieval of collections for resources
|
5
5
|
# within the resource controller.
|
@@ -46,9 +46,13 @@ module ActiveAdmin
|
|
46
46
|
|
47
47
|
def sort_order(chain)
|
48
48
|
params[:order] ||= active_admin_config.sort_order
|
49
|
-
table_name = active_admin_config.resource_table_name
|
50
49
|
if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
|
51
|
-
|
50
|
+
column = $1
|
51
|
+
order = $2
|
52
|
+
table = active_admin_config.resource_table_name
|
53
|
+
table_column = (column =~ /\./) ? column : "#{table}.#{column}"
|
54
|
+
|
55
|
+
chain.order("#{table_column} #{order}")
|
52
56
|
else
|
53
57
|
chain # just return the chain
|
54
58
|
end
|
@@ -120,7 +124,7 @@ module ActiveAdmin
|
|
120
124
|
end
|
121
125
|
|
122
126
|
def paginate(chain)
|
123
|
-
chain.
|
127
|
+
chain.send(Kaminari.config.page_method_name, params[:page]).per(@per_page || active_admin_namespace.default_per_page)
|
124
128
|
end
|
125
129
|
end
|
126
130
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
class ResourceController < BaseController
|
3
|
+
module ResourceClassMethods
|
4
|
+
|
5
|
+
# Override the default resource_class class and instance
|
6
|
+
# methods to only return the class defined in the instance
|
7
|
+
# of ActiveAdmin::Resource
|
8
|
+
def override_resource_class_methods!
|
9
|
+
self.class_eval do
|
10
|
+
def self.resource_class=(klass); end
|
11
|
+
|
12
|
+
def self.resource_class
|
13
|
+
@active_admin_config ? @active_admin_config.resource_class : nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def resource_class
|
17
|
+
self.class.resource_class
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
# This is the class where all the register blocks are instance eval'd
|
3
|
+
class ResourceDSL < DSL
|
4
|
+
private
|
5
|
+
|
6
|
+
def belongs_to(target, options = {})
|
7
|
+
config.belongs_to(target, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Scope this controller to some object which has a relation
|
11
|
+
# to the resource. Can either accept a block or a symbol
|
12
|
+
# of a method to call.
|
13
|
+
#
|
14
|
+
# Eg:
|
15
|
+
#
|
16
|
+
# ActiveAdmin.register Post do
|
17
|
+
# scope_to :current_user
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# Then every time we instantiate and object, it would call
|
21
|
+
#
|
22
|
+
# current_user.posts.build
|
23
|
+
#
|
24
|
+
# By default Active Admin will use the resource name to build a
|
25
|
+
# method to call as the association. If its different, you can
|
26
|
+
# pass in the association_method as an option.
|
27
|
+
#
|
28
|
+
# scope_to :current_user, :association_method => :blog_posts
|
29
|
+
#
|
30
|
+
# will result in the following
|
31
|
+
#
|
32
|
+
# current_user.blog_posts.build
|
33
|
+
#
|
34
|
+
def scope_to(*args, &block)
|
35
|
+
options = args.extract_options!
|
36
|
+
method = args.first
|
37
|
+
|
38
|
+
config.scope_to = block_given? ? block : method
|
39
|
+
config.scope_to_association_method = options[:association_method]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Create a scope
|
43
|
+
def scope(*args, &block)
|
44
|
+
config.scope(*args, &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Configure the index page for the resource
|
48
|
+
def index(options = {}, &block)
|
49
|
+
options[:as] ||= :table
|
50
|
+
config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Configure the show page for the resource
|
54
|
+
def show(options = {}, &block)
|
55
|
+
config.set_page_presenter :show, ActiveAdmin::PagePresenter.new(options, &block)
|
56
|
+
end
|
57
|
+
|
58
|
+
def form(options = {}, &block)
|
59
|
+
config.set_page_presenter :form, ActiveAdmin::PagePresenter.new(options, &block)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Configure the CSV format
|
63
|
+
#
|
64
|
+
# For example:
|
65
|
+
#
|
66
|
+
# csv do
|
67
|
+
# column :name
|
68
|
+
# column("Author") { |post| post.author.full_name }
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
def csv(&block)
|
72
|
+
config.csv_builder = CSVBuilder.new(&block)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Member Actions give you the functionality of defining both the
|
76
|
+
# action and the route directly from your ActiveAdmin registration
|
77
|
+
# block.
|
78
|
+
#
|
79
|
+
# For example:
|
80
|
+
#
|
81
|
+
# ActiveAdmin.register Post do
|
82
|
+
# member_action :comments do
|
83
|
+
# @post = Post.find(params[:id]
|
84
|
+
# @comments = @post.comments
|
85
|
+
# end
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
# Will create a new controller action comments and will hook it up to
|
89
|
+
# the named route (comments_admin_post_path) /admin/posts/:id/comments
|
90
|
+
#
|
91
|
+
# You can treat everything within the block as a standard Rails controller
|
92
|
+
# action.
|
93
|
+
#
|
94
|
+
def member_action(name, options = {}, &block)
|
95
|
+
config.member_actions << ControllerAction.new(name, options)
|
96
|
+
controller do
|
97
|
+
define_method(name, &block || Proc.new{})
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def collection_action(name, options = {}, &block)
|
102
|
+
config.collection_actions << ControllerAction.new(name, options)
|
103
|
+
controller do
|
104
|
+
define_method(name, &block || Proc.new{})
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Defined Callbacks
|
109
|
+
#
|
110
|
+
# == After Build
|
111
|
+
# Called after the resource is built in the new and create actions.
|
112
|
+
#
|
113
|
+
# ActiveAdmin.register Post do
|
114
|
+
# after_build do |post|
|
115
|
+
# post.author = current_user
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
# == Before / After Create
|
120
|
+
# Called before and after a resource is saved to the db on the create action.
|
121
|
+
#
|
122
|
+
# == Before / After Update
|
123
|
+
# Called before and after a resource is saved to the db on the update action.
|
124
|
+
#
|
125
|
+
# == Before / After Save
|
126
|
+
# Called before and after the object is saved in the create and update action.
|
127
|
+
# Note: Gets called after the create and update callbacks
|
128
|
+
#
|
129
|
+
# == Before / After Destroy
|
130
|
+
# Called before and after the object is destroyed from the database.
|
131
|
+
#
|
132
|
+
delegate :before_build, :after_build, :to => :controller
|
133
|
+
delegate :before_create, :after_create, :to => :controller
|
134
|
+
delegate :before_update, :after_update, :to => :controller
|
135
|
+
delegate :before_save, :after_save, :to => :controller
|
136
|
+
delegate :before_destroy, :after_destroy, :to => :controller
|
137
|
+
|
138
|
+
# Filters
|
139
|
+
delegate :filter, :to => :controller
|
140
|
+
|
141
|
+
|
142
|
+
# Standard rails filters
|
143
|
+
delegate :before_filter, :skip_before_filter, :after_filter, :around_filter, :to => :controller
|
144
|
+
|
145
|
+
# Specify which actions to create in the controller
|
146
|
+
#
|
147
|
+
# Eg:
|
148
|
+
#
|
149
|
+
# ActiveAdmin.register Post do
|
150
|
+
# actions :index, :show
|
151
|
+
# end
|
152
|
+
#
|
153
|
+
# Will only create the index and show actions (no create, update or delete)
|
154
|
+
delegate :actions, :to => :controller
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
data/lib/active_admin/router.rb
CHANGED
@@ -28,27 +28,33 @@ module ActiveAdmin
|
|
28
28
|
|
29
29
|
# Now define the routes for each resource
|
30
30
|
router.instance_exec(@application.namespaces) do |namespaces|
|
31
|
-
resources = namespaces.values.collect{|n| n.resources.
|
31
|
+
resources = namespaces.values.collect{|n| n.resources.resources }.flatten
|
32
32
|
resources.each do |config|
|
33
33
|
|
34
34
|
# Define the block the will get eval'd within the namespace
|
35
35
|
route_definition_block = Proc.new do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
case config
|
37
|
+
when Resource
|
38
|
+
resources config.underscored_resource_name.pluralize do
|
39
|
+
# Define any member actions
|
40
|
+
member do
|
41
|
+
config.member_actions.each do |action|
|
42
|
+
# eg: get :comment
|
43
|
+
send(action.http_verb, action.name)
|
44
|
+
end
|
43
45
|
end
|
44
|
-
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
# Define any collection actions
|
48
|
+
collection do
|
49
|
+
config.collection_actions.each do |action|
|
50
|
+
send(action.http_verb, action.name)
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
54
|
+
when Page
|
55
|
+
match "/#{config.underscored_resource_name}" => "#{config.underscored_resource_name}#index"
|
56
|
+
else
|
57
|
+
raise "Unsupported config class: #{config.class}"
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|
@@ -60,7 +66,8 @@ module ActiveAdmin
|
|
60
66
|
instance_eval &routes_for_belongs_to if config.belongs_to_config.optional?
|
61
67
|
|
62
68
|
# Make the nested belongs_to routes
|
63
|
-
|
69
|
+
# :only is set to nothing so that we don't clobber any existing routes on the resource
|
70
|
+
resources config.belongs_to_config.target.underscored_resource_name.pluralize, :only => [] do
|
64
71
|
instance_eval &routes_for_belongs_to
|
65
72
|
end
|
66
73
|
end
|
data/lib/active_admin/scope.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActiveAdmin
|
2
2
|
class Scope
|
3
3
|
|
4
|
-
attr_reader :name, :scope_method, :id, :scope_block
|
4
|
+
attr_reader :name, :scope_method, :id, :scope_block, :display_if_block
|
5
5
|
|
6
6
|
# Create a Scope
|
7
7
|
#
|
@@ -13,11 +13,14 @@ 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
|
18
|
+
#
|
16
19
|
# Scope.new('Published') { |articles| articles.where(:published => true) }
|
17
20
|
# # => Scope with name 'Published' using a block to scope
|
18
21
|
#
|
19
|
-
def initialize(name, method = nil, &block)
|
20
|
-
@name = name.to_s.titleize
|
22
|
+
def initialize(name, method = nil, options = {}, &block)
|
23
|
+
@name = name.is_a?( String ) ? name : name.to_s.titleize
|
21
24
|
@scope_method = method
|
22
25
|
# Scope ':all' means no scoping
|
23
26
|
@scope_method ||= name.to_sym unless name.to_sym == :all
|
@@ -26,6 +29,15 @@ module ActiveAdmin
|
|
26
29
|
@scope_method = nil
|
27
30
|
@scope_block = block
|
28
31
|
end
|
32
|
+
|
33
|
+
@display_if_block = options[:if]
|
29
34
|
end
|
35
|
+
|
36
|
+
# Returns the display if block. If the block was not explicitly defined
|
37
|
+
# a default block always returning true will be returned.
|
38
|
+
def display_if_block
|
39
|
+
@display_if_block || proc{ true }
|
40
|
+
end
|
41
|
+
|
30
42
|
end
|
31
43
|
end
|
data/lib/active_admin/version.rb
CHANGED
@@ -15,9 +15,10 @@ module ActiveAdmin
|
|
15
15
|
register :dashboard_page => ActiveAdmin::Views::Pages::Dashboard,
|
16
16
|
:index_page => ActiveAdmin::Views::Pages::Index,
|
17
17
|
:show_page => ActiveAdmin::Views::Pages::Show,
|
18
|
-
:new_page => ActiveAdmin::Views::Pages::
|
19
|
-
:edit_page => ActiveAdmin::Views::Pages::
|
20
|
-
:layout => ActiveAdmin::Views::Pages::Layout
|
18
|
+
:new_page => ActiveAdmin::Views::Pages::Form,
|
19
|
+
:edit_page => ActiveAdmin::Views::Pages::Form,
|
20
|
+
:layout => ActiveAdmin::Views::Pages::Layout,
|
21
|
+
:page => ActiveAdmin::Views::Pages::Page
|
21
22
|
|
22
23
|
end
|
23
24
|
end
|
@@ -24,19 +24,10 @@ module ActiveAdmin
|
|
24
24
|
|
25
25
|
# Returns the ActiveAdmin::Resource instance for a class
|
26
26
|
def active_admin_resource_for(klass)
|
27
|
+
return nil unless respond_to?(:active_admin_namespace)
|
27
28
|
active_admin_namespace.resource_for(klass)
|
28
29
|
end
|
29
30
|
|
30
|
-
# Returns the current Active Admin namespace
|
31
|
-
def active_admin_namespace
|
32
|
-
if respond_to?(:active_admin_config) && active_admin_config
|
33
|
-
active_admin_config.namespace
|
34
|
-
else
|
35
|
-
# Return a default namespace if none exists
|
36
|
-
active_admin_application.find_or_create_namespace(active_admin_application.default_namespace)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
31
|
end
|
41
32
|
end
|
42
33
|
end
|