Browse Source

Refactor filter_selected?

pull/2666/head
Manny Dinssa 2 years ago
parent
commit
ff3339a3cd
  1. 61
      app/helpers/filters_helper.rb

61
app/helpers/filters_helper.rb

@ -5,24 +5,21 @@ module FiltersHelper
return false unless session[session_name_for(filter_type)] return false unless session[session_name_for(filter_type)]
selected_filters = JSON.parse(session[session_name_for(filter_type)]) selected_filters = JSON.parse(session[session_name_for(filter_type)])
return true if !selected_filters.key?("user") && filter == "assigned_to" && value == :all
return true if selected_filters["assigned_to"] == "specific_user" && filter == "assigned_to" && value == :specific_user
return true if !selected_filters.key?("owning_organisation") && filter == "owning_organisation_select" && value == :all case filter
return true if !selected_filters.key?("managing_organisation") && filter == "managing_organisation_select" && value == :all when "assigned_to"
assigned_to_filter_selected?(selected_filters, value)
return true if (selected_filters["owning_organisation"].present? || selected_filters["owning_organisation_text_search"].present?) && filter == "owning_organisation_select" && value == :specific_org when "owning_organisation_select"
return true if (selected_filters["managing_organisation"].present? || selected_filters["managing_organisation_text_search"].present?) && filter == "managing_organisation_select" && value == :specific_org owning_organisation_filter_selected?(selected_filters, value)
when "managing_organisation_select"
return true if !selected_filters.key?("user") && filter == "uploaded_by" && value == :all managing_organisation_filter_selected?(selected_filters, value)
return true if selected_filters["uploaded_by"] == "specific_user" && filter == "uploaded_by" && value == :specific_user when "uploaded_by"
uploaded_by_filter_selected?(selected_filters, value)
return true if !selected_filters.key?("uploading_organisation") && filter == "uploading_organisation_select" && value == :all when "uploading_organisation_select"
return true if (selected_filters["uploading_organisation"].present? || selected_filters["uploading_organisation_text_search"].present?) && filter == "uploading_organisation_select" && value == :specific_org uploading_organisation_filter_selected?(selected_filters, value)
else
return false if selected_filters[filter].blank? selected_filters[filter]&.include?(value.to_s) || false
end
selected_filters[filter].include?(value.to_s)
end end
def any_filter_selected?(filter_type) def any_filter_selected?(filter_type)
@ -349,4 +346,34 @@ private
def unanswered_filter_value def unanswered_filter_value
"<span class=\"app-!-colour-muted\">You didn’t answer this filter</span>".html_safe "<span class=\"app-!-colour-muted\">You didn’t answer this filter</span>".html_safe
end end
def assigned_to_filter_selected?(selected_filters, value)
return true if !selected_filters.key?("user") && value == :all
return true if selected_filters["assigned_to"] == "specific_user" && value == :specific_user
false
end
def owning_organisation_filter_selected?(selected_filters, value)
return true if !selected_filters.key?("owning_organisation") && value == :all
return true if (selected_filters["owning_organisation"].present? || selected_filters["owning_organisation_text_search"].present?) && value == :specific_org
false
end
def managing_organisation_filter_selected?(selected_filters, value)
return true if !selected_filters.key?("managing_organisation") && value == :all
return true if (selected_filters["managing_organisation"].present? || selected_filters["managing_organisation_text_search"].present?) && value == :specific_org
false
end
def uploaded_by_filter_selected?(selected_filters, value)
return true if !selected_filters.key?("user") && value == :all
return true if selected_filters["uploaded_by"] == "specific_user" && value == :specific_user
false
end
def uploading_organisation_filter_selected?(selected_filters, value)
return true if !selected_filters.key?("uploading_organisation") && value == :all
return true if (selected_filters["uploading_organisation"].present? || selected_filters["uploading_organisation_text_search"].present?) && value == :specific_org
false
end
end end

Loading…
Cancel
Save