Implemented missing part, code/style cleanup.

* Moved Anne.create to the Anne module.
 * In Anne::Controllers::Vote#post "either" is no longer a possible choice.
 * Implemented Anne::Controllers::Finish#post.
 * Added Anne::Controllers::Thanks and Anne::Views#thanks.
 * Coding style cleanup; removed debug print.
 * Use white on black basic style to suit the look of the images.
This commit is contained in:
Paul van Tilburg 2010-05-18 23:54:15 +02:00
parent f10145a66b
commit c28cd15189
1 changed files with 39 additions and 13 deletions

View File

@ -13,6 +13,10 @@ module Anne
include Camping::Session include Camping::Session
secret "JeMoeder" secret "JeMoeder"
def self.create
Anne::Models.create_schema
end
end end
module Anne::Models module Anne::Models
@ -49,14 +53,16 @@ end
module Anne::Helpers module Anne::Helpers
def next_image def next_image
all_images = Pathname.glob(IMAGE_DIR + "*.jpg").map { |img| all_images =
img.basename.to_s } Pathname.glob(IMAGE_DIR + "*.jpg").map { |img| img.basename.to_s }
voted_images = Anne::Models::Vote.find(:all, :conditions => { all_votes =
:user_id => @state["user"].id }).map { |vote| vote.image } Anne::Models::Vote.find(:all,
:conditions => { :user_id => @state["user"].id })
voted_images = all_votes.map { |vote| vote.image }
remaining_images = all_images - voted_images remaining_images = all_images - voted_images
return nil, 100 if remaining_images.empty? return nil, 100 if remaining_images.empty?
return remaining_images.sort_by { rand }.first, 100 - return remaining_images.sort_by { rand }.first,
(remaining_images.length * 100.0 / all_images.length).to_i 100 - (remaining_images.length * 100.0 / all_images.length).to_i
end end
end end
@ -97,7 +103,7 @@ module Anne::Controllers
def post def post
choice = if @input.left then "left" choice = if @input.left then "left"
elsif @input.right then "right" elsif @input.right then "right"
else "either" else raise "no choice made!"
end end
vote = Anne::Models::Vote.create( :user_id => @state["user"].id, vote = Anne::Models::Vote.create( :user_id => @state["user"].id,
:image => @input.image, :image => @input.image,
@ -124,6 +130,16 @@ module Anne::Controllers
return redirect Vote unless next_image.first.nil? return redirect Vote unless next_image.first.nil?
render :finish render :finish
end end
def post
user = User.find(@state["user"].id)
raise "unknown user" if user.nil?
user.email = @input.email
user.prize = !@input.prize.nil?
user.results = !@input.results.nil?
user.save
redirect Thanks
end
end end
class Style < R '/style\.css' class Style < R '/style\.css'
@ -135,6 +151,12 @@ module Anne::Controllers
end end
end end
class Thanks
def get
render :thanks
end
end
end end
module Anne::Views module Anne::Views
@ -143,7 +165,6 @@ module Anne::Views
xhtml_strict do xhtml_strict do
head do head do
title "Anne's hippe enqueteshizzle" title "Anne's hippe enqueteshizzle"
p @state["user"].inspect
link :rel => "stylesheet", :type => "text/css", link :rel => "stylesheet", :type => "text/css",
:media => "screen", :href => "/style.css" :media => "screen", :href => "/style.css"
end end
@ -181,8 +202,8 @@ module Anne::Views
make_select "Studiejaar", "user_study_year", ["nvt"] + (1998..2010).to_a make_select "Studiejaar", "user_study_year", ["nvt"] + (1998..2010).to_a
make_select "Geslacht", "user_gender", ["", "man", "vrouw"] make_select "Geslacht", "user_gender", ["", "man", "vrouw"]
make_select "Kleurenblind?", "user_colorblind", ["nee", "ja"] make_select "Kleurenblind?", "user_colorblind", ["nee", "ja"]
make_select "Ruimtelijk ingesteld?", "user_spaciousness", ["neutraal", make_select "Ruimtelijk ingesteld?", "user_spaciousness",
"ja", "nee"] ["neutraal", "ja", "nee"]
input :type => "submit", :value => "Start de enquete" input :type => "submit", :value => "Start de enquete"
end end
@ -222,11 +243,16 @@ module Anne::Views
end end
end end
end def thanks
h2 "Bedankt voor die bloemen!"
end
def Anne.create
Anne::Models.create_schema
end end
__END__ __END__
/* Style sheet for the Anne Survey Camping app */ /* Style sheet for the Anne Survey Camping app */
body {
color: white;
background-color: black;
}