add stats via email address

master
Coleman 2008-10-17 03:53:38 -05:00
parent 0ffda6bbf4
commit 3ca488f4bc
7 changed files with 72 additions and 0 deletions

View File

@ -81,6 +81,28 @@ class Photos < Application
render
end
def by_email
if request.post? and !params[:email].to_s.empty?
redirect url(:action => :by_hash, :id => User.salted_string(params[:email]))
else
render
end
end
def by_hash
@photo_ids = Photo.find(:all, :select => 'id', :conditions => [ 'email_hash = ?', params[:id] ]).collect { |p| p.id } rescue []
@page = params[:page].to_i
per_page = 4
@photos = Photo.find :all, :conditions => "id IN (#{@photo_ids.join(',')})", :limit => per_page, :offset => (@page * per_page)
@votes = Vote.find :all, :conditions => "photo_id IN (#{@photo_ids.join(',')})"
@page_count = (@photo_ids.size.to_f / per_page.to_f).ceil
if params[:id].to_s.empty? or @photo_ids.empty? or @votes.empty?
redirect url(:action => :by_email)
else
render
end
end
protected
def make_photo

View File

@ -10,5 +10,16 @@ module Merb
)
"<img src='#{curl}' alt='Chart Results' />"
end
def stat_chart
curl = Gchart.pie(
:size => '415x275',
:title => "Voting results for #{@photo_ids.size} photos. Oneness #{"%.1f%%" % (@votes.select { |v| v.one? }.size.to_f / @votes.size.to_f * 100.0)}",
:legend => [ "Not One (#{@votes.select { |v| v.zero? }.size})", "One (#{@votes.select { |v| v.one? }.size})" ],
:data => [ @votes.select { |v| v.zero? }.size, @votes.select { |v| v.one? }.size ],
:theme => :pastel
)
"<img src='#{curl}' alt='Chart Results' />"
end
end
end # Merb

View File

@ -33,3 +33,7 @@
%a{ :href => menu_item[:href], :title => menu_item[:name] }
%img{ :src => menu_item[:img] }
= menu_item[:title]
%li
%a{ :href => url(:controller => :photos, :action => :by_email) }
%img{ :src => '/images/mail-message-new.png' }
Lookup photos of you by email address

View File

@ -0,0 +1,25 @@
- dim = 100
#inner_scrolling_photo_block{ :style => (request.xhr? ? 'display: none;' : '') }
%table{ :cellspacing => 0, :cellpadding => 0 }
%tr
%td{ :style => "width: 140px; height: 150px;" }
- if @photos[0]
%a{ :href => url(:photo, @photos[0]), :onclick => 'window.open(this.href);return false;' }
%img{ :src => photo_url(@photos[0], dim, dim) }
%p== <tt>#{@photos[0].one_votes.to_i} / #{@photos[0].oneness}%</tt>
%td{ :style => "width: 140px; height: 150px;" }
- if @photos[1]
%a{ :href => url(:photo, @photos[1]), :onclick => 'window.open(this.href);return false;' }
%img{ :src => photo_url(@photos[1], dim, dim) }
%p== <tt>#{@photos[1].one_votes.to_i} / #{@photos[1].oneness}%</tt>
%tr
%td{ :style => "width: 140px; height: 150px;" }
- if @photos[2]
%a{ :href => url(:photo, @photos[2]), :onclick => 'window.open(this.href);return false;' }
%img{ :src => photo_url(@photos[2], dim, dim) }
%p== <tt>#{@photos[2].one_votes.to_i} / #{@photos[2].oneness}%</tt>
%td{ :style => "width: 140px; height: 150px;" }
- if @photos[3]
%a{ :href => url(:photo, @photos[3]), :onclick => 'window.open(this.href);return false;' }
%img{ :src => photo_url(@photos[3], dim, dim) }
%p== <tt>#{@photos[3].one_votes.to_i} / #{@photos[3].oneness}%</tt>

View File

@ -0,0 +1,8 @@
= form :action => url(:action => :by_email) do
%fieldset
%legend What is your email address?
%p
%label{ :for => 'email' }
Email
= text_field :name => 'email', :id => 'email'
= submit 'Go'

View File

@ -5,6 +5,8 @@ Merb::Router.prepare do |r|
r.match('/acceptable_use').to(:controller => 'home', :action => 'acceptable_use')
r.match('/disclaimer').to(:controller => 'home', :action => 'disclaimer')
r.match('/hall_of_fame').to(:controller => 'home', :action => 'hall_of_fame')
r.match('/photos/by_email').to(:controller => 'photos', :action => 'by_email')
r.match('/photos/by_hash/:id').to(:controller => 'photos', :action => 'by_hash')
# restful things
r.resources :sessions

Binary file not shown.

After

Width:  |  Height:  |  Size: 946 B