Compare commits

..

No commits in common. "0cad34acfc7d8d697973473b280807475585beb6" and "48f613d9bc6519d1d22998ea28897b20d32cce4c" have entirely different histories.

6 changed files with 32 additions and 67 deletions

View file

@ -68,13 +68,13 @@ class Item < ApplicationRecord
where('description NOT LIKE ?',
'%' + sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
}
scope :occupies, ->(zone_label) {
zone_ids = Zone.matching_label(zone_label).map(&:id)
scope :occupies, ->(zone_label, locale = I18n.locale) {
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
sa = SwfAsset.arel_table
joins(:swf_assets).where(sa[:zone_id].in(zone_ids)).distinct
}
scope :not_occupies, ->(zone_label) {
zone_ids = Zone.matching_label(zone_label).map(&:id)
scope :not_occupies, ->(zone_label, locale = I18n.locale) {
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
i = Item.arel_table
sa = SwfAsset.arel_table
# Querying for "has NO swf_assets matching these zone IDs" is trickier than
@ -87,13 +87,13 @@ class Item < ApplicationRecord
condition = zone_ids.map { 'FIND_IN_SET(?, GROUP_CONCAT(zone_id)) = 0' }.join(' AND ')
joins(:swf_assets).group(i[:id]).having(condition, *zone_ids).distinct
}
scope :restricts, ->(zone_label) {
zone_ids = Zone.matching_label(zone_label).map(&:id)
scope :restricts, ->(zone_label, locale = I18n.locale) {
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
condition = zone_ids.map { '(SUBSTR(items.zones_restrict, ?, 1) = "1")' }.join(' OR ')
where(condition, *zone_ids)
}
scope :not_restricts, ->(zone_label) {
zone_ids = Zone.matching_label(zone_label).map(&:id)
scope :not_restricts, ->(zone_label, locale = I18n.locale) {
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
condition = zone_ids.map { '(SUBSTR(items.zones_restrict, ?, 1) = "1")' }.join(' OR ')
where("NOT (#{condition})", *zone_ids)
}

View file

@ -40,12 +40,12 @@ class Item
Filter.name_excludes(value, locale))
when 'occupies'
filters << (is_positive ?
Filter.occupies(value) :
Filter.not_occupies(value))
Filter.occupies(value, locale) :
Filter.not_occupies(value, locale))
when 'restricts'
filters << (is_positive ?
Filter.restricts(value) :
Filter.not_restricts(value))
Filter.restricts(value, locale) :
Filter.not_restricts(value, locale))
when 'fits'
color_name, species_name = value.split('-')
begin
@ -196,20 +196,20 @@ class Item
self.new Item.name_excludes(value, locale), "-#{q value}"
end
def self.occupies(value)
self.new Item.occupies(value), "occupies:#{q value}"
def self.occupies(value, locale)
self.new Item.occupies(value, locale), "occupies:#{q value}"
end
def self.not_occupies(value)
self.new Item.not_occupies(value), "-occupies:#{q value}"
def self.not_occupies(value, locale)
self.new Item.not_occupies(value, locale), "-occupies:#{q value}"
end
def self.restricts(value)
self.new Item.restricts(value), "restricts:#{q value}"
def self.restricts(value, locale)
self.new Item.restricts(value, locale), "restricts:#{q value}"
end
def self.not_restricts(value)
self.new Item.not_restricts(value), "-restricts:#{q value}"
def self.not_restricts(value, locale)
self.new Item.not_restricts(value, locale), "-restricts:#{q value}"
end
def self.fits(body_id, color_name, species_name)

View file

@ -1,36 +1,23 @@
class Zone < ActiveRecord::Base
translates # TODO: Remove once we're all done with translations!
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, -> { order(:label) }
scope :matching_label, ->(label) {
where(plain_label: Zone.plainify_label(label))
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)) }
# 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
def as_json(options={})
super({only: [:id, :depth, :label]}.merge(options))
end

View file

@ -2,10 +2,6 @@
= advertise_campaign_progress @campaign
.notice
%strong Happy NC UC day!
We're working on some changes to get everything set up, see you soon! 💖
%p#pet-not-found.alert= t 'pets.load.not_found'
#outfit-forms

View file

@ -1,16 +0,0 @@
class AddLabelAndPlainLabelToZones < ActiveRecord::Migration[7.1]
def change
add_column :zones, :label, :string, null: false
add_column :zones, :plain_label, :string, null: false
reversible do |direction|
direction.up do
Zone.includes(:translations).find_each do |zone|
zone.label = zone.translation_for(:en).label
zone.plain_label = zone.translation_for(:en).plain_label
zone.save!
end
end
end
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_01_23_133215) do
ActiveRecord::Schema[7.1].define(version: 2024_01_23_125509) do
create_table "auth_servers", id: :integer, charset: "latin1", collation: "latin1_swedish_ci", force: :cascade do |t|
t.string "short_name", limit: 10, null: false
t.string "name", limit: 40, null: false
@ -297,8 +297,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_23_133215) do
create_table "zones", id: :integer, charset: "latin1", collation: "latin1_swedish_ci", force: :cascade do |t|
t.integer "depth"
t.integer "type_id"
t.string "label", null: false
t.string "plain_label", null: false
end
end