Sha256: 1433d18c1fa06e99edadd1592d77d2243306b2f679229d635d056a128a0a04ea

Contents?: true

Size: 1.13 KB

Versions: 65

Compression:

Stored size: 1.13 KB

Contents

module Avo
  module Concerns
    module FiltersSessionHandler
      def reset_filters
        return unless cache_resource_filters?

        session.delete(filters_session_key)
      end

      def fetch_filters
        return filters_from_params unless cache_resource_filters?

        (filters_from_params && save_filters_to_session) || filters_from_session
      end

      def filters_from_params
        params[Avo::Filters::BaseFilter::PARAM_KEY].presence
      end

      def save_filters_to_session
        session[filters_session_key] = params[Avo::Filters::BaseFilter::PARAM_KEY]
      end

      def filters_from_session
        session[filters_session_key]
      end

      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

      def cache_resource_filters?
        Avo::ExecutionContext.new(
          target: Avo.configuration.cache_resource_filters,
          current_user: _current_user,
          resource: @resource
        ).handle
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
avo-3.15.3 lib/avo/concerns/filters_session_handler.rb
avo-3.15.2 lib/avo/concerns/filters_session_handler.rb
avo-3.15.1 lib/avo/concerns/filters_session_handler.rb
avo-3.15.0 lib/avo/concerns/filters_session_handler.rb
avo-3.14.5 lib/avo/concerns/filters_session_handler.rb
avo-3.14.4 lib/avo/concerns/filters_session_handler.rb
avo-3.14.3 lib/avo/concerns/filters_session_handler.rb
avo-3.14.2 lib/avo/concerns/filters_session_handler.rb
avo-3.14.1 lib/avo/concerns/filters_session_handler.rb
avo-3.14.0 lib/avo/concerns/filters_session_handler.rb
avo-3.13.7 lib/avo/concerns/filters_session_handler.rb
avo-3.13.6 lib/avo/concerns/filters_session_handler.rb
avo-3.13.5 lib/avo/concerns/filters_session_handler.rb
avo-3.13.4 lib/avo/concerns/filters_session_handler.rb
avo-3.13.3 lib/avo/concerns/filters_session_handler.rb
avo-3.13.2 lib/avo/concerns/filters_session_handler.rb
avo-3.13.1 lib/avo/concerns/filters_session_handler.rb
avo-3.13.0 lib/avo/concerns/filters_session_handler.rb
avo-3.12.0 lib/avo/concerns/filters_session_handler.rb
avo-3.11.10 lib/avo/concerns/filters_session_handler.rb