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
|
end
|
||||||
|
|
||||||
single_search_filter :type, {:limit => true, :scope => :join_swf_assets} do |zone_set_name|
|
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
|
raise SearchError, "Type \"#{zone_set_name}\" does not exist" unless zone_set
|
||||||
SwfAsset.arel_table[:zone_id].in(zone_set.map(&:id))
|
SwfAsset.arel_table[:zone_id].in(zone_set.map(&:id))
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,16 +17,35 @@ class Zone < StaticResource
|
||||||
@sometimes ? "#{label} sometimes" : label
|
@sometimes ? "#{label} sometimes" : label
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.find_set(name)
|
||||||
|
ItemZoneSets[plain(name)]
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.plain(name)
|
||||||
|
name.delete('\- /').downcase
|
||||||
|
end
|
||||||
|
|
||||||
n = 0
|
n = 0
|
||||||
@objects = YAML.load_file(Rails.root.join('config', 'zones.yml')).map do |a|
|
@objects = YAML.load_file(Rails.root.join('config', 'zones.yml')).map do |a|
|
||||||
a['id'] = (n += 1)
|
a['id'] = (n += 1)
|
||||||
obj = new(a)
|
obj = new(a)
|
||||||
if obj.type_id == 2 || obj.type_id == 3
|
if obj.type_id == 2 || obj.type_id == 3
|
||||||
zone_name = obj.label.delete(' -').gsub(/item$/, '').downcase
|
plain_name = plain(obj.label)
|
||||||
ItemZoneSets[zone_name] ||= []
|
|
||||||
ItemZoneSets[zone_name] << obj
|
ItemZoneSets[plain_name] ||= []
|
||||||
|
ItemZoneSets[plain_name] << obj
|
||||||
end
|
end
|
||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
n = nil
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue