From f4c435c3cd7c359e2d2bc1893ff05545b8475e20 Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 27 Feb 2014 00:39:52 -0600 Subject: [PATCH] handle user filters --- app/models/item/search/filter.rb | 5 ++++- app/models/item/search/query.rb | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/item/search/filter.rb b/app/models/item/search/filter.rb index 0e0b8949..7645d95b 100644 --- a/app/models/item/search/filter.rb +++ b/app/models/item/search/filter.rb @@ -19,6 +19,10 @@ class Item if key_str.start_with?('is_') is_label = I18n.translate("items.search.flag_keywords.is") "#{sign}#{is_label}:#{label}" + elsif key_str.start_with?('user_') + user_label = I18n.translate("items.search.labels.user_closet_hanger_ownership") + value = Query::REVERSE_RESOURCE_FINDERS[:ownership].call(@value) + "#{sign}#{user_label}:#{value}" else if Query::TEXT_QUERY_RESOURCE_TYPES_BY_KEY.include?(@key) resource_type = Query::TEXT_QUERY_RESOURCE_TYPES_BY_KEY[@key] @@ -35,7 +39,6 @@ class Item if @key == :name "#{sign}#{quoted_value}" else - "#{sign}#{label}:#{quoted_value}" end end diff --git a/app/models/item/search/query.rb b/app/models/item/search/query.rb index e2f32609..a6d5965b 100644 --- a/app/models/item/search/query.rb +++ b/app/models/item/search/query.rb @@ -170,7 +170,8 @@ class Item Zone.find(id).plain_label }, ownership: lambda { |owned| - I18n.translate("items.search.labels.user_#{owned}") + owned_key = owned ? 'owns' : 'wants' + I18n.translate("items.search.labels.user_#{owned_key}") } } @@ -243,8 +244,13 @@ class Item if filter_params.has_key?(:key) key = filter_params[:key].to_sym if FIELD_KEYS.include?(key) + value = filter_params[:value] + # Ugh, this bit feels so hacky :P + if key == :user_closet_hanger_ownership + value = (value == 'true') + end is_positive = filter_params[:is_positive] == 'true' - Filter.new(key, filter_params[:value], is_positive) + Filter.new(key, value, is_positive) end end }.compact