-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
166 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module PricesHelper | ||
def prices_by_country(games: [], countries:, currency: nil) | ||
prices = games.flat_map(&:prices) | ||
cache = prices.each_with_object({}) do |price, result| | ||
result[price.country] = price.value.exchange_to(currency || 'USD') | ||
end | ||
min, max = cache.values.minmax | ||
|
||
countries.each do |country| | ||
price = prices.detect { |p| p.country == country } | ||
title = "\"#{games.first.title}\" price in #{ISO3166::Country[country].translation('en')}" | ||
if price | ||
options = { | ||
class: (min == cache[country] && 'table-success') || (max == cache[country] && 'table-danger'), | ||
title: title, | ||
} | ||
yield(price.value.exchange_to(currency || price.currency).format, options) | ||
else | ||
yield('N/A', { class: 'text-muted', title: title }) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
table.table.table-responsive | ||
thead.thead-default | ||
tr | ||
th Cover | ||
th Code | ||
th Region | ||
th style="width:100%;min-width:200px" Title | ||
th eShop ID (nsuid) | ||
th Release date | ||
tbody.games | ||
- @games.each do |region, games| | ||
- cover = games.map(&:cover_url).compact.first | ||
- games.each_with_index do |game, index| | ||
tr.game | ||
- if index.zero? | ||
td.game--cover-url rowspan=games.count | ||
= cover ? image_tag("https://assets.calyh.re/resize?url=#{cover}", style: 'max-width:120px;max-height:120px;', class: 'rounded mx-auto d-block', title: 'wat') : nil | ||
td.game--code rowspan=games.count = game.game_code | ||
td.game--region = game.region | ||
td.game--title.text-overflow style="width:100%;max-width:0" title=games.first.title = game.title | ||
td.game--nsuid = game.nsuid || 'NA' | ||
td.game--release-date | ||
time.text-overflow datetime=game.release_date.iso8601 = game.release_date.strftime("%b #{game.release_date.day.ordinalize}, %Y") | ||
- content_for :head_style do | ||
css: | ||
.games { | ||
min-width: 800px; | ||
} | ||
.game-cover { | ||
width: 144px; | ||
} | ||
.game-code { | ||
width: 70px; | ||
} | ||
.game-region { | ||
width: 100px; | ||
} | ||
.game-title { | ||
width: 100%; | ||
} | ||
.game-nsuid { | ||
width: 170px; | ||
} | ||
.game-release-date { | ||
width: 140px; | ||
} | ||
|
||
.scroll-container | ||
table.table | ||
thead.thead-default | ||
tr | ||
th.game-cover Cover | ||
th.game-code Code | ||
th.game-region Region | ||
th.game-title Title | ||
th.game-nsuid eShop ID (nsuid) | ||
th.game-release-date Release date | ||
tbody.games | ||
- @games.each do |region, games| | ||
- cover = games.map(&:cover_url).compact.first | ||
- games.each_with_index do |game, index| | ||
tr.game | ||
- if index.zero? | ||
td.game-cover rowspan=games.count | ||
= cover ? image_tag("https://assets.calyh.re/resize?url=#{cover}", style: 'max-width:120px;max-height:120px;', class: 'rounded mx-auto d-block', title: 'wat') : nil | ||
td.game-code rowspan=games.count = game.game_code | ||
td.game-region = game.region | ||
td.game-title.text-overflow title=games.first.title = game.title | ||
td.game-nsuid.text-overflow title=game.nsuid = game.nsuid || 'NA' | ||
td.game-release-date.text-overflow title=game.release_date.iso8601 | ||
time.text-overflow datetime=game.release_date.iso8601 = game.release_date.strftime("%b #{game.release_date.day.ordinalize}, %Y") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
- content_for :head_style do | ||
css: | ||
td { | ||
font-size: 0.9rem; | ||
} | ||
|
||
- content_for :navbar_right do | ||
ul.navbar-nav | ||
li.nav-item.dropdown | ||
= link_to '#', class: 'nav-link dropdown-toggle', id: 'navbarDropdownMenuLink', data: { toggle: 'dropdown' }, aria: { haspopup: true, expanded: false } do | ||
- if @currency.nil? | ||
| Change currency | ||
- else | ||
= ISO3166::Country.find_country_by_currency(@currency).currency.name | ||
.dropdown-menu.dropdown-menu-right aria-labelledby="navbarDropdownMenuLink" | ||
- unless @currency.nil? | ||
= link_to 'In original currency', prices_url, class: 'dropdown-item' | ||
.dropdown-divider | ||
- @currencies.each do |currency| | ||
- next if @currency === currency | ||
= link_to ISO3166::Country.find_country_by_currency(currency).currency.name, prices_url(currency: currency), class: 'dropdown-item' | ||
|
||
.scroll-container | ||
table.table.table-hover | ||
thead.thead-default | ||
tr | ||
th.column--frozen Game | ||
- @countries.each do |code| | ||
- country = ISO3166::Country[code] | ||
th.game-country.text-right style="width: 110px" title=country.unofficial_names.first | ||
.text-centered | ||
span.emoji = country.emoji_flag | ||
= country.alpha3 | ||
tbody.games | ||
- @games.each do |region, games| | ||
tr.game title=games.first.title | ||
td.game-title.column--frozen.text-overflow = games.first.title | ||
- prices_by_country(games: games, countries: @countries, currency: @currency) do |price, options| | ||
td.text-overflow.text-right style="width: 110px" title=options[:title] class=options[:class] = price |