forked from OpenNeo/impress
Add restricts filter back to item search
This commit is contained in:
parent
d952685c5d
commit
b244057808
2 changed files with 26 additions and 4 deletions
|
@ -65,13 +65,13 @@ class Item < ActiveRecord::Base
|
|||
}
|
||||
scope :is_pb, -> {
|
||||
it = Item::Translation.arel_table
|
||||
Item.joins(:translations).where(it[:locale].eq('en')).
|
||||
joins(:translations).where(it[:locale].eq('en')).
|
||||
where('description LIKE ?',
|
||||
'%' + Item.sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
||||
}
|
||||
scope :is_not_pb, -> {
|
||||
it = Item::Translation.arel_table
|
||||
Item.joins(:translations).where(it[:locale].eq('en')).
|
||||
joins(:translations).where(it[:locale].eq('en')).
|
||||
where('description NOT LIKE ?',
|
||||
'%' + Item.sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class Item < ActiveRecord::Base
|
|||
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
|
||||
i = Item.arel_table
|
||||
sa = SwfAsset.arel_table
|
||||
Item.joins(:swf_assets).where(sa[:zone_id].in(zone_ids)).distinct
|
||||
joins(:swf_assets).where(sa[:zone_id].in(zone_ids)).distinct
|
||||
}
|
||||
scope :not_occupies, ->(zone_label, locale = I18n.locale) {
|
||||
# TODO: The perf on this is miserable on its own, the query plan chooses
|
||||
|
@ -89,7 +89,17 @@ class Item < ActiveRecord::Base
|
|||
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
|
||||
i = Item.arel_table
|
||||
sa = SwfAsset.arel_table
|
||||
Item.joins(:swf_assets).where(sa[:zone_id].not_in(zone_ids)).distinct
|
||||
joins(:swf_assets).where(sa[:zone_id].not_in(zone_ids)).distinct
|
||||
}
|
||||
scope :restricts, ->(zone_label, locale = I18n.locale) {
|
||||
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
|
||||
condition = zone_ids.map { '(SUBSTR(zones_restrict, ?, 1) = "1")' }.join(' OR ')
|
||||
where(condition, *zone_ids)
|
||||
}
|
||||
scope :not_restricts, ->(zone_label, locale = I18n.locale) {
|
||||
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
|
||||
condition = zone_ids.map { '(SUBSTR(zones_restrict, ?, 1) = "1")' }.join(' OR ')
|
||||
where("NOT (#{condition})", *zone_ids)
|
||||
}
|
||||
|
||||
def closeted?
|
||||
|
|
|
@ -42,6 +42,10 @@ class Item
|
|||
filters << (is_positive ?
|
||||
Filter.occupies(value, locale) :
|
||||
Filter.not_occupies(value, locale))
|
||||
when 'restricts'
|
||||
filters << (is_positive ?
|
||||
Filter.restricts(value, locale) :
|
||||
Filter.not_restricts(value, locale))
|
||||
when 'is'
|
||||
case value
|
||||
when 'nc'
|
||||
|
@ -113,6 +117,14 @@ class Item
|
|||
self.new Item.not_occupies(value, locale), "-occupies:#{value}"
|
||||
end
|
||||
|
||||
def self.restricts(value, locale)
|
||||
self.new Item.restricts(value, locale), "restricts:#{value}"
|
||||
end
|
||||
|
||||
def self.not_restricts(value, locale)
|
||||
self.new Item.not_restricts(value, locale), "-restricts:#{value}"
|
||||
end
|
||||
|
||||
def self.is_nc
|
||||
self.new Item.is_nc, 'is:nc'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue