diff --git a/app/controllers/photos.rb b/app/controllers/photos.rb
index 586765f..6f8c308 100644
--- a/app/controllers/photos.rb
+++ b/app/controllers/photos.rb
@@ -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
diff --git a/app/helpers/photos_helper.rb b/app/helpers/photos_helper.rb
index 2254d30..588ad2b 100644
--- a/app/helpers/photos_helper.rb
+++ b/app/helpers/photos_helper.rb
@@ -10,5 +10,16 @@ module Merb
)
""
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
+ )
+ ""
+ end
end
end # Merb
diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml
index 9d9c96b..0845683 100644
--- a/app/views/home/index.html.haml
+++ b/app/views/home/index.html.haml
@@ -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
diff --git a/app/views/photos/_stats_for_email_hash.html.haml b/app/views/photos/_stats_for_email_hash.html.haml
new file mode 100644
index 0000000..98cd613
--- /dev/null
+++ b/app/views/photos/_stats_for_email_hash.html.haml
@@ -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== #{@photos[0].one_votes.to_i} / #{@photos[0].oneness}%
+ %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== #{@photos[1].one_votes.to_i} / #{@photos[1].oneness}%
+ %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== #{@photos[2].one_votes.to_i} / #{@photos[2].oneness}%
+ %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== #{@photos[3].one_votes.to_i} / #{@photos[3].oneness}%
diff --git a/app/views/photos/by_email.html.haml b/app/views/photos/by_email.html.haml
new file mode 100644
index 0000000..0b97887
--- /dev/null
+++ b/app/views/photos/by_email.html.haml
@@ -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'
diff --git a/config/router.rb b/config/router.rb
index 6d16863..3fb700f 100644
--- a/config/router.rb
+++ b/config/router.rb
@@ -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
diff --git a/public/images/mail-message-new.png b/public/images/mail-message-new.png
new file mode 100644
index 0000000..96ae0e9
Binary files /dev/null and b/public/images/mail-message-new.png differ