Skip to content

Commit

Permalink
Fixed AccessModifierIndentation offences -- private, protected
Browse files Browse the repository at this point in the history
  • Loading branch information
durhamka committed Dec 19, 2013
1 parent d0db9e9 commit 5533854
Show file tree
Hide file tree
Showing 16 changed files with 931 additions and 931 deletions.
66 changes: 33 additions & 33 deletions app/controllers/rails_admin/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,48 @@ def to_model_name(param)
model_name = param.split('~').map(&:camelize).join('::')
end

private
private

def _get_plugin_name
@plugin_name_array ||= [RailsAdmin.config.main_app_name.is_a?(Proc) ? instance_eval(&RailsAdmin.config.main_app_name) : RailsAdmin.config.main_app_name].flatten
end
def _get_plugin_name
@plugin_name_array ||= [RailsAdmin.config.main_app_name.is_a?(Proc) ? instance_eval(&RailsAdmin.config.main_app_name) : RailsAdmin.config.main_app_name].flatten
end

def _authenticate!
instance_eval &RailsAdmin::Config.authenticate_with
end
def _authenticate!
instance_eval &RailsAdmin::Config.authenticate_with
end

def _authorize!
instance_eval &RailsAdmin::Config.authorize_with
end
def _authorize!
instance_eval &RailsAdmin::Config.authorize_with
end

def _audit!
instance_eval &RailsAdmin::Config.audit_with
end
def _audit!
instance_eval &RailsAdmin::Config.audit_with
end

def _current_user
instance_eval &RailsAdmin::Config.current_user_method
end
def _current_user
instance_eval &RailsAdmin::Config.current_user_method
end

alias_method :user_for_paper_trail, :_current_user
alias_method :user_for_paper_trail, :_current_user

rescue_from RailsAdmin::ObjectNotFound do
flash[:error] = I18n.t('admin.flash.object_not_found', :model => @model_name, :id => params[:id])
params[:action] = 'index'
index
end
rescue_from RailsAdmin::ObjectNotFound do
flash[:error] = I18n.t('admin.flash.object_not_found', :model => @model_name, :id => params[:id])
params[:action] = 'index'
index
end

rescue_from RailsAdmin::ModelNotFound do
flash[:error] = I18n.t('admin.flash.model_not_found', :model => @model_name)
params[:action] = 'dashboard'
dashboard
end
rescue_from RailsAdmin::ModelNotFound do
flash[:error] = I18n.t('admin.flash.model_not_found', :model => @model_name)
params[:action] = 'dashboard'
dashboard
end

def not_found
render :file => Rails.root.join('public', '404.html'), :layout => false, :status => :not_found
end
def not_found
render :file => Rails.root.join('public', '404.html'), :layout => false, :status => :not_found
end

def rails_admin_controller?
true
end
def rails_admin_controller?
true
end
end
end
182 changes: 91 additions & 91 deletions app/controllers/rails_admin/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,115 +37,115 @@ def list_entries(model_config = @model_config, auth_scope_key = :index, addition
get_collection(model_config, scope, pagination)
end

private
private

def get_layout
"rails_admin/#{request.headers['X-PJAX'] ? 'pjax' : 'application'}"
end

def back_or_index
params[:return_to].presence && params[:return_to].include?(request.host) && (params[:return_to] != request.fullpath) ? params[:return_to] : index_path
end
def get_layout
"rails_admin/#{request.headers['X-PJAX'] ? 'pjax' : 'application'}"
end

def get_sort_hash(model_config)
abstract_model = model_config.abstract_model
params[:sort] = params[:sort_reverse] = nil unless model_config.list.fields.map { |f| f.name.to_s }.include? params[:sort]

params[:sort] ||= model_config.list.sort_by.to_s
params[:sort_reverse] ||= 'false'

field = model_config.list.fields.detect { |f| f.name.to_s == params[:sort] }

column = if field.nil? || field.sortable == true # use params[:sort] on the base table
"#{abstract_model.table_name}.#{params[:sort]}"
elsif field.sortable == false # use default sort, asked field is not sortable
"#{abstract_model.table_name}.#{model_config.list.sort_by}"
elsif (field.sortable.is_a?(String) || field.sortable.is_a?(Symbol)) && field.sortable.to_s.include?('.') # just provide sortable, don't do anything smart
field.sortable
elsif field.sortable.is_a?(Hash) # just join sortable hash, don't do anything smart
"#{field.sortable.keys.first}.#{field.sortable.values.first}"
elsif field.association? # use column on target table
"#{field.associated_model_config.abstract_model.table_name}.#{field.sortable}"
else # use described column in the field conf.
"#{abstract_model.table_name}.#{field.sortable}"
end
def back_or_index
params[:return_to].presence && params[:return_to].include?(request.host) && (params[:return_to] != request.fullpath) ? params[:return_to] : index_path
end

reversed_sort = (field ? field.sort_reverse? : model_config.list.sort_reverse?)
{:sort => column, :sort_reverse => (params[:sort_reverse] == reversed_sort.to_s)}
def get_sort_hash(model_config)
abstract_model = model_config.abstract_model
params[:sort] = params[:sort_reverse] = nil unless model_config.list.fields.map { |f| f.name.to_s }.include? params[:sort]

params[:sort] ||= model_config.list.sort_by.to_s
params[:sort_reverse] ||= 'false'

field = model_config.list.fields.detect { |f| f.name.to_s == params[:sort] }

column = if field.nil? || field.sortable == true # use params[:sort] on the base table
"#{abstract_model.table_name}.#{params[:sort]}"
elsif field.sortable == false # use default sort, asked field is not sortable
"#{abstract_model.table_name}.#{model_config.list.sort_by}"
elsif (field.sortable.is_a?(String) || field.sortable.is_a?(Symbol)) && field.sortable.to_s.include?('.') # just provide sortable, don't do anything smart
field.sortable
elsif field.sortable.is_a?(Hash) # just join sortable hash, don't do anything smart
"#{field.sortable.keys.first}.#{field.sortable.values.first}"
elsif field.association? # use column on target table
"#{field.associated_model_config.abstract_model.table_name}.#{field.sortable}"
else # use described column in the field conf.
"#{abstract_model.table_name}.#{field.sortable}"
end

def redirect_to_on_success
notice = t('admin.flash.successful', :name => @model_config.label, :action => t("admin.actions.#{@action.key}.done"))
if params[:_add_another]
redirect_to new_path(:return_to => params[:return_to]), :flash => {:success => notice}
elsif params[:_add_edit]
redirect_to edit_path(:id => @object.id, :return_to => params[:return_to]), :flash => {:success => notice}
else
redirect_to back_or_index, :flash => {:success => notice}
end
reversed_sort = (field ? field.sort_reverse? : model_config.list.sort_reverse?)
{:sort => column, :sort_reverse => (params[:sort_reverse] == reversed_sort.to_s)}
end

def redirect_to_on_success
notice = t('admin.flash.successful', :name => @model_config.label, :action => t("admin.actions.#{@action.key}.done"))
if params[:_add_another]
redirect_to new_path(:return_to => params[:return_to]), :flash => {:success => notice}
elsif params[:_add_edit]
redirect_to edit_path(:id => @object.id, :return_to => params[:return_to]), :flash => {:success => notice}
else
redirect_to back_or_index, :flash => {:success => notice}
end
end

def satisfy_strong_params!
if @abstract_model.model.ancestors.map(&:to_s).include?('ActiveModel::ForbiddenAttributesProtection')
params[@abstract_model.param_key].try :permit!
end
def satisfy_strong_params!
if @abstract_model.model.ancestors.map(&:to_s).include?('ActiveModel::ForbiddenAttributesProtection')
params[@abstract_model.param_key].try :permit!
end
end

def sanitize_params_for!(action, model_config = @model_config, _params = params[@abstract_model.param_key])
return unless _params.present?
fields = model_config.send(action).with(:controller => self, :view => view_context, :object => @object).visible_fields
allowed_methods = fields.map { |f|
f.allowed_methods
}.flatten.uniq.map(&:to_s) << 'id' << '_destroy'
fields.each { |f| f.parse_input(_params) }
_params.slice!(*allowed_methods)
fields.select(&:nested_form).each do |association|
children_params = association.multiple? ? _params[association.method_name].try(:values) : [_params[association.method_name]].compact
(children_params || []).each do |children_param|
sanitize_params_for!(:nested, association.associated_model_config, children_param)
end
def sanitize_params_for!(action, model_config = @model_config, _params = params[@abstract_model.param_key])
return unless _params.present?
fields = model_config.send(action).with(:controller => self, :view => view_context, :object => @object).visible_fields
allowed_methods = fields.map { |f|
f.allowed_methods
}.flatten.uniq.map(&:to_s) << 'id' << '_destroy'
fields.each { |f| f.parse_input(_params) }
_params.slice!(*allowed_methods)
fields.select(&:nested_form).each do |association|
children_params = association.multiple? ? _params[association.method_name].try(:values) : [_params[association.method_name]].compact
(children_params || []).each do |children_param|
sanitize_params_for!(:nested, association.associated_model_config, children_param)
end
end
end

def handle_save_error whereto = :new
action = params[:action]
def handle_save_error whereto = :new
action = params[:action]

flash.now[:error] = t('admin.flash.error', :name => @model_config.label, :action => t("admin.actions.#{@action.key}.done"))
flash.now[:error] += ". #{@object.errors[:base].to_sentence}" unless @object.errors[:base].blank?
flash.now[:error] = t('admin.flash.error', :name => @model_config.label, :action => t("admin.actions.#{@action.key}.done"))
flash.now[:error] += ". #{@object.errors[:base].to_sentence}" unless @object.errors[:base].blank?

respond_to do |format|
format.html { render whereto, :status => :not_acceptable }
format.js { render whereto, :layout => false, :status => :not_acceptable }
end
respond_to do |format|
format.html { render whereto, :status => :not_acceptable }
format.js { render whereto, :layout => false, :status => :not_acceptable }
end
end

def check_for_cancel
if params[:_continue] || (params[:bulk_action] && !params[:bulk_ids])
redirect_to(back_or_index, :flash => {:info => t('admin.flash.noaction')})
end
def check_for_cancel
if params[:_continue] || (params[:bulk_action] && !params[:bulk_ids])
redirect_to(back_or_index, :flash => {:info => t('admin.flash.noaction')})
end
end

def get_collection(model_config, scope, pagination)
associations = model_config.list.fields.select { |f| f.type == :belongs_to_association && !f.polymorphic? }.map { |f| f.association[:name] }
options = {}
options = options.merge(:page => (params[Kaminari.config.param_name] || 1).to_i, :per => (params[:per] || model_config.list.items_per_page)) if pagination
options = options.merge(:include => associations) unless associations.blank?
options = options.merge(get_sort_hash(model_config))
options = options.merge(:query => params[:query]) if params[:query].present?
options = options.merge(:filters => params[:f]) if params[:f].present?
options = options.merge(:bulk_ids => params[:bulk_ids]) if params[:bulk_ids]

objects = model_config.abstract_model.all(options, scope)
end
def get_collection(model_config, scope, pagination)
associations = model_config.list.fields.select { |f| f.type == :belongs_to_association && !f.polymorphic? }.map { |f| f.association[:name] }
options = {}
options = options.merge(:page => (params[Kaminari.config.param_name] || 1).to_i, :per => (params[:per] || model_config.list.items_per_page)) if pagination
options = options.merge(:include => associations) unless associations.blank?
options = options.merge(get_sort_hash(model_config))
options = options.merge(:query => params[:query]) if params[:query].present?
options = options.merge(:filters => params[:f]) if params[:f].present?
options = options.merge(:bulk_ids => params[:bulk_ids]) if params[:bulk_ids]

objects = model_config.abstract_model.all(options, scope)
end

def get_association_scope_from_params
return nil unless params[:associated_collection].present?
source_abstract_model = RailsAdmin::AbstractModel.new(to_model_name(params[:source_abstract_model]))
source_model_config = source_abstract_model.config
source_object = source_abstract_model.get(params[:source_object_id])
action = params[:current_action].in?([%w(create update)]) ? params[:current_action] : 'edit'
@association = source_model_config.send(action).fields.detect { |f| f.name == params[:associated_collection].to_sym }.with(:controller => self, :object => source_object)
@association.associated_collection_scope
end
def get_association_scope_from_params
return nil unless params[:associated_collection].present?
source_abstract_model = RailsAdmin::AbstractModel.new(to_model_name(params[:source_abstract_model]))
source_model_config = source_abstract_model.config
source_object = source_abstract_model.get(params[:source_object_id])
action = params[:current_action].in?([%w(create update)]) ? params[:current_action] : 'edit'
@association = source_model_config.send(action).fields.detect { |f| f.name == params[:associated_collection].to_sym }.with(:controller => self, :object => source_object)
@association.associated_collection_scope
end
end
end
50 changes: 25 additions & 25 deletions app/helpers/rails_admin/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,34 +97,34 @@ def dom_name(field)
(@dom_name ||= {})[field.name] ||= %{#{@object_name}#{options[:index] && "[#{options[:index]}]"}[#{field.method_name}]#{field.is_a?(Config::Fields::Association) && field.multiple? ? '[]' : ''}}
end

protected
def generator_action(action, nested)
if nested
action = :nested
elsif @template.request.format == 'text/javascript'
action = :modal
end

action
protected
def generator_action(action, nested)
if nested
action = :nested
elsif @template.request.format == 'text/javascript'
action = :modal
end

def visible_groups(model_config, action)
model_config.send(action).with(
:form => self,
:object => @object,
:view => @template,
:controller => @template.controller
).visible_groups
end
action
end

def without_field_error_proc_added_div
default_field_error_proc = ::ActionView::Base.field_error_proc
begin
::ActionView::Base.field_error_proc = proc { |html_tag, instance| html_tag }
yield
ensure
::ActionView::Base.field_error_proc = default_field_error_proc
end
def visible_groups(model_config, action)
model_config.send(action).with(
:form => self,
:object => @object,
:view => @template,
:controller => @template.controller
).visible_groups
end

def without_field_error_proc_added_div
default_field_error_proc = ::ActionView::Base.field_error_proc
begin
::ActionView::Base.field_error_proc = proc { |html_tag, instance| html_tag }
yield
ensure
::ActionView::Base.field_error_proc = default_field_error_proc
end
end
end
end
Loading

0 comments on commit 5533854

Please sign in to comment.