forked from OpenNeo/impress
Item search can filter by fitting alt styles (but missing many details!)
A query like this works for finding items containing "hat" that fit alt style #87296 (the Faerie Acara): http://localhost:3000/items?q%5B0%5D%5Bkey%5D=name&q%5B0%5D%5Bvalue%5D=hat&q%5B1%5D%5Bkey%5D=fits&q%5B1%5D%5Bvalue%5D%5Bspecies_id%5D=1&q%5B1%5D%5Bvalue%5D%5Bcolor_id%5D=8&q%5B1%5D%5Bvalue%5D%5Balt_style_id%5D=87296 But there's two main missing pieces still: 1. You can't do a text-filter version of this—in fact, clicking Search immediately on the page this loads will return an error! 2. We haven't extended this to the `with_appearances_for` parameter, so we add a `NotImplementedError` to that bit for now too. I'm also thinking that the text filter should ideally be like, `fits:nostalgic-faerie-acara` if we can pull it off; and then fall back to the plainer `fits:alt-style-87296` if e.g. we don't know the set it's from yet.
This commit is contained in:
parent
183cb40e74
commit
3781c9810a
3 changed files with 40 additions and 7 deletions
|
@ -123,6 +123,7 @@ class ItemsController < ApplicationController
|
||||||
def load_appearances
|
def load_appearances
|
||||||
appearance_params = params[:with_appearances_for]
|
appearance_params = params[:with_appearances_for]
|
||||||
return {} if appearance_params.blank?
|
return {} if appearance_params.blank?
|
||||||
|
raise NotImplementedError if appearance_params[:alt_style_id].present?
|
||||||
|
|
||||||
pet_type = Item::Search::Query.load_pet_type_by_color_and_species(
|
pet_type = Item::Search::Query.load_pet_type_by_color_and_species(
|
||||||
appearance_params[:color_id], appearance_params[:species_id])
|
appearance_params[:color_id], appearance_params[:species_id])
|
||||||
|
|
|
@ -128,12 +128,18 @@ class Item
|
||||||
Filter.restricts(value) :
|
Filter.restricts(value) :
|
||||||
Filter.not_restricts(value))
|
Filter.not_restricts(value))
|
||||||
when 'fits'
|
when 'fits'
|
||||||
raise NotImplementedError if value[:alt_style_id].present?
|
if value[:alt_style_id].present?
|
||||||
|
alt_style = load_alt_style_by_id(value[:alt_style_id])
|
||||||
|
filters << (is_positive ?
|
||||||
|
Filter.fits_alt_style(alt_style) :
|
||||||
|
Filter.fits_alt_style(alt_style))
|
||||||
|
else
|
||||||
pet_type = load_pet_type_by_color_and_species(
|
pet_type = load_pet_type_by_color_and_species(
|
||||||
value[:color_id], value[:species_id])
|
value[:color_id], value[:species_id])
|
||||||
filters << (is_positive ?
|
filters << (is_positive ?
|
||||||
Filter.fits_pet_type(pet_type) :
|
Filter.fits_pet_type(pet_type) :
|
||||||
Filter.not_fits_pet_type(pet_type))
|
Filter.not_fits_pet_type(pet_type))
|
||||||
|
end
|
||||||
when 'user_closet_hanger_ownership'
|
when 'user_closet_hanger_ownership'
|
||||||
case value
|
case value
|
||||||
when 'true'
|
when 'true'
|
||||||
|
@ -174,6 +180,16 @@ class Item
|
||||||
raise Item::Search::Error, message
|
raise Item::Search::Error, message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.load_alt_style_by_id(alt_style_id)
|
||||||
|
begin
|
||||||
|
AltStyle.find(alt_style_id)
|
||||||
|
rescue
|
||||||
|
message = I18n.translate('items.search.errors.not_found.alt_style',
|
||||||
|
filter_text: "alt-style-#{alt_style_id}")
|
||||||
|
raise Item::Search::Error, message
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Error < Exception
|
class Error < Exception
|
||||||
|
@ -235,6 +251,16 @@ class Item
|
||||||
self.new Item.not_fits(pet_type.body_id), "-fits:#{q value}"
|
self.new Item.not_fits(pet_type.body_id), "-fits:#{q value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.fits_alt_style(alt_style)
|
||||||
|
value = alt_style_to_filter_text(alt_style)
|
||||||
|
self.new Item.fits(alt_style.body_id), "fits:#{q value}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.not_fits_alt_style(alt_style)
|
||||||
|
value = alt_style_to_filter_text(alt_style)
|
||||||
|
self.new Item.not_fits(alt_style.body_id), "-fits:#{q value}"
|
||||||
|
end
|
||||||
|
|
||||||
def self.fits_species(body_id, species_name)
|
def self.fits_species(body_id, species_name)
|
||||||
self.new Item.fits(body_id), "species:#{q species_name}"
|
self.new Item.fits(body_id), "species:#{q species_name}"
|
||||||
end
|
end
|
||||||
|
@ -297,7 +323,11 @@ class Item
|
||||||
species_name ||= pet_type.species.name
|
species_name ||= pet_type.species.name
|
||||||
|
|
||||||
# NOTE: Some color syntaxes are weird, like `fits:"polka dot-aisha"`!
|
# NOTE: Some color syntaxes are weird, like `fits:"polka dot-aisha"`!
|
||||||
value = "#{color_name}-#{species_name}".downcase
|
"#{color_name}-#{species_name}".downcase
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.alt_style_to_filter_text(alt_style)
|
||||||
|
"alt-style-#{alt_style.id}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -358,6 +358,8 @@ en:
|
||||||
user:wants?
|
user:wants?
|
||||||
pet_type: We have no record of the %{name1} %{name2}.
|
pet_type: We have no record of the %{name1} %{name2}.
|
||||||
It is spelled correctly?
|
It is spelled correctly?
|
||||||
|
alt_style: We have no record of the "%{filter_text}" alt style. Is it
|
||||||
|
spelled correctly?
|
||||||
pet_type_id: We have no record of pet type %{id}. Weird.
|
pet_type_id: We have no record of pet type %{id}. Weird.
|
||||||
not_logged_in: The "user" filters are only available if you're logged in.
|
not_logged_in: The "user" filters are only available if you're logged in.
|
||||||
flag_keywords:
|
flag_keywords:
|
||||||
|
|
Loading…
Reference in a new issue