Class: ActiveAdmin::Filters::ActiveFilter

Inherits:
Object
  • Object
show all
Includes:
ViewHelpers
Defined in:
lib/active_admin/filters/active_filter.rb

Constant Summary

Constants included from ViewHelpers::DisplayHelper

ViewHelpers::DisplayHelper::DISPLAY_NAME_FALLBACK

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ViewHelpers::ScopeNameHelper

#scope_name

Methods included from ViewHelpers::FlashHelper

#flash_messages

Methods included from ViewHelpers::ViewFactoryHelper

#view_factory

Methods included from ViewHelpers::TitleHelper

#title

Methods included from ViewHelpers::FormHelper

#active_admin_form_for, #fields_for_params, #hidden_field_tags_for

Methods included from ViewHelpers::SidebarHelper

#skip_sidebar!, #skip_sidebar?

Methods included from MethodOrProcHelper

#call_method_or_exec_proc, #call_method_or_proc_on, #render_in_context, #render_or_call_method_or_proc_on

Methods included from ViewHelpers::DisplayHelper

#association_methods_for, #boolean_attr?, #display_name, #display_name_method_for, #find_value, #format_attribute, #format_collection, #pretty_format

Methods included from ViewHelpers::BreadcrumbHelper

#breadcrumb_links

Methods included from ViewHelpers::AutoLinkHelper

#active_admin_resource_for, #auto_link, #auto_url_for

Methods included from ViewHelpers::ActiveAdminApplicationHelper

#active_admin_application

Constructor Details

#initialize(resource, condition) ⇒ ActiveFilter

Instantiate a ‘ActiveFilter`

Parameters:

  • resource (ActiveAdmin::Resource)

    current resource

  • condition (Ransack::Nodes::Condition)

    applied ransack condition



14
15
16
17
18
# File 'lib/active_admin/filters/active_filter.rb', line 14

def initialize(resource, condition)
  @resource = resource
  @condition = condition
  @related_class = find_class if find_class?
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



8
9
10
# File 'lib/active_admin/filters/active_filter.rb', line 8

def condition
  @condition
end

Returns the value of attribute related_class.



8
9
10
# File 'lib/active_admin/filters/active_filter.rb', line 8

def related_class
  @related_class
end

#resourceObject (readonly)

Returns the value of attribute resource.



8
9
10
# File 'lib/active_admin/filters/active_filter.rb', line 8

def resource
  @resource
end

Instance Method Details

#html_optionsObject



48
49
50
# File 'lib/active_admin/filters/active_filter.rb', line 48

def html_options
  { class: "current_filter current_filter_#{condition.key}" }
end

#labelObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_admin/filters/active_filter.rb', line 29

def label
  translated_predicate = predicate_name.downcase
  if filter_label && filter_label.is_a?(Proc)
    "#{filter_label.call} #{translated_predicate}"
  elsif filter_label
    "#{filter_label} #{translated_predicate}"
  elsif related_class
    "#{related_class_name} #{translated_predicate}"
  else
    "#{attribute_name} #{translated_predicate}"
  end.strip
end

#predicate_nameObject



42
43
44
45
46
# File 'lib/active_admin/filters/active_filter.rb', line 42

def predicate_name
  I18n.t(
    "ransack.predicates.#{condition.predicate.name}",
    default: ransack_predicate_name)
end

#valuesObject



20
21
22
23
24
25
26
27
# File 'lib/active_admin/filters/active_filter.rb', line 20

def values
  condition_values = condition.values.map(&:value)
  if related_class
    related_class.where(related_primary_key => condition_values)
  else
    condition_values
  end
end