activeadmin 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -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 :
|
|
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
|
|
@@ -21,7 +21,7 @@ module ActiveAdmin
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def record_comments
|
|
24
|
-
@record_comments ||= @record
|
|
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
|
-
|
|
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
|
|
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] ||= []
|
|
@@ -6,19 +6,31 @@ module ActiveAdmin
|
|
|
6
6
|
|
|
7
7
|
def index
|
|
8
8
|
@dashboard_sections = find_sections
|
|
9
|
-
render 'active_admin/dashboard/index
|
|
9
|
+
render 'active_admin/dashboard/index'
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
|
|
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
|
-
|
|
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
|
data/lib/active_admin/dsl.rb
CHANGED
|
@@ -15,14 +15,14 @@ module ActiveAdmin
|
|
|
15
15
|
|
|
16
16
|
private
|
|
17
17
|
|
|
18
|
-
# The instance of ActiveAdmin::
|
|
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.
|
|
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
|
-
|
|
109
|
-
|
|
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
|
data/lib/active_admin/event.rb
CHANGED
|
@@ -9,9 +9,11 @@ module ActiveAdmin
|
|
|
9
9
|
@events = {}
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def subscribe(
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
def subscribe(*event_names, &block)
|
|
13
|
+
event_names.each do |event|
|
|
14
|
+
@events[event] ||= []
|
|
15
|
+
@events[event] << block
|
|
16
|
+
end
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def subscribers(event)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module ActiveAdmin
|
|
2
|
+
# This form builder defines methods to build filter forms such
|
|
3
|
+
# as the one found in the sidebar of the index page of a standard resource.
|
|
4
|
+
class FilterFormBuilder < FormBuilder
|
|
5
|
+
|
|
6
|
+
def filter(method, options = {})
|
|
7
|
+
return "" if method.nil? || method == ""
|
|
8
|
+
options[:as] ||= default_input_type(method)
|
|
9
|
+
return "" unless options[:as]
|
|
10
|
+
content = input(method, options)
|
|
11
|
+
form_buffers.last << content.html_safe if content
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
protected
|
|
15
|
+
|
|
16
|
+
# Returns the default filter type for a given attribute
|
|
17
|
+
def default_input_type(method, options = {})
|
|
18
|
+
if column = column_for(method)
|
|
19
|
+
case column.type
|
|
20
|
+
when :date, :datetime
|
|
21
|
+
return :date_range
|
|
22
|
+
when :string, :text
|
|
23
|
+
return :string
|
|
24
|
+
when :integer
|
|
25
|
+
return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
|
|
26
|
+
return :numeric
|
|
27
|
+
when :float, :decimal
|
|
28
|
+
return :numeric
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if reflection = reflection_for(method)
|
|
33
|
+
return :select if reflection.macro == :belongs_to && !reflection.options[:polymorphic]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def custom_input_class_name(as)
|
|
38
|
+
"ActiveAdmin::Inputs::Filter#{as.to_s.camelize}Input"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Returns the column for an attribute on the object being searched
|
|
42
|
+
# if it exists. Otherwise returns nil
|
|
43
|
+
def column_for(method)
|
|
44
|
+
@object.base.columns_hash[method.to_s] if @object.base.respond_to?(:columns_hash)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Returns the association reflection for the method if it exists
|
|
48
|
+
def reflection_for(method)
|
|
49
|
+
@object.base.reflect_on_association(method) if @object.base.respond_to?(:reflect_on_association)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
require 'formtastic'
|
|
2
|
-
|
|
3
1
|
module ActiveAdmin
|
|
4
|
-
class FormBuilder < ::Formtastic::
|
|
2
|
+
class FormBuilder < ::Formtastic::FormBuilder
|
|
5
3
|
|
|
6
4
|
attr_reader :form_buffers
|
|
7
5
|
|
|
@@ -21,8 +19,6 @@ module ActiveAdmin
|
|
|
21
19
|
# its contents, so we want to skip the internal buffering
|
|
22
20
|
# while building up its contents
|
|
23
21
|
def input(method, *args)
|
|
24
|
-
return if polymorphic_belongs_to_association?(method)
|
|
25
|
-
|
|
26
22
|
content = with_new_form_buffer { super }
|
|
27
23
|
return content.html_safe unless @inputs_with_block
|
|
28
24
|
form_buffers.last << content.html_safe
|
|
@@ -52,14 +48,6 @@ module ActiveAdmin
|
|
|
52
48
|
content << cancel_link
|
|
53
49
|
end
|
|
54
50
|
|
|
55
|
-
def datepicker_input(method, options)
|
|
56
|
-
options = options.dup
|
|
57
|
-
options[:input_html] ||= {}
|
|
58
|
-
options[:input_html][:class] = [options[:input_html][:class], "datepicker"].compact.join(' ')
|
|
59
|
-
options[:input_html][:size] ||= "10"
|
|
60
|
-
string_input(method, options)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
51
|
def has_many(association, options = {}, &block)
|
|
64
52
|
options = { :for => association }.merge(options)
|
|
65
53
|
options[:class] ||= ""
|
|
@@ -98,15 +86,33 @@ module ActiveAdmin
|
|
|
98
86
|
form_buffers.last << content.html_safe
|
|
99
87
|
end
|
|
100
88
|
|
|
101
|
-
|
|
89
|
+
protected
|
|
102
90
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
reflection = reflection_for(method)
|
|
106
|
-
|
|
107
|
-
reflection && reflection.macro == :belongs_to && reflection.options[:polymorphic]
|
|
91
|
+
def active_admin_input_class_name(as)
|
|
92
|
+
"ActiveAdmin::Inputs::#{as.to_s.camelize}Input"
|
|
108
93
|
end
|
|
109
94
|
|
|
95
|
+
def input_class(as)
|
|
96
|
+
@input_classes_cache ||= {}
|
|
97
|
+
@input_classes_cache[as] ||= begin
|
|
98
|
+
begin
|
|
99
|
+
begin
|
|
100
|
+
custom_input_class_name(as).constantize
|
|
101
|
+
rescue NameError
|
|
102
|
+
begin
|
|
103
|
+
active_admin_input_class_name(as).constantize
|
|
104
|
+
rescue NameError
|
|
105
|
+
standard_input_class_name(as).constantize
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
rescue NameError
|
|
109
|
+
raise Formtastic::UnknownInputError
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
private
|
|
115
|
+
|
|
110
116
|
def with_new_form_buffer
|
|
111
117
|
form_buffers << "".html_safe
|
|
112
118
|
return_value = yield
|