Compare commits
No commits in common. "758b62e7d599c58db0f0b29e90e7a588c57a893b" and "d34bebc336e5bccc5ddc53bc855ccc7ddfdbeffa" have entirely different histories.
758b62e7d5
...
d34bebc336
8 changed files with 7 additions and 81 deletions
|
@ -16,6 +16,7 @@ caption, tbody, tfoot, thead, tr, th, td
|
||||||
margin: 0
|
margin: 0
|
||||||
padding: 0
|
padding: 0
|
||||||
border: 0
|
border: 0
|
||||||
|
outline: 0
|
||||||
font-size: 100%
|
font-size: 100%
|
||||||
vertical-align: baseline
|
vertical-align: baseline
|
||||||
background: transparent
|
background: transparent
|
||||||
|
|
|
@ -61,17 +61,6 @@
|
||||||
text-wrap: balance
|
text-wrap: balance
|
||||||
font-style: italic
|
font-style: italic
|
||||||
|
|
||||||
.subtitle
|
|
||||||
font-size: 85%
|
|
||||||
opacity: .85
|
|
||||||
|
|
||||||
a[title]
|
|
||||||
text-decoration-line: underline
|
|
||||||
text-decoration-style: dotted
|
|
||||||
|
|
||||||
&:hover, &:focus
|
|
||||||
text-decoration-style: solid
|
|
||||||
|
|
||||||
/* For wearable items that belong to a specific set that all come together,
|
/* For wearable items that belong to a specific set that all come together,
|
||||||
* like a Paint Brush. */
|
* like a Paint Brush. */
|
||||||
&[data-group-type="bundle"]
|
&[data-group-type="bundle"]
|
||||||
|
|
|
@ -128,9 +128,6 @@ class ItemsController < ApplicationController
|
||||||
@np_items = @items.select(&:np?)
|
@np_items = @items.select(&:np?)
|
||||||
@pb_items = @items.select(&:pb?)
|
@pb_items = @items.select(&:pb?)
|
||||||
|
|
||||||
# Start loading the NC trade values for the non-Mall NC items.
|
|
||||||
trade_values_task = Async { Item.preload_nc_trade_values(@other_nc_items) }
|
|
||||||
|
|
||||||
# Also, PB items have some special handling: we group them by color, then
|
# 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.
|
# load example pet types for the colors that don't have paint brushes.
|
||||||
@pb_items_by_color = @pb_items.group_by(&:pb_color).
|
@pb_items_by_color = @pb_items.group_by(&:pb_color).
|
||||||
|
@ -147,9 +144,6 @@ class ItemsController < ApplicationController
|
||||||
[color, color.example_pet_type(preferred_species: species)]
|
[color, color.example_pet_type(preferred_species: species)]
|
||||||
end.to_h
|
end.to_h
|
||||||
|
|
||||||
# Finish loading the NC trade values.
|
|
||||||
trade_values_task.wait
|
|
||||||
|
|
||||||
render layout: "application"
|
render layout: "application"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -156,17 +156,6 @@ module ItemsHelper
|
||||||
"Last updated: #{date_str} (#{time_ago_str} ago)"
|
"Last updated: #{date_str} (#{time_ago_str} ago)"
|
||||||
end
|
end
|
||||||
|
|
||||||
def nc_trade_value_subtitle_for(item)
|
|
||||||
value = item.nc_trade_value
|
|
||||||
return nil if value.nil?
|
|
||||||
|
|
||||||
link_to "Owls listing: #{item.nc_trade_value.value_text}",
|
|
||||||
"https://www.neopets.com/~owls",
|
|
||||||
title: 'Owls keeps track of approximate "capsule" values of NC items ' +
|
|
||||||
"for trading. Items with similar values can often be traded for one " +
|
|
||||||
"another. This is an estimate, not a rule!"
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def build_on_pet_types(species, special_color=nil, &block)
|
def build_on_pet_types(species, special_color=nil, &block)
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
require "async"
|
|
||||||
require "async/barrier"
|
|
||||||
|
|
||||||
class Item < ApplicationRecord
|
class Item < ApplicationRecord
|
||||||
include PrettyParam
|
include PrettyParam
|
||||||
|
|
||||||
|
@ -117,25 +114,15 @@ class Item < ApplicationRecord
|
||||||
|
|
||||||
def nc_trade_value
|
def nc_trade_value
|
||||||
return nil unless nc?
|
return nil unless nc?
|
||||||
|
begin
|
||||||
# Load the trade value, if we haven't already. Note that, because the trade
|
|
||||||
# value may be nil, we also save an explicit boolean for whether we've
|
|
||||||
# already looked it up, rather than checking if the saved value is empty.
|
|
||||||
return @nc_trade_value if @nc_trade_value_loaded
|
|
||||||
|
|
||||||
@nc_trade_value = begin
|
|
||||||
Rails.logger.debug "Item #{id} (#{name}) <lookup>"
|
|
||||||
OwlsValueGuide.find_by_name(name)
|
OwlsValueGuide.find_by_name(name)
|
||||||
rescue OwlsValueGuide::NotFound => error
|
rescue OwlsValueGuide::NotFound => error
|
||||||
Rails.logger.debug("No NC trade value listed for #{name} (#{id})")
|
Rails.logger.debug("No NC trade value listed for #{name} (#{id})")
|
||||||
nil
|
return nil
|
||||||
rescue OwlsValueGuide::NetworkError => error
|
rescue OwlsValueGuide::NetworkError => error
|
||||||
Rails.logger.error("Couldn't load nc_trade_value: #{error.full_message}")
|
Rails.logger.error("Couldn't load nc_trade_value: #{error.full_message}")
|
||||||
nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@nc_trade_value_loaded = true
|
|
||||||
@nc_trade_value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return an OrderedHash mapping users to the number of times they
|
# Return an OrderedHash mapping users to the number of times they
|
||||||
|
@ -612,27 +599,6 @@ class Item < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.preload_nc_trade_values(items)
|
|
||||||
# Only allow 10 trade values to be loaded at a time.
|
|
||||||
barrier = Async::Barrier.new
|
|
||||||
semaphore = Async::Semaphore.new(10, parent: barrier)
|
|
||||||
|
|
||||||
Sync do
|
|
||||||
# Load all the trade values in concurrent async tasks. (The
|
|
||||||
# `nc_trade_value` caches the value in the Item object.)
|
|
||||||
items.each do |item|
|
|
||||||
semaphore.async { item.nc_trade_value }
|
|
||||||
end
|
|
||||||
|
|
||||||
# Wait until all tasks are done.
|
|
||||||
barrier.wait
|
|
||||||
ensure
|
|
||||||
barrier.stop # If something goes wrong, clean up all tasks.
|
|
||||||
end
|
|
||||||
|
|
||||||
items
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.collection_from_pet_type_and_registries(pet_type, info_registry, asset_registry, scope=Item.all)
|
def self.collection_from_pet_type_and_registries(pet_type, info_registry, asset_registry, scope=Item.all)
|
||||||
# bear in mind that registries are arrays with many nil elements,
|
# bear in mind that registries are arrays with many nil elements,
|
||||||
# due to how the parser works
|
# due to how the parser works
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
= link_to t('items.show.resources.jn_items'), jn_items_url_for(item)
|
= link_to t('items.show.resources.jn_items'), jn_items_url_for(item)
|
||||||
= link_to t('items.show.resources.impress_2020'), impress_2020_url_for(item)
|
= link_to t('items.show.resources.impress_2020'), impress_2020_url_for(item)
|
||||||
- if item.nc_trade_value
|
- if item.nc_trade_value
|
||||||
= link_to t('items.show.resources.owls', value: item.nc_trade_value_text),
|
= link_to t('items.show.resources.owls', value: item.nc_trade_value.value_text),
|
||||||
"https://www.neopets.com/~owls",
|
"https://www.neopets.com/~owls",
|
||||||
title: nc_trade_value_updated_at_text(item.nc_trade_value)
|
title: nc_trade_value_updated_at_text(item.nc_trade_value)
|
||||||
- unless item.nc?
|
- unless item.nc?
|
||||||
|
|
|
@ -2,8 +2,5 @@
|
||||||
%td.thumbnail-cell
|
%td.thumbnail-cell
|
||||||
= link_to item_thumbnail_for(item), item, target: "_blank",
|
= link_to item_thumbnail_for(item), item, target: "_blank",
|
||||||
tabindex: "-1"
|
tabindex: "-1"
|
||||||
%td.name-cell
|
%td.name-cell= link_to item.name, item, target: "_blank"
|
||||||
= link_to item.name, item, target: "_blank"
|
|
||||||
- if subtitle.present?
|
|
||||||
.subtitle= subtitle
|
|
||||||
%td.actions-cell= yield
|
%td.actions-cell= yield
|
||||||
|
|
|
@ -99,17 +99,7 @@
|
||||||
purchased at all anymore, and can only be obtained via gifts or trades.
|
purchased at all anymore, and can only be obtained via gifts or trades.
|
||||||
|
|
||||||
[mall]: https://ncmall.neopets.com/
|
[mall]: https://ncmall.neopets.com/
|
||||||
%table.item-list
|
= render @other_nc_items
|
||||||
%thead
|
|
||||||
%td
|
|
||||||
%th{colspan: 2}
|
|
||||||
Total: #{pluralize @other_nc_items.size, "item"}
|
|
||||||
%tbody
|
|
||||||
- @other_nc_items.each do |item|
|
|
||||||
= render "item_list_row", item:, subtitle: nc_trade_value_subtitle_for(item) do
|
|
||||||
= button_link_to "NC Trades",
|
|
||||||
item_trades_path(item, type: "offering"),
|
|
||||||
target: "_blank", icon: search_icon
|
|
||||||
|
|
||||||
- content_for :stylesheets do
|
- content_for :stylesheets do
|
||||||
= page_stylesheet_link_tag "items/sources"
|
= page_stylesheet_link_tag "items/sources"
|
||||||
|
|
Loading…
Reference in a new issue