From 3ca488f4bcf72614cd180a8a9f3c2dac190dc8d9 Mon Sep 17 00:00:00 2001 From: Coleman Date: Fri, 17 Oct 2008 03:53:38 -0500 Subject: [PATCH] add stats via email address --- app/controllers/photos.rb | 22 +++++++++++++++ app/helpers/photos_helper.rb | 11 ++++++++ app/views/home/index.html.haml | 4 +++ .../photos/_stats_for_email_hash.html.haml | 25 ++++++++++++++++++ app/views/photos/by_email.html.haml | 8 ++++++ config/router.rb | 2 ++ public/images/mail-message-new.png | Bin 0 -> 946 bytes 7 files changed, 72 insertions(+) create mode 100644 app/views/photos/_stats_for_email_hash.html.haml create mode 100644 app/views/photos/by_email.html.haml create mode 100644 public/images/mail-message-new.png 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 ) "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 + ) + "Chart Results" + 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 0000000000000000000000000000000000000000..96ae0e907765f8db0b231e5ccaab461bb9b13da8 GIT binary patch literal 946 zcmV;j15NyiP)d|u#YOs1TCZ>O|UE4JNYYG)=DZ+NypzIFJ&d$tx9=fycKj@)}zvLa>dwHMt zd++yV6t;jY=geKXLt8kZybKBVea_UF@WKt@20;6S^!_O zr{!JYiOKQTfGv!^$k!V{C@ zuLEC1Xat5~ScUs^?J98X=aY0j+_kQ%JA@`?Zz>}5sX};4v!^|+4jqorTrSrD-suOZ z{Kb0q2X=SwCs1EWpzV}_f7aAWr`}QIKbL{uwYoxmJvuT*Hk)mV-Wl^yV|kE8{4jxP zv;m4DrLIDFKac>>s;fUbGDaqose|e>7AT5I)=^08_=ULIhT8Hd?#4xZ-4TWMBx?Y% za>A!aN5)A1lqLuQf*`>6eSF`q^cQZ-GdDNOYA%OcvUp_Qdn8g%kn7MEsL)WpaWCa0g(3O>CR86IAXFEcO zhL5ZP1~|~y&)M^5=;`jkb=}ImloBMY=2r3j5(l3ds@eFiu->B6-}eNUE~UBg=R(6G z!!UUB@Y`FWTf$OGRx-;FQ#kVe2M8f*o?-g(MP@FX0H-q2(Fs629_Jn+ zA7$+LzJKEQ)Ul)7Tdag(_*s-_{f}M+tn!8r0P%7&qcQ*cKP!7I{!!f3lftS U;Y_NNVgLXD07*qoM6N<$f)BaF9smFU literal 0 HcmV?d00001