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, -> {
|
scope :is_pb, -> {
|
||||||
it = Item::Translation.arel_table
|
it = Item::Translation.arel_table
|
||||||
Item.joins(:translations).where(it[:locale].eq('en')).
|
joins(:translations).where(it[:locale].eq('en')).
|
||||||
where('description LIKE ?',
|
where('description LIKE ?',
|
||||||
'%' + Item.sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
'%' + Item.sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
||||||
}
|
}
|
||||||
scope :is_not_pb, -> {
|
scope :is_not_pb, -> {
|
||||||
it = Item::Translation.arel_table
|
it = Item::Translation.arel_table
|
||||||
Item.joins(:translations).where(it[:locale].eq('en')).
|
joins(:translations).where(it[:locale].eq('en')).
|
||||||
where('description NOT LIKE ?',
|
where('description NOT LIKE ?',
|
||||||
'%' + Item.sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
'%' + 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)
|
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
|
||||||
i = Item.arel_table
|
i = Item.arel_table
|
||||||
sa = SwfAsset.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) {
|
scope :not_occupies, ->(zone_label, locale = I18n.locale) {
|
||||||
# TODO: The perf on this is miserable on its own, the query plan chooses
|
# 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)
|
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
|
||||||
i = Item.arel_table
|
i = Item.arel_table
|
||||||
sa = SwfAsset.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?
|
def closeted?
|
||||||
|
|
|
@ -42,6 +42,10 @@ class Item
|
||||||
filters << (is_positive ?
|
filters << (is_positive ?
|
||||||
Filter.occupies(value, locale) :
|
Filter.occupies(value, locale) :
|
||||||
Filter.not_occupies(value, locale))
|
Filter.not_occupies(value, locale))
|
||||||
|
when 'restricts'
|
||||||
|
filters << (is_positive ?
|
||||||
|
Filter.restricts(value, locale) :
|
||||||
|
Filter.not_restricts(value, locale))
|
||||||
when 'is'
|
when 'is'
|
||||||
case value
|
case value
|
||||||
when 'nc'
|
when 'nc'
|
||||||
|
@ -113,6 +117,14 @@ class Item
|
||||||
self.new Item.not_occupies(value, locale), "-occupies:#{value}"
|
self.new Item.not_occupies(value, locale), "-occupies:#{value}"
|
||||||
end
|
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
|
def self.is_nc
|
||||||
self.new Item.is_nc, 'is:nc'
|
self.new Item.is_nc, 'is:nc'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue