Sha256: 5472f018d156b5c2d5be7a3df069f0de2813f6822fcf2fc949ca2e8dbbce6375

Contents?: true

Size: 1.16 KB

Versions: 57

Compression:

Stored size: 1.16 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 ||= '/filters/' << %w[
          turbo_frame controller resource_name related_name
          action id
        ].map { |key| params[key] }.compact.join('/')
      end

      def cache_resource_filters?
        return Avo.configuration.cache_resource_filters unless Avo.configuration.cache_resource_filters.is_a?(Proc)

        Avo.configuration.cache_resource_filters.call(current_user: current_user, resource: @resource)
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
avo-3.0.0.pre10 lib/avo/concerns/filters_session_handler.rb
avo-3.0.0.pre11 lib/avo/concerns/filters_session_handler.rb
avo-3.0.0.pre8 lib/avo/concerns/filters_session_handler.rb
avo-3.0.0.pre9 lib/avo/concerns/filters_session_handler.rb
avo-3.0.0.pre7 lib/avo/concerns/filters_session_handler.rb
avo-3.0.0.pre5 lib/avo/concerns/filters_session_handler.rb
avo-3.0.0.pre6 lib/avo/concerns/filters_session_handler.rb
avo-3.0.0.pre4 lib/avo/concerns/filters_session_handler.rb
avo-3.0.0.pre3 lib/avo/concerns/filters_session_handler.rb
avo-3.0.0.pre2 lib/avo/concerns/filters_session_handler.rb
avo-3.0.0.pre1 lib/avo/concerns/filters_session_handler.rb
avo-2.32.5 lib/avo/concerns/filters_session_handler.rb
avo-2.32.4 lib/avo/concerns/filters_session_handler.rb
avo-2.32.3 lib/avo/concerns/filters_session_handler.rb
avo-2.32.2 lib/avo/concerns/filters_session_handler.rb
avo-2.32.1 lib/avo/concerns/filters_session_handler.rb
avo-2.32.0 lib/avo/concerns/filters_session_handler.rb
avo-2.31.0 lib/avo/concerns/filters_session_handler.rb
avo-2.30.2 lib/avo/concerns/filters_session_handler.rb
avo-2.30.1 lib/avo/concerns/filters_session_handler.rb