2022-12-15 10:58:17 +01:00
|
|
|
module QueryParamsStoreConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2023-02-08 14:12:46 +01:00
|
|
|
included do
|
|
|
|
helper_method :stored_query_params?
|
|
|
|
end
|
|
|
|
|
2022-12-15 10:58:17 +01:00
|
|
|
def store_query_params
|
|
|
|
# Don't override already stored params, because we could do goings and comings with authentication, and
|
|
|
|
# lost previously stored params
|
2023-02-08 15:23:50 +01:00
|
|
|
return if stored_query_params? || filtered_query_params.empty?
|
2022-12-15 10:58:17 +01:00
|
|
|
|
2023-02-08 15:23:50 +01:00
|
|
|
session[:stored_params] = filtered_query_params.to_json
|
2022-12-15 10:58:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def retrieve_and_delete_stored_query_params
|
2023-02-08 14:12:46 +01:00
|
|
|
return {} unless stored_query_params?
|
2022-12-15 10:58:17 +01:00
|
|
|
|
|
|
|
JSON.parse(session.delete(:stored_params))
|
|
|
|
end
|
2023-02-08 14:12:46 +01:00
|
|
|
|
|
|
|
def stored_query_params?
|
|
|
|
session[:stored_params].present?
|
|
|
|
end
|
2023-02-08 15:23:50 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def filtered_query_params
|
|
|
|
request.query_parameters.except(:locale, "locale")
|
|
|
|
end
|
2022-12-15 10:58:17 +01:00
|
|
|
end
|