| Class | VoteController |
| In: |
app/controllers/vote_controller.rb
|
| Parent: | ApplicationController |
# File app/controllers/vote_controller.rb, line 83
83: def feedback
84: if request.post? && params[:feedback] && !params[:feedback].blank?
85: user = Question.first(:conditions => { :pairwise_id => @question_id }).user
86: Mailer.deliver_feedback(t('feedback.submitted_feedback'), user, @question, params[:email], params[:feedback])
87: flash[:notice] = t('feedback.successfully_sent')
88: end
89: end
# File app/controllers/vote_controller.rb, line 9
9: def index
10: @current_page = t('nav.view_results')
11: @third_page = t('nav.recent_winners')
12: votes = Pairwise.list_votes(@question_id, nil, 10)
13: @responses = votes.inject([]) do |array, vote|
14: item = vote.last
15: winner = item ? [from_hash_or_get_item(item)] : []
16: losers = Pairwise.get_prompt(vote[1]).last
17: array << [winner, losers.map { |loser| from_hash_or_get_item(loser) } - winner]
18: end
19: end
# File app/controllers/vote_controller.rb, line 56
56: def map
57: votes = Pairwise.list_votes(@question_id, nil, 100)
58: @ip_percents = ip_percents(votes, false)
59: @current_page = t('nav.view_results')
60: @third_page = t('nav.map_of_voters')
61: @label = t('items.total')
62: @explain = t('questions.map_explanation')
63: end
# File app/controllers/vote_controller.rb, line 65
65: def named
66: @name = params[:path]
67: @name = @name.is_a?(Array) ? @name.first.downcase : @name.downcase
68: unless @name && @question_internal = Question.first(:conditions => { :name => @name, :active => true })
69: redirect_to(root_path)
70: else
71: if request.post? || params[:p] == '1'
72: if @question_internal.id == Const::TOUR_DEMO_QUESTION_ID
73: flash.now[:notice] = render_to_string(:partial => 'example_note')
74: else
75: flash.now[:notice] = render_to_string(:partial => 'new_question')
76: end
77: end
78: @current_page = t('vote.cast_votes')
79: vars_for_question(@question_internal.pairwise_id) && render(:show)
80: end
81: end
# File app/controllers/vote_controller.rb, line 32
32: def new
33: # filter out bots
34: unless looks_like_a_bot?
35: id = params[:id].to_i
36: item_id = params[:item_id]
37: prompt_id = params[:prompt_id].to_i
38: if id > 0 && prompt_id > 0
39: set_pairwise_from_question_id(id)
40: qv = QuestionsVisit.qv(id, current_visit.id)
41: Pairwise.vote(prompt_id, item_id, qv.voter_id_ext, get_response_time, ip_address)
42: items = Pairwise.get_prompt(prompt_id).last
43: items = [items] << items.map { |p_id| Pairwise.get_item(p_id)[1] }
44: if items.first.first == item_id
45: session[:last_prompt] = [items.last.first, items.first.first, items.last.last, items.first.last]
46: else
47: session[:last_prompt] = [items.last.last, items.first.last, items.last.first, items.first.first]
48: end
49: item_id.to_i > 0 ? session[:last_prompt] << false : session[:last_prompt] << true
50: end
51: clear_prompt_for_question_visit(id)
52: end
53: params[:name] ? redirect_to("/#{params[:name]}") : redirect_to(vote_path(id))
54: end
# File app/controllers/vote_controller.rb, line 21
21: def show
22: id = params[:id].to_i
23: if id > 0
24: @current_page = t('vote.cast_votes')
25: @question_internal = Question.first(:conditions => { :pairwise_id => id, :active => true })
26: vars_for_question(id)
27: else
28: redirect_to root_path
29: end
30: end
To keep the client light and remove the need for Javascript response time tracking is done on the server. Here a time is stored in the session, on vote the time is diffed and reset. Time is sent in milliseconds.
# File app/controllers/vote_controller.rb, line 104
104: def get_response_time #:doc:
105: ret = session[:prompt_time].nil? ? 0 : (1000 * (Time.now - session[:prompt_time])).round
106: session[:prompt_time] = nil
107: ret
108: end