a more forgiving "type" search filter
This commit is contained in:
parent
775ef7fa51
commit
671641cc16
2 changed files with 23 additions and 4 deletions
|
@ -764,7 +764,7 @@ class Item < ActiveRecord::Base
|
|||
end
|
||||
|
||||
single_search_filter :type, {:limit => true, :scope => :join_swf_assets} do |zone_set_name|
|
||||
zone_set = Zone::ItemZoneSets[zone_set_name]
|
||||
zone_set = Zone.find_set(zone_set_name)
|
||||
raise SearchError, "Type \"#{zone_set_name}\" does not exist" unless zone_set
|
||||
SwfAsset.arel_table[:zone_id].in(zone_set.map(&:id))
|
||||
end
|
||||
|
|
|
@ -17,16 +17,35 @@ class Zone < StaticResource
|
|||
@sometimes ? "#{label} sometimes" : label
|
||||
end
|
||||
|
||||
def self.find_set(name)
|
||||
ItemZoneSets[plain(name)]
|
||||
end
|
||||
|
||||
def self.plain(name)
|
||||
name.delete('\- /').downcase
|
||||
end
|
||||
|
||||
n = 0
|
||||
@objects = YAML.load_file(Rails.root.join('config', 'zones.yml')).map do |a|
|
||||
a['id'] = (n += 1)
|
||||
obj = new(a)
|
||||
if obj.type_id == 2 || obj.type_id == 3
|
||||
zone_name = obj.label.delete(' -').gsub(/item$/, '').downcase
|
||||
ItemZoneSets[zone_name] ||= []
|
||||
ItemZoneSets[zone_name] << obj
|
||||
plain_name = plain(obj.label)
|
||||
|
||||
ItemZoneSets[plain_name] ||= []
|
||||
ItemZoneSets[plain_name] << obj
|
||||
end
|
||||
obj
|
||||
end
|
||||
n = nil
|
||||
|
||||
# Add aliases to keys like "lowerforegrounditem" to "lowerforeground"
|
||||
# ...unless there's already such a key, like "backgrounditem" to "background",
|
||||
# in which case we don't, because that'd be silly.
|
||||
ItemZoneSets.keys.each do |name|
|
||||
if name.end_with?('item')
|
||||
stripped_name = name[0..-5]
|
||||
ItemZoneSets[stripped_name] ||= ItemZoneSets[name]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue