Compare commits
No commits in common. "0cad34acfc7d8d697973473b280807475585beb6" and "48f613d9bc6519d1d22998ea28897b20d32cce4c" have entirely different histories.
0cad34acfc
...
48f613d9bc
6 changed files with 32 additions and 67 deletions
|
@ -68,13 +68,13 @@ class Item < ApplicationRecord
|
||||||
where('description NOT LIKE ?',
|
where('description NOT LIKE ?',
|
||||||
'%' + sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
'%' + sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
||||||
}
|
}
|
||||||
scope :occupies, ->(zone_label) {
|
scope :occupies, ->(zone_label, locale = I18n.locale) {
|
||||||
zone_ids = Zone.matching_label(zone_label).map(&:id)
|
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
|
||||||
sa = SwfAsset.arel_table
|
sa = SwfAsset.arel_table
|
||||||
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) {
|
scope :not_occupies, ->(zone_label, locale = I18n.locale) {
|
||||||
zone_ids = Zone.matching_label(zone_label).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
|
||||||
# Querying for "has NO swf_assets matching these zone IDs" is trickier than
|
# 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 ')
|
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
|
joins(:swf_assets).group(i[:id]).having(condition, *zone_ids).distinct
|
||||||
}
|
}
|
||||||
scope :restricts, ->(zone_label) {
|
scope :restricts, ->(zone_label, locale = I18n.locale) {
|
||||||
zone_ids = Zone.matching_label(zone_label).map(&:id)
|
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
|
||||||
condition = zone_ids.map { '(SUBSTR(items.zones_restrict, ?, 1) = "1")' }.join(' OR ')
|
condition = zone_ids.map { '(SUBSTR(items.zones_restrict, ?, 1) = "1")' }.join(' OR ')
|
||||||
where(condition, *zone_ids)
|
where(condition, *zone_ids)
|
||||||
}
|
}
|
||||||
scope :not_restricts, ->(zone_label) {
|
scope :not_restricts, ->(zone_label, locale = I18n.locale) {
|
||||||
zone_ids = Zone.matching_label(zone_label).map(&:id)
|
zone_ids = Zone.matching_label(zone_label, locale).map(&:id)
|
||||||
condition = zone_ids.map { '(SUBSTR(items.zones_restrict, ?, 1) = "1")' }.join(' OR ')
|
condition = zone_ids.map { '(SUBSTR(items.zones_restrict, ?, 1) = "1")' }.join(' OR ')
|
||||||
where("NOT (#{condition})", *zone_ids)
|
where("NOT (#{condition})", *zone_ids)
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,12 @@ class Item
|
||||||
Filter.name_excludes(value, locale))
|
Filter.name_excludes(value, locale))
|
||||||
when 'occupies'
|
when 'occupies'
|
||||||
filters << (is_positive ?
|
filters << (is_positive ?
|
||||||
Filter.occupies(value) :
|
Filter.occupies(value, locale) :
|
||||||
Filter.not_occupies(value))
|
Filter.not_occupies(value, locale))
|
||||||
when 'restricts'
|
when 'restricts'
|
||||||
filters << (is_positive ?
|
filters << (is_positive ?
|
||||||
Filter.restricts(value) :
|
Filter.restricts(value, locale) :
|
||||||
Filter.not_restricts(value))
|
Filter.not_restricts(value, locale))
|
||||||
when 'fits'
|
when 'fits'
|
||||||
color_name, species_name = value.split('-')
|
color_name, species_name = value.split('-')
|
||||||
begin
|
begin
|
||||||
|
@ -196,20 +196,20 @@ class Item
|
||||||
self.new Item.name_excludes(value, locale), "-#{q value}"
|
self.new Item.name_excludes(value, locale), "-#{q value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.occupies(value)
|
def self.occupies(value, locale)
|
||||||
self.new Item.occupies(value), "occupies:#{q value}"
|
self.new Item.occupies(value, locale), "occupies:#{q value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.not_occupies(value)
|
def self.not_occupies(value, locale)
|
||||||
self.new Item.not_occupies(value), "-occupies:#{q value}"
|
self.new Item.not_occupies(value, locale), "-occupies:#{q value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.restricts(value)
|
def self.restricts(value, locale)
|
||||||
self.new Item.restricts(value), "restricts:#{q value}"
|
self.new Item.restricts(value, locale), "restricts:#{q value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.not_restricts(value)
|
def self.not_restricts(value, locale)
|
||||||
self.new Item.not_restricts(value), "-restricts:#{q value}"
|
self.new Item.not_restricts(value, locale), "-restricts:#{q value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.fits(body_id, color_name, species_name)
|
def self.fits(body_id, color_name, species_name)
|
||||||
|
|
|
@ -1,36 +1,23 @@
|
||||||
class Zone < ActiveRecord::Base
|
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
|
# 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.
|
# whether or not the zone is "sometimes" occupied. This is false by default.
|
||||||
attr_writer :sometimes
|
attr_writer :sometimes
|
||||||
|
|
||||||
scope :alphabetical, -> { order(:label) }
|
scope :alphabetical, -> {
|
||||||
scope :matching_label, ->(label) {
|
zt = Zone::Translation.arel_table
|
||||||
where(plain_label: Zone.plainify_label(label))
|
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)) }
|
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={})
|
def as_json(options={})
|
||||||
super({only: [:id, :depth, :label]}.merge(options))
|
super({only: [:id, :depth, :label]}.merge(options))
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,10 +2,6 @@
|
||||||
|
|
||||||
= advertise_campaign_progress @campaign
|
= 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'
|
%p#pet-not-found.alert= t 'pets.load.not_found'
|
||||||
|
|
||||||
#outfit-forms
|
#outfit-forms
|
||||||
|
|
|
@ -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
|
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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|
|
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 "short_name", limit: 10, null: false
|
||||||
t.string "name", limit: 40, 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|
|
create_table "zones", id: :integer, charset: "latin1", collation: "latin1_swedish_ci", force: :cascade do |t|
|
||||||
t.integer "depth"
|
t.integer "depth"
|
||||||
t.integer "type_id"
|
t.integer "type_id"
|
||||||
t.string "label", null: false
|
|
||||||
t.string "plain_label", null: false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue