items petpage export

This commit is contained in:
Emi Matchu 2011-07-31 02:48:16 -04:00
parent 4f0e7899b7
commit 30096f6b0a
11 changed files with 233 additions and 23 deletions

View file

@ -1,6 +1,7 @@
class ClosetHangersController < ApplicationController
before_filter :authorize_user!, :only => [:destroy, :create, :update]
before_filter :authorize_user!, :only => [:destroy, :create, :update, :petpage]
before_filter :find_item, :only => [:destroy, :create, :update]
before_filter :find_user, :only => [:index, :petpage]
def destroy
raise ActiveRecord::RecordNotFound unless params[:closet_hanger]
@ -13,29 +14,9 @@ class ClosetHangersController < ApplicationController
end
def index
@user = User.find params[:user_id]
@public_perspective = params.has_key?(:public) || !user_is?(@user)
@perspective_user = current_user unless @public_perspective
@closet_lists_by_owned = @user.closet_lists.
alphabetical.includes(:hangers => :item)
unless @perspective_user == @user
# If we run this when the user matches, we'll end up with effectively:
# WHERE belongs_to_user AND (is_public OR belongs_to_user)
# and it's a bit silly to put the SQL server through a condition that's
# always true.
@closet_lists_by_owned = @closet_lists_by_owned.visible_to(@perspective_user)
end
@closet_lists_by_owned = @closet_lists_by_owned.group_by(&:hangers_owned)
visible_groups = @user.closet_hangers_groups_visible_to(@perspective_user)
unless visible_groups.empty?
@unlisted_closet_hangers_by_owned = @user.closet_hangers.unlisted.
owned_before_wanted.alphabetical_by_item_name.includes(:item).
where(:owned => [visible_groups]).group_by(&:owned)
else
@unlisted_closet_hangers_by_owned = {}
end
find_closet_hangers!
if @public_perspective && user_signed_in?
items = []
@ -53,6 +34,11 @@ class ClosetHangersController < ApplicationController
end
end
def petpage
@public_perspective = true
find_closet_hangers!
end
# Since the user does not care about the idea of a hanger, but rather the
# quantity of an item they own, the user would expect a create form to work
# even after the record already exists, and an update form to work even after
@ -108,6 +94,34 @@ class ClosetHangersController < ApplicationController
@item = Item.find params[:item_id]
end
def find_user
@user = User.find params[:user_id]
end
def find_closet_hangers!
@perspective_user = current_user unless @public_perspective
@closet_lists_by_owned = @user.closet_lists.
alphabetical.includes(:hangers => :item)
unless @perspective_user == @user
# If we run this when the user matches, we'll end up with effectively:
# WHERE belongs_to_user AND (is_public OR belongs_to_user)
# and it's a bit silly to put the SQL server through a condition that's
# always true.
@closet_lists_by_owned = @closet_lists_by_owned.visible_to(@perspective_user)
end
@closet_lists_by_owned = @closet_lists_by_owned.group_by(&:hangers_owned)
visible_groups = @user.closet_hangers_groups_visible_to(@perspective_user)
unless visible_groups.empty?
@unlisted_closet_hangers_by_owned = @user.closet_hangers.unlisted.
owned_before_wanted.alphabetical_by_item_name.includes(:item).
where(:owned => [visible_groups]).group_by(&:owned)
else
@unlisted_closet_hangers_by_owned = {}
end
end
def owned
owned = true
if params[:closet_hanger]

View file

@ -61,10 +61,30 @@ module ClosetHangersHelper
link_to(content, path, options)
end
def nc_icon_url
"http://#{request.host}#{image_path 'nc.png'}"
end
def petpage_item_name(item)
item.name.gsub(/ on/i, ' o<b></b>n')
end
def public_perspective?
@public_perspective
end
PETPAGE_HANGER_BATCH_SIZE = 5
def render_batched_petpage_hangers(hangers)
output do |html|
hangers.in_groups_of(PETPAGE_HANGER_BATCH_SIZE) do |batch|
content = batch.map do |hanger|
render 'petpage_hanger', :hanger => hanger if hanger
end.join.html_safe
html << content_tag(:div, content, :class => 'dti-item-row')
end
end
end
def render_closet_lists(lists)
if lists
render :partial => 'closet_lists/closet_list', :collection => lists,

View file

@ -10,6 +10,7 @@ class ClosetList < ActiveRecord::Base
validates :hangers_owned, :inclusion => {:in => [true, false], :message => "can't be blank"}
scope :alphabetical, order(:name)
scope :public, where(arel_table[:visibility].gteq(ClosetVisibility[:public].id))
scope :visible_to, lambda { |user|
condition = arel_table[:visibility].gteq(ClosetVisibility[:public].id)
condition = condition.or(arel_table[:user_id].eq(user.id)) if user

View file

@ -0,0 +1,12 @@
body.closet_hangers-petpage
+secondary-nav
#intro
clear: both
#petpage-output
display: block
height: 30em
margin: 0 auto
width: 50%

View file

@ -7,6 +7,7 @@
@import partials/jquery.jgrowl
@import closet_hangers/index
@import closet_hangers/petpage
@import closet_lists/form
@import closet_pages/new
@import contributions/index

View file

@ -0,0 +1,97 @@
%style{:type => 'text/css'}
:plain
.dti-item-group, .dti-item-list, .dti-unlisted-items {
margin: 0;
padding: 0;
}
.dti-item-group-header, .dti-item-group, #dti-item-footer {
color: #040;
font-family: Helvetica, Arial, Verdana, sans-serif;
line-height: 1.5;
margin: 0 auto;
text-align: center;
width: 560px;
}
.dti-item-group-header {
border-top: 1px solid #060;
font-size: 175%;
margin-top: 1em;
}
.dti-item-group-header, .dti-item-list {
border-bottom: 1px solid #ADA;
}
.dti-item-group {
list-style: none;
}
.dti-item-list h3 {
font-size: 150%;
}
.dti-items {
border-spacing: 10px;
display: table;
}
.dti-item-row {
display: table-row;
}
.dti-item {
display: table-cell;
margin: 0 10px;
padding: 8px;
text-align: right;
width: 84px;
}
.dti-item-thumbnail {
height: 80px;
width: 80px;
}
.dti-item span {
display: block;
text-align: center;
}
.dti-item-nc {
margin-top: -16px;
}
.dti-unlisted-items h3 {
font-style: italic;
}
#dti-item-footer {
font-size: 85%;
margin-top: 2em;
}
- [true, false].each do |owned|
- lists = lists_by_owned[owned]
- if lists || unlisted_hangers_by_owned[owned]
%h2.dti-item-group-header Items #OWNER #{ClosetHanger.verb(:someone, owned)}
%ul.dti-item-group
- lists.each do |list|
- unless list.hangers.empty?
%li.dti-item-list
%h3= list.name
- if list.description?
.dti-item-list-desc
= closet_list_description_format list
%div.dti-items
= render_batched_petpage_hangers(list.hangers.sort { |a,b| a.item.name <=> b.item.name })
%li.dti-unlisted-items
- unless lists.empty?
%h3 (Not in a list)
%div
= render_batched_petpage_hangers(unlisted_hangers_by_owned[owned])
#dti-item-footer
I made this list on Dress to Impress. You can, too!

View file

@ -0,0 +1,6 @@
%div.dti-item
= image_tag hanger.item.thumbnail_url, :alt => nil, :class => 'dti-item-thumbnail'
- if hanger.item.nc?
= image_tag nc_icon_url, :alt => 'NC', :class => 'dti-item-nc', :title => 'This is an NC Mall item'
%span= petpage_item_name hanger.item

View file

@ -0,0 +1,22 @@
- title 'Export to Petpage'
- secondary_nav do
= link_to 'Back to Your Items', user_closet_hangers_path(current_user), :class => 'button'
#intro
%p
We took your public lists and created a nice, simple HTML file for your
Neopet's petpage. By default it's styled as a table, but it doesn't have to
be. The HTML is flexible, so, if you're the artsy type, you're free to mess
with the styles all you want!
%p
Copy the HTML from the box below, then paste it into
= succeed '.' do
= link_to "your pet's page", 'http://www.neopets.com/edithomepage.phtml'
Then head to the Neoboards to show off! Have fun!
%textarea#petpage-output
= '' + render('petpage_content',
:lists_by_owned => @closet_lists_by_owned,
:unlisted_hangers_by_owned => @unlisted_closet_hangers_by_owned)

View file

@ -1,4 +1,6 @@
OpenneoImpressItems::Application.routes.draw do |map|
get "petpages/new"
get "closet_lists/new"
get "closet_lists/create"
@ -41,7 +43,11 @@ OpenneoImpressItems::Application.routes.draw do |map|
resources :users, :path => 'user', :only => [:update] do
resources :contributions, :only => [:index]
resources :closet_hangers, :only => [:index], :path => 'closet'
resources :closet_hangers, :only => [:index], :path => 'closet' do
collection do
get :petpage
end
end
resources :closet_lists, :only => [:new, :create, :edit, :update, :destroy], :path => 'closet/lists'
resources :items, :only => [] do

View file

@ -1152,6 +1152,32 @@ body.closet_hangers-index.current-user.js .closet-hangers-group.hidden header .s
display: block;
}
/* line 2, ../../../app/stylesheets/partials/_secondary_nav.sass */
body.closet_hangers-petpage #title {
float: left;
margin-right: 0.5em;
}
/* line 6, ../../../app/stylesheets/partials/_secondary_nav.sass */
body.closet_hangers-petpage .flash {
clear: both;
}
/* line 9, ../../../app/stylesheets/partials/_secondary_nav.sass */
body.closet_hangers-petpage #secondary-nav {
display: block;
margin-top: 0.75em;
}
/* line 4, ../../../app/stylesheets/closet_hangers/_petpage.sass */
body.closet_hangers-petpage #intro {
clear: both;
}
/* line 7, ../../../app/stylesheets/closet_hangers/_petpage.sass */
body.closet_hangers-petpage #petpage-output {
display: block;
height: 30em;
margin: 0 auto;
width: 50%;
}
/* line 2, ../../../app/stylesheets/partials/_secondary_nav.sass */
body.closet_lists-new #title, body.closet_lists-create #title, body.closet_lists-edit #title, body.closet_lists-update #title {
float: left;

View file

@ -0,0 +1,5 @@
require 'spec_helper'
describe "petpages/new.html.erb" do
pending "add some examples to (or delete) #{__FILE__}"
end