From f56b544963281aefa6c840c7718716d5697c6494 Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 24 Oct 2012 22:09:05 -0500 Subject: [PATCH] brought-to-you-by on items#show lists contributors --- app/controllers/items_controller.rb | 3 + app/helpers/items_helper.rb | 4 ++ app/models/contribution_observer.rb | 5 ++ app/models/item.rb | 26 +++++++ app/stylesheets/items/_show.sass | 18 +++++ app/stylesheets/outfits/_new.sass | 9 +-- app/stylesheets/partials/clean/_mixins.sass | 10 +++ app/views/items/show.html.haml | 9 +++ config/initializers/activemerchant.rb | 21 ++++++ public/stylesheets/compiled/screen.css | 75 ++++++++++++++++----- 10 files changed, 156 insertions(+), 24 deletions(-) create mode 100644 config/initializers/activemerchant.rb diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index eb56a5c1..c26b7919 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -48,6 +48,9 @@ class ItemsController < ApplicationController respond_to do |format| format.html do + unless fragment_exist?("items/#{@item.id} contributors") + @contributors_with_counts = @item.contributors_with_counts + end @trading_closet_hangers_by_owned = { true => @item.closet_hangers.owned_trading.newest.includes(:user), diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index 57302af2..3cc21aa1 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -108,6 +108,10 @@ module ItemsHelper link_to hanger.user.name, user_closet_hangers_path(hanger.user) end.to_sentence.html_safe end + + def format_contribution_count(count) + "(×#{count})".html_safe if count > 1 + end private diff --git a/app/models/contribution_observer.rb b/app/models/contribution_observer.rb index 52f23c93..8fd87b3b 100644 --- a/app/models/contribution_observer.rb +++ b/app/models/contribution_observer.rb @@ -1,6 +1,11 @@ class ContributionObserver < ActiveRecord::Observer def after_create(contribution) controller.expire_fragment('outfits#new latest_contribution') + + if contribution.contributed_type == 'SwfAsset' + item = contribution.contributed.item + controller.expire_fragment("items/#{item.id} contributors") + end end private diff --git a/app/models/item.rb b/app/models/item.rb index bb5ffe2e..0cf42c48 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -42,6 +42,32 @@ class Item < ActiveRecord::Base def closeted? @owned || @wanted end + + # Return an OrderedHash mapping users to the number of times they + # contributed to this item's assets, from most contributions to least. + def contributors_with_counts + # Get contributing users' IDs + swf_asset_ids = swf_assets.select(SwfAsset.arel_table[:id]).map(&:id) + swf_asset_contributions = Contribution.select('user_id'). + where(:contributed_type => 'SwfAsset', :contributed_id => swf_asset_ids) + contributor_ids = swf_asset_contributions.map(&:user_id) + + # Get the users, mapped by ID + contributors_by_id = {} + User.find(contributor_ids).each { |u| contributors_by_id[u.id] = u } + + # Count each user's contributions + contributor_counts_by_id = Hash.new(0) + contributor_ids.each { |id| contributor_counts_by_id[id] += 1 } + + # Build an OrderedHash mapping users to counts in descending order + contributors_with_counts = ActiveSupport::OrderedHash.new + contributor_counts_by_id.sort_by { |k, v| v }.reverse.each do |id, count| + contributor = contributors_by_id[id] + contributors_with_counts[contributor] = count + end + contributors_with_counts + end def nc? NCRarities.include?(rarity_index) diff --git a/app/stylesheets/items/_show.sass b/app/stylesheets/items/_show.sass index 849359f9..453b952f 100644 --- a/app/stylesheets/items/_show.sass +++ b/app/stylesheets/items/_show.sass @@ -108,6 +108,24 @@ body.items-show .less display: none + + #item-contributors + +subtle-banner + clear: both + + header + display: inline + font-weight: bold + margin-right: .25em + + footer + display: inline + + ul + +comma-delimited-list + + li:last-child::after + content: "." #item-preview-header clear: both diff --git a/app/stylesheets/outfits/_new.sass b/app/stylesheets/outfits/_new.sass index f5826bd6..ef873876 100644 --- a/app/stylesheets/outfits/_new.sass +++ b/app/stylesheets/outfits/_new.sass @@ -198,14 +198,7 @@ body.outfits-new width: 80px #latest-contribution - border: - color: $soft-border-color - style: solid - width: 1px 0 - font-size: 85% - margin: 1em 0 - padding: .5em 0 - text-align: center + +subtle-banner #recent-contributions-link font-weight: bold diff --git a/app/stylesheets/partials/clean/_mixins.sass b/app/stylesheets/partials/clean/_mixins.sass index 428d7cd4..d599dee8 100644 --- a/app/stylesheets/partials/clean/_mixins.sass +++ b/app/stylesheets/partials/clean/_mixins.sass @@ -106,3 +106,13 @@ background: $warning-bg-color border: 1px solid $warning-border-color color: $warning-color + +=subtle-banner + border: + color: $soft-border-color + style: solid + width: 1px 0 + font-size: 85% + margin: 1em 0 + padding: .5em 0 + text-align: center diff --git a/app/views/items/show.html.haml b/app/views/items/show.html.haml index 96ab2750..d0c1b62f 100644 --- a/app/views/items/show.html.haml +++ b/app/views/items/show.html.haml @@ -89,6 +89,15 @@ %span.more more %span.less less +- cache "items/#{@item.id} contributors" do + - unless @contributors_with_counts.empty? + #item-contributors + %header Brought to you by: + %ul + - @contributors_with_counts.each do |contributor, count| + %li #{link_to contributor.name, user_contributions_path(contributor)} #{format_contribution_count(count)} + %footer Thanks, everybody! + - cache 'items#show preview_header' do #item-preview-header %h3 Preview diff --git a/config/initializers/activemerchant.rb b/config/initializers/activemerchant.rb new file mode 100644 index 00000000..01dedf2c --- /dev/null +++ b/config/initializers/activemerchant.rb @@ -0,0 +1,21 @@ +if defined? ActiveMerchant + if Rails.env.development? + ActiveMerchant::Billing::Base.mode = :test + paypal_options = { + :login => "dti00_1309660809_biz_api1.gmail.com", + :password => "1309660841", + :signature => "A8hoaApkuosyp0eSB5fO.FMMFsFPA2E9DtCZkbNkmIuVRqeOmTOzXqQQ" + } + elsif Rails.env.production? + ActiveMerchant::Billing::Base.mode = :production + paypal_options = { + :login => "matchu1993_api1.gmail.com", + :password => "JCJ2NK5DTBZ94QNP", + :signature => "AFcWxV21C7fd0v3bYYYRCpSSRl31AFGfnit6OH.i894Lf4Bgc81N2lfc" + } + else + raise RuntimeError, "ActiveMerchant is not configured for #{Rails.env}. See config/initializers/activemerchant.rb" + end + + ::DONATION_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options) +end diff --git a/public/stylesheets/compiled/screen.css b/public/stylesheets/compiled/screen.css index 54fcbe5c..5c801bb7 100644 --- a/public/stylesheets/compiled/screen.css +++ b/public/stylesheets/compiled/screen.css @@ -1935,10 +1935,53 @@ body.items-show #trade-hangers .toggle .less { display: none; } /* line 112, ../../../app/stylesheets/items/_show.sass */ +body.items-show #item-contributors { + border-color: #aaddaa; + border-style: solid; + border-width: 1px 0; + font-size: 85%; + margin: 1em 0; + padding: 0.5em 0; + text-align: center; + clear: both; +} +/* line 116, ../../../app/stylesheets/items/_show.sass */ +body.items-show #item-contributors header { + display: inline; + font-weight: bold; + margin-right: 0.25em; +} +/* line 121, ../../../app/stylesheets/items/_show.sass */ +body.items-show #item-contributors footer { + display: inline; +} +/* line 124, ../../../app/stylesheets/items/_show.sass */ +body.items-show #item-contributors ul { + list-style-type: none; +} +/* line 5, ../../../../../../.rvm/gems/ruby-1.9.2-p290/gems/compass-0.10.6/frameworks/compass/stylesheets/compass/utilities/lists/_inline-list.scss */ +body.items-show #item-contributors ul, body.items-show #item-contributors ul li { + margin: 0px; + padding: 0px; + display: inline; +} +/* line 24, ../../../../../../.rvm/gems/ruby-1.9.2-p290/gems/compass-0.10.6/frameworks/compass/stylesheets/compass/utilities/lists/_inline-list.scss */ +body.items-show #item-contributors ul li:after { + content: ", "; +} +/* line 26, ../../../../../../.rvm/gems/ruby-1.9.2-p290/gems/compass-0.10.6/frameworks/compass/stylesheets/compass/utilities/lists/_inline-list.scss */ +body.items-show #item-contributors ul li:last-child:after, body.items-show #item-contributors ul li.last:after { + content: ""; +} +/* line 127, ../../../app/stylesheets/items/_show.sass */ +body.items-show #item-contributors ul li:last-child::after { + content: "."; +} +/* line 130, ../../../app/stylesheets/items/_show.sass */ body.items-show #item-preview-header { clear: both; } -/* line 115, ../../../app/stylesheets/items/_show.sass */ +/* line 133, ../../../app/stylesheets/items/_show.sass */ body.items-show #item-preview-header h3, body.items-show #item-preview-header a { display: -moz-inline-box; -moz-box-orient: vertical; @@ -1950,17 +1993,17 @@ body.items-show #item-preview-header h3, body.items-show #item-preview-header a body.items-show #item-preview-header h3, body.items-show #item-preview-header a { *display: inline; } -/* line 117, ../../../app/stylesheets/items/_show.sass */ +/* line 135, ../../../app/stylesheets/items/_show.sass */ body.items-show #item-preview-header a { font-size: 85%; margin: -1.5em 0 0 1em; } -/* line 121, ../../../app/stylesheets/items/_show.sass */ +/* line 139, ../../../app/stylesheets/items/_show.sass */ body.items-show .nc-icon { height: 16px; width: 16px; } -/* line 125, ../../../app/stylesheets/items/_show.sass */ +/* line 143, ../../../app/stylesheets/items/_show.sass */ body.items-show #closet-hangers { border: 1px solid #006600; float: right; @@ -1972,13 +2015,13 @@ body.items-show #closet-hangers { position: relative; z-index: 2; } -/* line 138, ../../../app/stylesheets/items/_show.sass */ +/* line 156, ../../../app/stylesheets/items/_show.sass */ body.items-show #closet-hangers h3 { font-size: 150%; font-weight: bold; margin-bottom: 0.25em; } -/* line 143, ../../../app/stylesheets/items/_show.sass */ +/* line 161, ../../../app/stylesheets/items/_show.sass */ body.items-show #closet-hangers #closet-hangers-ownership-groups { overflow: hidden; display: inline-block; @@ -1988,41 +2031,41 @@ body.items-show #closet-hangers #closet-hangers-ownership-groups { body.items-show #closet-hangers #closet-hangers-ownership-groups { display: block; } -/* line 147, ../../../app/stylesheets/items/_show.sass */ +/* line 165, ../../../app/stylesheets/items/_show.sass */ body.items-show #closet-hangers #closet-hangers-ownership-groups div { float: left; margin: 0 5%; text-align: left; width: 40%; } -/* line 153, ../../../app/stylesheets/items/_show.sass */ +/* line 171, ../../../app/stylesheets/items/_show.sass */ body.items-show #closet-hangers #closet-hangers-ownership-groups div li { list-style: none; word-wrap: break-word; } -/* line 157, ../../../app/stylesheets/items/_show.sass */ +/* line 175, ../../../app/stylesheets/items/_show.sass */ body.items-show #closet-hangers #closet-hangers-ownership-groups div li label.unlisted { font-style: italic; } -/* line 160, ../../../app/stylesheets/items/_show.sass */ +/* line 178, ../../../app/stylesheets/items/_show.sass */ body.items-show #closet-hangers form { padding: 0.5em 0; } -/* line 163, ../../../app/stylesheets/items/_show.sass */ +/* line 181, ../../../app/stylesheets/items/_show.sass */ body.items-show #closet-hangers select { width: 9em; } -/* line 166, ../../../app/stylesheets/items/_show.sass */ +/* line 184, ../../../app/stylesheets/items/_show.sass */ body.items-show #closet-hangers input[type=number] { margin-right: 0.5em; width: 3em; } -/* line 172, ../../../app/stylesheets/items/_show.sass */ +/* line 190, ../../../app/stylesheets/items/_show.sass */ body.items-show.js #trade-hangers p { max-height: 3em; overflow: hidden; } -/* line 176, ../../../app/stylesheets/items/_show.sass */ +/* line 194, ../../../app/stylesheets/items/_show.sass */ body.items-show.js #trade-hangers p.showing-more { max-height: none; } @@ -3932,12 +3975,12 @@ body.outfits-new #latest-contribution { padding: 0.5em 0; text-align: center; } -/* line 210, ../../../app/stylesheets/outfits/_new.sass */ +/* line 203, ../../../app/stylesheets/outfits/_new.sass */ body.outfits-new #latest-contribution #recent-contributions-link { font-weight: bold; margin-right: 0.5em; } -/* line 214, ../../../app/stylesheets/outfits/_new.sass */ +/* line 207, ../../../app/stylesheets/outfits/_new.sass */ body.outfits-new #latest-contribution #latest-contribution-created-at { color: #448844; margin-left: 0.5em;