Track contributions of Alt Styles
This commit is contained in:
parent
1933046809
commit
4e5023288e
6 changed files with 29 additions and 4 deletions
|
@ -11,7 +11,8 @@ class ContributionsController < ApplicationController
|
||||||
@contributions,
|
@contributions,
|
||||||
:scopes => {
|
:scopes => {
|
||||||
'Item' => Item.includes(:translations),
|
'Item' => Item.includes(:translations),
|
||||||
'PetType' => PetType.includes(:species, :color)
|
'PetType' => PetType.includes(:species, :color),
|
||||||
|
'AltStyle' => AltStyle.includes(:species, :color),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,8 @@ module ContributionHelper
|
||||||
contributed_pet_type('pet_type', contributed, show_image)
|
contributed_pet_type('pet_type', contributed, show_image)
|
||||||
when PetState
|
when PetState
|
||||||
contributed_pet_type('pet_state', contributed.pet_type, show_image)
|
contributed_pet_type('pet_state', contributed.pet_type, show_image)
|
||||||
|
when AltStyle
|
||||||
|
contributed_alt_style(contributed, show_image)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -36,6 +38,20 @@ module ContributionHelper
|
||||||
output << image_tag(sprintf(PET_TYPE_IMAGE_FORMAT, pet_type.image_hash)) if show_image
|
output << image_tag(sprintf(PET_TYPE_IMAGE_FORMAT, pet_type.image_hash)) if show_image
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def contributed_alt_style(alt_style, show_image)
|
||||||
|
span = content_tag(:span, alt_style.name, class: 'contributed-name')
|
||||||
|
output = translate("contributions.contributed_description.main.alt_style_html",
|
||||||
|
alt_style_name: span)
|
||||||
|
# HACK: Just assume this is a Nostalgic Alt Style, and that the thumbnail
|
||||||
|
# is named reliably!
|
||||||
|
if show_image
|
||||||
|
thumbnail_url = "https://images.neopets.com/items/nostalgic_" +
|
||||||
|
"#{alt_style.color.name.downcase}_#{alt_style.species.name.downcase}.gif"
|
||||||
|
output << image_tag(thumbnail_url)
|
||||||
|
end
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,12 @@ class AltStyle < ApplicationRecord
|
||||||
|
|
||||||
has_many :parent_swf_asset_relationships, as: :parent
|
has_many :parent_swf_asset_relationships, as: :parent
|
||||||
has_many :swf_assets, through: :parent_swf_asset_relationships
|
has_many :swf_assets, through: :parent_swf_asset_relationships
|
||||||
|
has_many :contributions, as: :contributed, inverse_of: :contributed
|
||||||
|
|
||||||
|
def name
|
||||||
|
I18n.translate('pet_types.human_name', color_human_name: color.human_name,
|
||||||
|
species_human_name: species.human_name)
|
||||||
|
end
|
||||||
|
|
||||||
def biology=(biology)
|
def biology=(biology)
|
||||||
# TODO: This is very similar to what `PetState` does, but like… much much
|
# TODO: This is very similar to what `PetState` does, but like… much much
|
||||||
|
|
|
@ -3,7 +3,8 @@ class Contribution < ApplicationRecord
|
||||||
'Item' => 3,
|
'Item' => 3,
|
||||||
'SwfAsset' => 2,
|
'SwfAsset' => 2,
|
||||||
'PetType' => 15,
|
'PetType' => 15,
|
||||||
'PetState' => 10
|
'PetState' => 10,
|
||||||
|
'AltStyle' => 30,
|
||||||
}
|
}
|
||||||
|
|
||||||
belongs_to :contributed, :polymorphic => true
|
belongs_to :contributed, :polymorphic => true
|
||||||
|
@ -24,7 +25,7 @@ class Contribution < ApplicationRecord
|
||||||
'SwfAsset' => 'Item',
|
'SwfAsset' => 'Item',
|
||||||
'PetState' => 'PetType'
|
'PetState' => 'PetType'
|
||||||
}
|
}
|
||||||
CONTRIBUTED_CHILDREN = CONTRIBUTED_RELATIONSHIPS.keys
|
CONTRIBUTED_CHILDREN = CONTRIBUTED_RELATIONSHIPS.keys + ['AltStyle']
|
||||||
CONTRIBUTED_TYPES = CONTRIBUTED_CHILDREN + CONTRIBUTED_RELATIONSHIPS.values
|
CONTRIBUTED_TYPES = CONTRIBUTED_CHILDREN + CONTRIBUTED_RELATIONSHIPS.values
|
||||||
def self.preload_contributeds_and_parents(contributions, options={})
|
def self.preload_contributeds_and_parents(contributions, options={})
|
||||||
options[:scopes] ||= {}
|
options[:scopes] ||= {}
|
||||||
|
|
|
@ -79,7 +79,7 @@ class Pet < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def contributables
|
def contributables
|
||||||
contributables = [pet_type, @pet_state]
|
contributables = [pet_type, @pet_state, @alt_style].filter(&:present?)
|
||||||
items.each do |item|
|
items.each do |item|
|
||||||
contributables << item
|
contributables << item
|
||||||
contributables += item.pending_swf_assets
|
contributables += item.pending_swf_assets
|
||||||
|
|
|
@ -232,6 +232,7 @@ en:
|
||||||
swf_asset_html: "%{item_description} on a new body type"
|
swf_asset_html: "%{item_description} on a new body type"
|
||||||
pet_type_html: "%{pet_type_description} for the first time"
|
pet_type_html: "%{pet_type_description} for the first time"
|
||||||
pet_state_html: "a new pose for %{pet_type_description}"
|
pet_state_html: "a new pose for %{pet_type_description}"
|
||||||
|
alt_style_html: "a new Alt Style of the %{alt_style_name}"
|
||||||
|
|
||||||
contribution:
|
contribution:
|
||||||
description_html: "%{user_link} showed us %{contributed_description}"
|
description_html: "%{user_link} showed us %{contributed_description}"
|
||||||
|
|
Loading…
Reference in a new issue