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
@@ -0,0 +1,65 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
# Page is the primary data storage for page configuration in Active Admin
|
3
|
+
#
|
4
|
+
# When you register a page (ActiveAdmin.page "Status") you are actually creating
|
5
|
+
# a new Page instance within the given Namespace.
|
6
|
+
#
|
7
|
+
# The instance of the current page is available in PageController and views
|
8
|
+
# by calling the #active_admin_config method.
|
9
|
+
#
|
10
|
+
class Page
|
11
|
+
|
12
|
+
# The namespace this config belongs to
|
13
|
+
attr_reader :namespace
|
14
|
+
|
15
|
+
# The name of the page
|
16
|
+
attr_reader :name
|
17
|
+
|
18
|
+
module Base
|
19
|
+
def initialize(namespace, name, options)
|
20
|
+
@namespace = namespace
|
21
|
+
@name = name
|
22
|
+
@options = options
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
include Base
|
27
|
+
include Resource::Controllers
|
28
|
+
include Resource::PagePresenters
|
29
|
+
include Resource::Sidebars
|
30
|
+
include Resource::ActionItems
|
31
|
+
include Resource::Menu
|
32
|
+
include Resource::Naming
|
33
|
+
|
34
|
+
# plural_resource_name is singular
|
35
|
+
def resource_name
|
36
|
+
name
|
37
|
+
end
|
38
|
+
|
39
|
+
def safe_resource_name
|
40
|
+
name
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# Force plural to be singular
|
45
|
+
def plural_resource_name
|
46
|
+
name
|
47
|
+
end
|
48
|
+
|
49
|
+
# Force plural to be singular
|
50
|
+
def plural_safe_resource_name
|
51
|
+
name
|
52
|
+
end
|
53
|
+
|
54
|
+
def belongs_to?
|
55
|
+
false
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_default_action_items
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_default_sidebar_sections
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
|
3
|
+
# All Pages controllers inherit from this controller.
|
4
|
+
class PageController < BaseController
|
5
|
+
|
6
|
+
# Pages::Page subclasses Page::Base which implements the layout code
|
7
|
+
layout false
|
8
|
+
|
9
|
+
actions :index
|
10
|
+
|
11
|
+
def index(options={}, &block)
|
12
|
+
render "active_admin/page/index"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
# This is the class where all the register_page blocks are instance eval'd
|
3
|
+
class PageDSL < DSL
|
4
|
+
|
5
|
+
# Page content.
|
6
|
+
#
|
7
|
+
# The block should define the view using Arbre.
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
#
|
11
|
+
# ActiveAdmin.register "My Page" do
|
12
|
+
# content do
|
13
|
+
# para "Sweet!"
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
def content(options = {}, &block)
|
18
|
+
config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
|
3
|
+
# A simple object that gets used to present different aspects of views
|
4
|
+
#
|
5
|
+
# Initialize with a set of options and a block. The options become
|
6
|
+
# available using hash style syntax.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
#
|
10
|
+
# presenter = PagePresenter.new :as => :table do
|
11
|
+
# # some awesome stuff
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# presenter[:as] #=> :table
|
15
|
+
# presenter.block #=> The block passed in to new
|
16
|
+
#
|
17
|
+
class PagePresenter
|
18
|
+
|
19
|
+
attr_reader :block, :options
|
20
|
+
|
21
|
+
def initialize(options = {}, &block)
|
22
|
+
@options, @block = options, block
|
23
|
+
end
|
24
|
+
|
25
|
+
def [](key)
|
26
|
+
@options[key]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -1,63 +1,130 @@
|
|
1
1
|
module ActiveAdmin
|
2
2
|
|
3
|
-
|
3
|
+
module Reloader
|
4
4
|
|
5
|
-
#
|
6
|
-
|
7
|
-
|
5
|
+
# Builds the proper Reloader implementation class given the
|
6
|
+
# current version of Rails.
|
7
|
+
#
|
8
|
+
# @param [Rails::Application] rails_app The current rails application
|
9
|
+
# @param [ActiveAdmin::Application] active_admin_app The current Active Admin app
|
10
|
+
# @param [String] rails_version The version of Rails we're using.
|
11
|
+
#
|
12
|
+
# @returns A concrete subclass of AbstractReloader
|
13
|
+
def self.build(rails_app, active_admin_app, rails_version)
|
14
|
+
reloader_class = rails_version[0..2] == "3.2" ? Rails32Reloader : RailsLessThan31Reloader
|
15
|
+
reloader_class.new(rails_app, active_admin_app, rails_version)
|
8
16
|
end
|
9
17
|
|
10
|
-
|
18
|
+
class AbstractReloader
|
11
19
|
|
12
|
-
|
13
|
-
# development and once in production.
|
14
|
-
class Reloader
|
20
|
+
attr_reader :active_admin_app, :rails_app, :rails_version
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
def initialize(rails_app, active_admin_app, rails_version)
|
23
|
+
@rails_app = rails_app
|
24
|
+
@active_admin_app = active_admin_app
|
25
|
+
@rails_version = rails_version.to_s
|
26
|
+
end
|
19
27
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
def attach!
|
29
|
+
raise "Please implement #{self.class}#attach!"
|
30
|
+
end
|
31
|
+
|
32
|
+
def reload!
|
33
|
+
active_admin_app.unload!
|
34
|
+
rails_app.reload_routes!
|
35
|
+
end
|
36
|
+
|
37
|
+
def major_rails_version
|
38
|
+
@rails_version[0..2]
|
29
39
|
end
|
30
|
-
end
|
31
40
|
|
32
|
-
def reload!
|
33
|
-
active_admin_app.unload!
|
34
|
-
rails_app.reload_routes!
|
35
|
-
file_update_checker.paths.clear
|
36
|
-
watched_paths.each{|path| file_update_checker.paths << path }
|
37
41
|
end
|
38
42
|
|
39
|
-
#
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
# Reloads the application when using Rails 3.2
|
44
|
+
#
|
45
|
+
# 3.2 introduced a to_prepare block that only gets called when
|
46
|
+
# files have actually changed. ActiveAdmin had built this functionality
|
47
|
+
# in to speed up applications. So in Rails >= 3.2, we can now piggy
|
48
|
+
# back off the existing reloader. This simplifies our duties... which is
|
49
|
+
# nice.
|
50
|
+
class Rails32Reloader < AbstractReloader
|
51
|
+
|
52
|
+
# Attach to Rails and perform the reload on each request.
|
53
|
+
def attach!
|
54
|
+
active_admin_app.load_paths.each do |path|
|
55
|
+
rails_app.config.watchable_dirs[path] = [:rb]
|
56
|
+
end
|
43
57
|
|
44
|
-
|
45
|
-
|
58
|
+
reloader = self
|
59
|
+
|
60
|
+
ActionDispatch::Reloader.to_prepare do
|
61
|
+
reloader.reload!
|
62
|
+
end
|
46
63
|
end
|
47
|
-
end
|
48
64
|
|
49
|
-
def watched_paths
|
50
|
-
paths = active_admin_app.load_paths
|
51
|
-
active_admin_app.load_paths.each{|path| paths += Dir[File.join(path, "**", "*.rb")]}
|
52
|
-
paths
|
53
65
|
end
|
54
66
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
67
|
+
# Deals with reloading Active Admin on each request in
|
68
|
+
# development and once in production in Rails < 3.2.
|
69
|
+
class RailsLessThan31Reloader < AbstractReloader
|
70
|
+
|
71
|
+
class FileUpdateChecker < ::ActiveSupport::FileUpdateChecker
|
72
|
+
def paths
|
73
|
+
Rails.logger.info [@files, @paths].inspect
|
74
|
+
# hack to support both Rails 3.1 and 3.2
|
75
|
+
@files || @paths
|
76
|
+
end
|
77
|
+
|
78
|
+
# Over-ride the default #updated_at to support the deletion of files
|
79
|
+
def updated_at
|
80
|
+
paths.map { |path| File.mtime(path) rescue Time.now }.max
|
81
|
+
end
|
82
|
+
|
83
|
+
def execute_if_updated
|
84
|
+
super
|
85
|
+
end
|
60
86
|
end
|
87
|
+
|
88
|
+
attr_reader :file_update_checker
|
89
|
+
|
90
|
+
def initialize(rails_app, active_admin_app, rails_version)
|
91
|
+
super
|
92
|
+
@file_update_checker = FileUpdateChecker.new(watched_paths) do
|
93
|
+
reload!
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def reload!
|
98
|
+
super
|
99
|
+
file_update_checker.paths.clear
|
100
|
+
watched_paths.each{|path| file_update_checker.paths << path }
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
# Attach to Rails and perform the reload on each request.
|
105
|
+
def attach!
|
106
|
+
# Bring the checker into local scope for the ruby block
|
107
|
+
checker = file_update_checker
|
108
|
+
|
109
|
+
reloader_class.to_prepare do
|
110
|
+
checker.execute_if_updated
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def watched_paths
|
115
|
+
paths = active_admin_app.load_paths
|
116
|
+
active_admin_app.load_paths.each{|path| paths += Dir[File.join(path, "**", "*.rb")]}
|
117
|
+
paths
|
118
|
+
end
|
119
|
+
|
120
|
+
def reloader_class
|
121
|
+
if major_rails_version == "3.1"
|
122
|
+
ActionDispatch::Reloader
|
123
|
+
else
|
124
|
+
ActionDispatch::Callbacks
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
61
128
|
end
|
62
129
|
|
63
130
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'active_admin/resource/action_items'
|
2
|
+
require 'active_admin/resource/controllers'
|
2
3
|
require 'active_admin/resource/menu'
|
4
|
+
require 'active_admin/resource/page_presenters'
|
3
5
|
require 'active_admin/resource/naming'
|
4
6
|
require 'active_admin/resource/scopes'
|
5
7
|
require 'active_admin/resource/sidebars'
|
8
|
+
require 'active_admin/resource/belongs_to'
|
6
9
|
|
7
10
|
module ActiveAdmin
|
8
11
|
|
@@ -19,17 +22,11 @@ module ActiveAdmin
|
|
19
22
|
# Event dispatched when a new resource is registered
|
20
23
|
RegisterEvent = 'active_admin.resource.register'.freeze
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
# The namespace this resource belongs to
|
25
|
+
# The namespace this config belongs to
|
25
26
|
attr_reader :namespace
|
26
27
|
|
27
|
-
# The
|
28
|
-
|
29
|
-
attr_reader :resource
|
30
|
-
|
31
|
-
# A hash of page configurations for the controller indexed by action name
|
32
|
-
attr_reader :page_configs
|
28
|
+
# The name of the resource class
|
29
|
+
attr_reader :resource_class_name
|
33
30
|
|
34
31
|
# An array of member actions defined for this resource
|
35
32
|
attr_reader :member_actions
|
@@ -46,68 +43,55 @@ module ActiveAdmin
|
|
46
43
|
# If we're scoping resources, use this method on the parent to return the collection
|
47
44
|
attr_accessor :scope_to_association_method
|
48
45
|
|
49
|
-
# Set to false to turn off admin notes
|
50
|
-
attr_accessor :admin_notes
|
51
|
-
|
52
46
|
# Set the configuration for the CSV
|
53
47
|
attr_writer :csv_builder
|
54
48
|
|
55
49
|
module Base
|
56
|
-
def initialize(namespace,
|
50
|
+
def initialize(namespace, resource_class, options = {})
|
57
51
|
@namespace = namespace
|
58
|
-
@
|
52
|
+
@resource_class_name = "::#{resource_class.name}"
|
59
53
|
@options = default_options.merge(options)
|
60
54
|
@sort_order = @options[:sort_order]
|
61
|
-
@page_configs = {}
|
62
55
|
@member_actions, @collection_actions = [], []
|
63
56
|
end
|
64
57
|
end
|
65
58
|
|
66
59
|
include Base
|
60
|
+
include Controllers
|
61
|
+
include PagePresenters
|
67
62
|
include ActionItems
|
68
|
-
include Menu
|
69
63
|
include Naming
|
70
64
|
include Scopes
|
71
65
|
include Sidebars
|
66
|
+
include Menu
|
72
67
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
# Returns a properly formatted controller name for this
|
79
|
-
# resource within its namespace
|
80
|
-
def controller_name
|
81
|
-
[namespace.module_name, camelized_resource_name.pluralize + "Controller"].compact.join('::')
|
68
|
+
# The class this resource wraps. If you register the Post model, Resource#resource_class
|
69
|
+
# will point to the Post class
|
70
|
+
def resource_class
|
71
|
+
ActiveSupport::Dependencies.constantize(resource_class_name)
|
82
72
|
end
|
83
73
|
|
84
|
-
|
85
|
-
|
86
|
-
@controller ||= controller_name.constantize
|
74
|
+
def resource_table_name
|
75
|
+
resource_class.quoted_table_name
|
87
76
|
end
|
88
77
|
|
89
|
-
# Returns the
|
90
|
-
def
|
91
|
-
|
78
|
+
# Returns the named route for an instance of this resource
|
79
|
+
def route_instance_path
|
80
|
+
[route_prefix, controller.resources_configuration[:self][:route_instance_name], 'path'].compact.join('_').to_sym
|
92
81
|
end
|
93
82
|
|
94
83
|
# Returns a symbol for the route to use to get to the
|
95
84
|
# collection of this resource
|
96
85
|
def route_collection_path
|
97
|
-
route =
|
86
|
+
route = super
|
98
87
|
|
88
|
+
# Handle plural resources.
|
99
89
|
if controller.resources_configuration[:self][:route_collection_name] ==
|
100
|
-
|
101
|
-
route
|
90
|
+
controller.resources_configuration[:self][:route_instance_name]
|
91
|
+
route = route.to_s.gsub('_path', '_index_path').to_sym
|
102
92
|
end
|
103
93
|
|
104
|
-
route
|
105
|
-
route.compact.join('_').to_sym
|
106
|
-
end
|
107
|
-
|
108
|
-
# Returns the named route for an instance of this resource
|
109
|
-
def route_instance_path
|
110
|
-
[route_prefix, controller.resources_configuration[:self][:route_instance_name], 'path'].compact.join('_').to_sym
|
94
|
+
route
|
111
95
|
end
|
112
96
|
|
113
97
|
# Clears all the member actions this resource knows about
|
@@ -138,22 +122,32 @@ module ActiveAdmin
|
|
138
122
|
!belongs_to_config.nil?
|
139
123
|
end
|
140
124
|
|
125
|
+
def include_in_menu?
|
126
|
+
super && !(belongs_to? && !belongs_to_config.optional?)
|
127
|
+
end
|
128
|
+
|
141
129
|
# The csv builder for this resource
|
142
130
|
def csv_builder
|
143
131
|
@csv_builder || default_csv_builder
|
144
132
|
end
|
145
133
|
|
134
|
+
# @deprecated
|
135
|
+
def resource
|
136
|
+
resource_class
|
137
|
+
end
|
138
|
+
ActiveAdmin::Deprecation.deprecate self, :resource,
|
139
|
+
"ActiveAdmin::Resource#resource is deprecated. Please use #resource_class instead."
|
140
|
+
|
146
141
|
private
|
147
142
|
|
148
143
|
def default_options
|
149
144
|
{
|
150
|
-
:
|
151
|
-
:sort_order => "#{resource.respond_to?(:primary_key) ? resource.primary_key : 'id'}_desc"
|
145
|
+
:sort_order => "#{resource_class.respond_to?(:primary_key) ? resource_class.primary_key : 'id'}_desc"
|
152
146
|
}
|
153
147
|
end
|
154
148
|
|
155
149
|
def default_csv_builder
|
156
|
-
@default_csv_builder ||= CSVBuilder.default_for_resource(
|
150
|
+
@default_csv_builder ||= CSVBuilder.default_for_resource(resource_class)
|
157
151
|
end
|
158
152
|
end # class Resource
|
159
153
|
end # module ActiveAdmin
|