Compare commits

..

No commits in common. "341869fb177be051be5684d6b5fe583803449df4" and "e1c598e591c56a18e5ed207fadb6968ea67138e3" have entirely different histories.

4 changed files with 11 additions and 28 deletions

View file

@ -134,10 +134,10 @@ class ItemsController < ApplicationController
# Also, PB items have some special handling: we group them by color, then
# load example pet types for the colors that don't have paint brushes.
@pb_items_by_color = @pb_items.group_by(&:pb_color).
sort_by { |color, items| color&.name }.to_h
sort_by { |color, items| color.name }.to_h
colors_without_thumbnails = @pb_items_by_color.keys.
select(&:present?).reject(&:pb_item_thumbnail_url?)
colors_without_thumbnails =
@pb_items_by_color.keys.reject(&:pb_item_thumbnail_url?)
@pb_color_pet_types = colors_without_thumbnails.map do |color|
# Infer the ideal species from the first item we can, then try to find a

View file

@ -21,8 +21,7 @@ class Color < ApplicationRecord
end
end
def example_pet_type(preferred_species: nil)
preferred_species ||= Species.first
def example_pet_type(preferred_species: Species.first)
pet_types.order([Arel.sql("species_id = ? DESC"), preferred_species.id],
"species_id ASC").first
end

View file

@ -208,11 +208,7 @@ class Item < ApplicationRecord
end
# If this is a PB item, return the corresponding Color, inferred from the
# item name. If it's not a PB item, or we fail to infer a specific color,
# return nil. (This is expected to be nil for some PB items, like the "Aisha
# Collar", which belong to many colors. It can also be nil for PB items for
# new colors we haven't manually added to the database yet, or if a PB item
# is named strangely in the future.)
# item name. If it's not a PB item, or we fail to infer, return nil.
def pb_color
return nil unless pb?
@ -230,10 +226,7 @@ class Item < ApplicationRecord
end
# If this is a PB item, return the corresponding Species, inferred from the
# item name. If it's not a PB item, or we fail to infer a specific species,
# return nil. (This is not expected to be nil in general, but could be for PB
# items for new species we haven't manually added to the database yet, or if
# a PB item is named strangely in the future.)
# item name. If it's not a PB item, or we fail to infer, return nil.
def pb_species
return nil unless pb?
normalized_name = name.downcase

View file

@ -64,36 +64,27 @@
%table.item-list{"data-group-type": "bundle"}
%thead
%td.thumbnail-cell
- if color&.pb_item_thumbnail_url?
- if color.pb_item_thumbnail_url?
= image_tag color.pb_item_thumbnail_url,
alt: "Item thumbnail for #{color.pb_item_name}"
- elsif color
- else
= image_tag pet_type_image_url(@pb_color_pet_types[color], size: :face),
srcset: ["#{pet_type_image_url(@pb_color_pet_types[color], size: :face_2x)} 2x"],
alt: @pb_color_pet_types[color].human_name
- else
= image_tag "https://images.neopets.com/items/starter_red_pb.gif",
alt: "Item thumbnail for Starter Red Paint Brush"
%th
- if color
#{color.pb_item_name || color.name.humanize}
- else
Basic colors
#{color.pb_item_name || color.name.humanize}
(#{pluralize items.size, "item"})
%td.actions-cell
- if color&.pb_item_name?
- if color.pb_item_name?
= button_link_to "Shops",
shop_wizard_url_for(color.pb_item_name),
target: "_blank", icon: search_icon
= button_link_to "Trades",
trading_post_url_for(color.pb_item_name),
target: "_blank", icon: search_icon
- elsif color
.special-color-explanation
Get via Lab Ray, morphing potions, etc.
- else
.special-color-explanation
Many colors, like Red, will grant these items.
Get via Lab Ray, morphing potions, etc.
%tbody
- items.each do |item|
= render "item_list_row", item: