Permalink
Browse files

More on config reset, refs #275, #289, #515

  • Loading branch information...
1 parent 42aba16 commit d86ea760b30c19f142ba9e0680428dfbb069b6c1 @kaapa kaapa committed Jul 11, 2011
@@ -67,7 +67,7 @@ def self.create_history_item(message, object, abstract_model, user)
# Fetch the history items for a model. Returns an array containing
# the page count and an AR query result containing the history
# items.
- def self.history_for_model(model, query, sort, sort_reverse, all, page, per_page = RailsAdmin::Config::Sections::List.default_items_per_page || 20)
+ def self.history_for_model(model, query, sort, sort_reverse, all, page, per_page = RailsAdmin::Config.default_items_per_page || 20)
page ||= "1"
history = History.where :table => model.pretty_name
View
@@ -45,6 +45,38 @@ class AuthenticationNotConfigured < StandardError; end
end
class << self
+ # Configuration option to specify which models you want to exclude.
+ attr_accessor :excluded_models
+
+ # Configuration option to specify a whitelist of models you want to RailsAdmin to work with.
+ # The excluded_models list applies against the whitelist as well and further reduces the models
+ # RailsAdmin will use.
+ # If included_models is left empty ([]), then RailsAdmin will automatically use all the models
+ # in your application (less any excluded_models you may have specified).
+ attr_accessor :included_models
+
+ # Fields to be hidden in edit (create and update) views
+ attr_accessor :default_hidden_fields_for_edit
+
+ # Fields to be hidden in export views
+ attr_accessor :default_hidden_fields_for_export
+
+ # Default items per page value used if a model level option has not
+ # been configured
+ attr_accessor :default_items_per_page
+
+ attr_reader :default_search_operator
+
+ # Configuration option to specify which method names will be searched for
+ # to be used as a label for object records. This defaults to [:name, :title]
+ attr_accessor :label_methods
+
+ # Stores model configuration objects in a hash identified by model's class
+ # name.
+ #
+ # @see RailsAdmin::Config.model
+ attr_reader :registry
+
# Setup authentication to be run as a before filter
# This is run inside the controller instance so you can setup any authentication you need to
#
@@ -143,22 +175,6 @@ def current_user_method(&block)
@current_user || DEFAULT_CURRENT_USER
end
- # Configuration option to specify which models you want to exclude.
- attr_accessor :excluded_models
-
- # Configuration option to specify a whitelist of models you want to RailsAdmin to work with.
- # The excluded_models list applies against the whitelist as well and further reduces the models
- # RailsAdmin will use.
- # If included_models is left empty ([]), then RailsAdmin will automatically use all the models
- # in your application (less any excluded_models you may have specified).
- attr_accessor :included_models
-
- # Default items per page value used if a model level option has not
- # been configured
- attr_accessor :default_items_per_page
-
- attr_reader :default_search_operator
-
def default_search_operator=(operator)
if %w{ default like starts_with ends_with is = }.include? operator
@default_search_operator = operator
@@ -167,29 +183,20 @@ def default_search_operator=(operator)
end
end
- # Configuration option to specify which method names will be searched for
- # to be used as a label for object records. This defaults to [:name, :title]
- attr_accessor :label_methods
-
- # Stores model configuration objects in a hash identified by model's class
- # name.
- #
- # @see RailsAdmin::Config.model
- attr_reader :registry
-
# Shortcut to access the list section's class configuration
# within a config DSL block
#
# @see RailsAdmin::Config::Sections::List
def list
+ ActiveSupport::Deprecation.warn("RailsAdmin::Config.list is deprecated", caller)
RailsAdmin::Config::Sections::List
end
# Loads a model configuration instance from the registry or registers
# a new one if one is yet to be added.
#
- # First argument can be an instance of requested model, it's class object,
- # it's class name as a string or symbol or a RailsAdmin::AbstractModel
+ # First argument can be an instance of requested model, its class object,
+ # its class name as a string or symbol or a RailsAdmin::AbstractModel
# instance.
#
# If a block is given it is evaluated in the context of configuration instance.
@@ -229,6 +236,7 @@ def models(&block)
#
# @see RailsAdmin::Config::Sections::Navigation
def navigation
+ ActiveSupport::Deprecation.warn("RailsAdmin::Config.navigation is deprecated", caller)
RailsAdmin::Config::Sections::Navigation
end
@@ -239,6 +247,8 @@ def reset
@authenticate = nil
@authorize = nil
@current_user = nil
+ @default_hidden_fields_for_edit = [:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on]
+ @default_hidden_fields_for_export = []
@default_items_per_page = 20
@default_search_operator = 'default'
@excluded_models = []
@@ -7,14 +7,24 @@ module Sections
# Configuration of the navigation view
class Export < RailsAdmin::Config::Base
include RailsAdmin::Config::HasFields
- cattr_accessor :default_hidden_fields
- @@default_hidden_fields = []
+
+ def self.default_hidden_fields
+ ActiveSupport::Deprecation.warn("'#{self.name}.default_hidden_fields' is deprecated, use 'RailsAdmin::Config.default_hidden_fields_for_export' instead", caller)
+ RailsAdmin::Config.default_hidden_fields_for_export
+ end
+
+ def self.default_hidden_fields=(value)
+ ActiveSupport::Deprecation.warn("'#{self.name}.default_hidden_fields=' is deprecated, use 'RailsAdmin.config{|c| c.default_hidden_fields_for_export = #{value}}' instead", caller)
+ RailsAdmin.config do |config|
+ config.default_hidden_fields_for_export = value
+ end
+ end
def initialize(parent)
super(parent)
@fields = RailsAdmin::Config::Fields.factory(self)
@fields.each do |f|
- if @@default_hidden_fields.include?(f.name)
+ if RailsAdmin::Config.default_hidden_fields_for_export.include?(f.name)
f.hide
end
end
@@ -13,10 +13,17 @@ class Update < RailsAdmin::Config::Base
include RailsAdmin::Config::HasFields
include RailsAdmin::Config::HasGroups
- # Default items per page value used if a model level option has not
- # been configured
- cattr_accessor :default_hidden_fields
- @@default_hidden_fields = [:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on]
+ def self.default_hidden_fields
+ ActiveSupport::Deprecation.warn("'#{self.name}.default_hidden_fields' is deprecated, use 'RailsAdmin::Config.default_hidden_fields_for_edit' instead", caller)
+ RailsAdmin::Config.default_hidden_fields_for_edit
+ end
+
+ def self.default_hidden_fields=(value)
+ ActiveSupport::Deprecation.warn("'#{self.name}.default_hidden_fields=' is deprecated, use 'RailsAdmin.config{|c| c.default_hidden_fields_for_edit = #{value}}' instead", caller)
+ RailsAdmin.config do |config|
+ config.default_hidden_fields_for_edit = value
+ end
+ end
def initialize(parent)
super(parent)
@@ -38,7 +45,7 @@ def initialize(parent)
if f.association? && f.association[:options][:as]
f.hide
end
- if f.serial? || @@default_hidden_fields.include?(f.name)
+ if f.serial? || RailsAdmin::Config.default_hidden_fields_for_edit.include?(f.name)
f.hide
end
end
@@ -7,7 +7,9 @@
describe "authentication" do
it "should be disableable" do
logout
- RailsAdmin.authenticate_with {}
+ RailsAdmin.config do |config|
+ config.authenticate_with {}
+ end
visit rails_admin_dashboard_path
end
end

0 comments on commit d86ea76

Please sign in to comment.