forked from OpenNeo/impress
Matchu
010f64264f
Preparing a better endpoint for wardrobe-2020 to use! I deleted the now-unused swf_assets#index endpoint, and replaced it with an "appearances" concept that isn't exactly reflected in the database models but is a _lot_ easier for clients to work with imo. Note that this was a big part of the motivation for the recent `manifest_url` work—in this draft, I'm probably gonna have the client request the manifest, rather than use impress-2020's trick of caching it in the database! There's a bit of a perf penalty, but I think that's a simpler starting point, and I have a hunch I'll be able to make up the perf difference once we have the impress-media-server managing more of these responsibilities.
32 lines
971 B
Ruby
32 lines
971 B
Ruby
class Zone < ActiveRecord::Base
|
|
translates :label, :plain_label
|
|
|
|
# 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
|
|
|
|
scope :alphabetical, -> {
|
|
zt = Zone::Translation.arel_table
|
|
with_translations(I18n.locale).order(zt[:label].asc)
|
|
}
|
|
scope :includes_translations, -> { includes(:translations) }
|
|
scope :matching_label, ->(label, locale = I18n.locale) {
|
|
t = Zone::Translation.arel_table
|
|
joins(:translations)
|
|
.where(t[:locale].eq(locale))
|
|
.where(t[:plain_label].eq(Zone.plainify_label(label)))
|
|
}
|
|
scope :for_items, -> { where(arel_table[:type_id].gt(1)) }
|
|
|
|
def as_json(options={})
|
|
super({only: [:id, :depth, :label]}.merge(options))
|
|
end
|
|
|
|
def uncertain_label
|
|
@sometimes ? "#{label} sometimes" : label
|
|
end
|
|
|
|
def self.plainify_label(label)
|
|
label.delete('\- /').parameterize
|
|
end
|
|
end
|