Module: Avo::Concerns::FiltersSessionHandler
- Included in:
- BaseController
- Defined in:
- lib/avo/concerns/filters_session_handler.rb
Instance Method Summary collapse
- #cache_resource_filters? ⇒ Boolean
- #fetch_filters ⇒ Object
- #filters_from_params ⇒ Object
- #filters_from_session ⇒ Object
- #filters_session_key ⇒ Object
- #reset_filters ⇒ Object
- #save_filters_to_session ⇒ Object
Instance Method Details
#cache_resource_filters? ⇒ Boolean
35 36 37 38 39 40 41 |
# File 'lib/avo/concerns/filters_session_handler.rb', line 35 def cache_resource_filters? Avo::ExecutionContext.new( target: Avo.configuration.cache_resource_filters, current_user: _current_user, resource: @resource ).handle end |
#fetch_filters ⇒ Object
10 11 12 13 14 |
# File 'lib/avo/concerns/filters_session_handler.rb', line 10 def fetch_filters return filters_from_params unless cache_resource_filters? (filters_from_params && save_filters_to_session) || filters_from_session end |
#filters_from_params ⇒ Object
16 17 18 |
# File 'lib/avo/concerns/filters_session_handler.rb', line 16 def filters_from_params params[Avo::Filters::BaseFilter::PARAM_KEY].presence end |
#filters_from_session ⇒ Object
24 25 26 |
# File 'lib/avo/concerns/filters_session_handler.rb', line 24 def filters_from_session session[filters_session_key] end |
#filters_session_key ⇒ Object
28 29 30 31 32 33 |
# File 'lib/avo/concerns/filters_session_handler.rb', line 28 def filters_session_key @filters_session_key ||= "/encoded_filters/" << %w[ turbo_frame controller resource_name related_name action id ].map { |key| params[key] }.compact.join("/") end |
#reset_filters ⇒ Object
4 5 6 7 8 |
# File 'lib/avo/concerns/filters_session_handler.rb', line 4 def reset_filters return unless cache_resource_filters? session.delete(filters_session_key) end |
#save_filters_to_session ⇒ Object
20 21 22 |
# File 'lib/avo/concerns/filters_session_handler.rb', line 20 def save_filters_to_session session[filters_session_key] = params[Avo::Filters::BaseFilter::PARAM_KEY] end |