2023-08-02 16:05:02 -07:00
|
|
|
class Zone < ApplicationRecord
|
2013-01-21 17:34:39 -08:00
|
|
|
translates :label, :plain_label
|
2010-06-09 19:56:47 -07:00
|
|
|
|
2010-09-08 19:49:39 -07:00
|
|
|
# When selecting zones that an asset occupies, we allow the zone to set
|
|
|
|
# whether or not the zone is "sometimes" occupied. This is false by default.
|
|
|
|
attr_writer :sometimes
|
2013-01-21 17:34:39 -08:00
|
|
|
|
2023-07-22 14:04:01 -07:00
|
|
|
scope :alphabetical, -> {
|
2013-01-26 22:25:52 -08:00
|
|
|
with_translations(I18n.locale).order(Zone::Translation.arel_table[:label])
|
2013-01-21 17:34:39 -08:00
|
|
|
}
|
2023-07-22 14:04:01 -07:00
|
|
|
scope :includes_translations, -> { includes(:translations) }
|
2023-07-26 12:28:25 -07:00
|
|
|
scope :matching_label, ->(label, locale = I18n.locale) {
|
2013-01-21 17:34:39 -08:00
|
|
|
t = Zone::Translation.arel_table
|
2023-07-26 12:28:25 -07:00
|
|
|
joins(:translations)
|
|
|
|
.where(t[:locale].eq(locale))
|
fix the necklace/collar advanced search bug!
Ooh, this one was nasty, and only one symptom ever got noticed:
1. Pick "Occupies: Collar" in Advanced Search.
You get the text query "occupies:necklace".
2. And, if you try to do "occupies:collar" even in text-based search,
you *also* get the results from "occupies:necklace" mixed in with
the correct results.
The trick is that, in Spanish, zone 24 (necklace) is named "collar",
as is zone 27 (collar). Not sure what to do for Spanish, but this
issue also leaked into English: we really don't want English to return
results for Spanish-named zones.
This is a tricky problem, though, because it'd be nice for es users
to be able to type "occupies:hat". I think we'll have to do the quick
fix for now, though, and just only interpret the query in the current
locale.
2015-09-24 19:51:45 -07:00
|
|
|
.where(t[:plain_label].eq(Zone.plainify_label(label)))
|
2013-01-21 17:34:39 -08:00
|
|
|
}
|
2023-07-22 14:04:01 -07:00
|
|
|
scope :for_items, -> { where(arel_table[:type_id].gt(1)) }
|
2014-04-02 18:56:42 -07:00
|
|
|
|
2010-09-08 19:49:39 -07:00
|
|
|
def uncertain_label
|
|
|
|
@sometimes ? "#{label} sometimes" : label
|
|
|
|
end
|
|
|
|
|
2013-01-21 17:34:39 -08:00
|
|
|
def self.plainify_label(label)
|
2013-01-26 07:54:29 -08:00
|
|
|
label.delete('\- /').parameterize
|
2012-10-08 19:20:18 -07:00
|
|
|
end
|
2010-05-20 16:04:56 -07:00
|
|
|
end
|