2023-08-02 16:29:31 -07:00
|
|
|
class Zone < ActiveRecord::Base
|
2024-01-23 05:43:00 -08:00
|
|
|
translates # TODO: Remove once we're all done with translations!
|
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
|
|
|
|
2024-01-23 05:43:00 -08:00
|
|
|
scope :alphabetical, -> { order(:label) }
|
|
|
|
scope :matching_label, ->(label) {
|
|
|
|
where(plain_label: 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
|
|
|
|
2024-01-23 05:43:00 -08:00
|
|
|
# Temporary writer to keep the English translation record updated, while
|
|
|
|
# primarily using the attribute on the model itself.
|
|
|
|
#
|
|
|
|
# Once this app and DTI 2020 are both comfortably off the translation system,
|
|
|
|
# we can remove this!
|
|
|
|
def label=(new_label)
|
|
|
|
globalize.write(:en, :label, new_label)
|
|
|
|
write_attribute(:label, new_label)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Temporary writer to keep the English translation record updated, while
|
|
|
|
# primarily using the attribute on the model itself.
|
|
|
|
#
|
|
|
|
# Once this app and DTI 2020 are both comfortably off the translation system,
|
|
|
|
# we can remove this!
|
|
|
|
def plain_label=(new_plain_label)
|
|
|
|
globalize.write(:en, :plain_label, new_plain_label)
|
|
|
|
write_attribute(:plain_label, new_plain_label)
|
|
|
|
end
|
|
|
|
|
2023-11-11 07:14:48 -08:00
|
|
|
def as_json(options={})
|
|
|
|
super({only: [:id, :depth, :label]}.merge(options))
|
|
|
|
end
|
|
|
|
|
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
|