Module: ActiveAdmin::Filters::ResourceExtension

Defined in:
lib/active_admin/filters/resource_extension.rb

Instance Method Summary collapse

Instance Method Details

#add_filter(attribute, options = {}) ⇒ Object

Add a filter for this resource. If filters are not enabled, this method will raise a RuntimeError

Parameters:

  • attribute (Symbol)

    The attribute to filter on

  • options (Hash) (defaults to: {})

    The set of options that are passed through to ransack for the field definition.

Raises:


76
77
78
79
80
# File 'lib/active_admin/filters/resource_extension.rb', line 76

def add_filter(attribute, options = {})
  raise Disabled unless filters_enabled?

  (@filters ||= {})[attribute.to_sym] = options
end

#current_filters=(bool) ⇒ Object

Setter to enable/disable showing current filters on this resource.

Set to `nil` to inherit the setting from the namespace


38
39
40
# File 'lib/active_admin/filters/resource_extension.rb', line 38

def current_filters=(bool)
  @current_filters_enabled = bool
end

#current_filters_enabled?Boolean

Returns If show current filters are enabled for this resource.

Returns:

  • (Boolean)

    If show current filters are enabled for this resource


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

def current_filters_enabled?
  @current_filters_enabled.nil? ? namespace.current_filters : @current_filters_enabled
end

#filtersHash

Returns the filters for this resource. If filters are not enabled, it will always return an empty hash.

Returns:

  • (Hash)

    Filters that apply for this resource


24
25
26
# File 'lib/active_admin/filters/resource_extension.rb', line 24

def filters
  filters_enabled? ? filter_lookup : {}
end

#filters=(bool) ⇒ Object

Setter to enable / disable filters on this resource.

Set to `nil` to inherit the setting from the namespace


31
32
33
# File 'lib/active_admin/filters/resource_extension.rb', line 31

def filters=(bool)
  @filters_enabled = bool
end

#filters_enabled?Boolean

Returns If filters are enabled for this resource.

Returns:

  • (Boolean)

    If filters are enabled for this resource


43
44
45
# File 'lib/active_admin/filters/resource_extension.rb', line 43

def filters_enabled?
  @filters_enabled.nil? ? namespace.filters : @filters_enabled
end

#initializeObject


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

def initialize(*)
  super
  add_filters_sidebar_section
  add_search_status_sidebar_section
end

#preserve_default_filters!Object


52
53
54
# File 'lib/active_admin/filters/resource_extension.rb', line 52

def preserve_default_filters!
  @preserve_default_filters = true
end

#preserve_default_filters?Boolean

Returns:

  • (Boolean)

56
57
58
# File 'lib/active_admin/filters/resource_extension.rb', line 56

def preserve_default_filters?
  @preserve_default_filters == true
end

#remove_filter(*attributes) ⇒ Object

Remove a filter for this resource. If filters are not enabled, this method will raise a RuntimeError

Parameters:

  • attributes (Symbol)

    The attributes to not filter on

Raises:


64
65
66
67
68
# File 'lib/active_admin/filters/resource_extension.rb', line 64

def remove_filter(*attributes)
  raise Disabled unless filters_enabled?

  attributes.each { |attribute| (@filters_to_remove ||= []) << attribute.to_sym }
end

#reset_filters!Object

Reset the filters to use defaults


83
84
85
86
# File 'lib/active_admin/filters/resource_extension.rb', line 83

def reset_filters!
  @filters = nil
  @filters_to_remove = nil
end