Sha256: 13265f3f2daa7fc1a242be01ecd5404601feb4871dc6405300c84b4d67f2c731

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

class Dorsale::SmallData::FiltersController < ::Dorsale::ApplicationController
  def create
    skip_authorization
    skip_policy_scope

    new_filters = params.fetch(:filters, {}).permit!.to_h

    new_filters.each do |key, value|
      new_filters[key] = "" if value == "0"
    end

    filters = ::Dorsale::SmallData::Filter.new(cookies)
    new_filters = filters.read.merge(new_filters)
    filters.store(new_filters)

    # Rewrite cookie with 1 year expiry
    cookies[:filters] = {
      :value    => cookies[:filters],
      :expires => 1.year.from_now,
      :path     => "/",
    }

    redirect_to back_url
  end

  private

  def back_url
    url = [
      params[:form_url],
      request.referer,
      (main_app.root_path rescue "/"),
    ].select(&:present?).first

    # Delete page page
    base, query_string = url.split("?")
    query_string = query_string.to_s.split("&").delete_if { |p| p.include?("page=") }.join("&")
    query_string = "?#{query_string}" if query_string.present?
    base + query_string
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dorsale-3.1.6 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-3.1.5 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-3.1.4 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-3.1.3 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-3.1.2 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-3.1.1 app/controllers/dorsale/small_data/filters_controller.rb
dorsale-3.1.0 app/controllers/dorsale/small_data/filters_controller.rb