Class: Avo::Filters::BaseFilter
- Inherits:
-
Object
- Object
- Avo::Filters::BaseFilter
show all
- Defined in:
- lib/avo/filters/base_filter.rb
Constant Summary
collapse
- PARAM_KEY =
:encoded_filters
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(arguments: {}) ⇒ BaseFilter
Returns a new instance of BaseFilter.
38
39
40
|
# File 'lib/avo/filters/base_filter.rb', line 38
def initialize(arguments: {})
@arguments = arguments
end
|
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
14
15
16
|
# File 'lib/avo/filters/base_filter.rb', line 14
def arguments
@arguments
end
|
Class Method Details
.decode_filters(filter_params) ⇒ Object
25
26
27
|
# File 'lib/avo/filters/base_filter.rb', line 25
def decode_filters(filter_params)
JSON.parse(Base64.decode64(filter_params))
end
|
.encode_filters(filter_params) ⇒ Object
29
30
31
|
# File 'lib/avo/filters/base_filter.rb', line 29
def encode_filters(filter_params)
Base64.encode64(filter_params.to_json)
end
|
.get_empty_message ⇒ Object
33
34
35
|
# File 'lib/avo/filters/base_filter.rb', line 33
def get_empty_message
empty_message || I18n.t("avo.no_options_available")
end
|
Instance Method Details
#applied_filters ⇒ Object
Fetch the applied filters from the params
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/avo/filters/base_filter.rb', line 68
def applied_filters
return {} if (filters_from_params = params[PARAM_KEY]).blank?
return {} if !filters_from_params.is_a?(String)
self.class.decode_filters filters_from_params
end
|
#applied_or_default_value(applied_filters) ⇒ Object
Get the applied value this filter. If it’s not present return the default value.
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/avo/filters/base_filter.rb', line 54
def applied_or_default_value(applied_filters)
applied_value = applied_filters[self.class.to_s]
return applied_value unless applied_value.nil?
default
rescue
default
end
|
#apply_query(request, query, value) ⇒ Object
42
43
44
45
46
|
# File 'lib/avo/filters/base_filter.rb', line 42
def apply_query(request, query, value)
value.stringify_keys! if value.is_a? Hash
apply(request, query, value)
end
|
96
97
98
|
# File 'lib/avo/filters/base_filter.rb', line 96
def button_label
Avo::ExecutionContext.new(target: self.class.button_label, arguments: @arguments).handle
end
|
#current_user ⇒ Object
20
21
22
|
# File 'lib/avo/filters/base_filter.rb', line 20
def current_user
Avo::Current.user
end
|
#id ⇒ Object
48
49
50
|
# File 'lib/avo/filters/base_filter.rb', line 48
def id
name.underscore.tr("/", "_")
end
|
#name ⇒ Object
92
93
94
|
# File 'lib/avo/filters/base_filter.rb', line 92
def name
Avo::ExecutionContext.new(target: self.class.name, arguments: @arguments).handle
end
|
#visible_in_view(resource: nil, parent_resource: nil) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/avo/filters/base_filter.rb', line 79
def visible_in_view(resource: nil, parent_resource: nil)
return true if visible.blank?
Avo::ExecutionContext.new(
target: visible,
params: params,
parent_resource: parent_resource,
resource: resource,
arguments: arguments
).handle
end
|