From 277d9e323c1c9c525c1cea4590dc71bc56aeed06 Mon Sep 17 00:00:00 2001 From: Date: Mon, 6 Aug 2007 19:56:39 -0400 Subject: [PATCH 1/1] Modified the methods in graphs controller so they would work for Selectricity, but can't get them to successfully display yet. It seems that the 'url_for' helper might not be able to handle a :controller an argument. It doesn't throw an error, just displays nothing. I also removed various deprecated methods and replaced them with their updated counterparts in site_controller, and in some of the views. In addition I modified the confirm method in the QuickVote controller to save the time of the vote. I also changed what the voter.ip was logging because it wasn't working. Currently it says request.env["BLAH"] because I'm trying to vote multiple times in the same election for testing (not sure that jsut cahgnign the ip save feature is allowing that) but it will have to be request.env["REMOTE_ADDR"] in the long run. This is on line 108 of the QuickVote controller. --- app/controllers/graphs_controller.rb | 24 ++++++++++-------------- app/controllers/quickvote_controller.rb | 9 +++++++-- app/controllers/site_controller.rb | 4 ++-- app/models/election.rb | 10 +++++++++- app/models/vote.rb | 7 +++++++ app/views/layouts/hc.rhtml | 6 +++--- app/views/quickvote/results.rhtml | 1 + app/views/site/index.rhtml | 2 +- config/environment.rb | 1 + 9 files changed, 41 insertions(+), 23 deletions(-) diff --git a/app/controllers/graphs_controller.rb b/app/controllers/graphs_controller.rb index c810853..101dc6d 100644 --- a/app/controllers/graphs_controller.rb +++ b/app/controllers/graphs_controller.rb @@ -29,15 +29,15 @@ class GraphsController < ApplicationController send_data(g.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "gruff.png") end - #The following section has been pasted directly fromworking pollarize graphs - #and hasn't been adopted to fit Selectricity yet - + #I've started to modify the following section to fit Selectricity, still + #desn't seem towork, issue seems tobe realted to path def day_votes - @poll = Poll.find(params[:id]) + + @election = Election.find(params[:id]) line = Gruff::Line.new line.title = "Voters Per Day" line.font = File.expand_path('/usr/X11R6/lib/X11/fonts/TTF/Vera.ttf', RAILS_ROOT) - line.data("#{@poll.name}", voter_days["voters_per_day"] ) + line.data("#{@election.name}", voter_days["voters_per_day"] ) line.labels = voter_days["days_hash"] line.x_axis_label = "Date" line.y_axis_label = "Number of Votes" @@ -50,22 +50,18 @@ class GraphsController < ApplicationController end def voter_days - @poll = Poll.find(params[:id]) + @election = Election.find(params[:id]) voter_times = Array.new unique_days = Array.new voters_per_day = Array.new days_hash = Hash.new - @poll.questions.each do |qstn| - qstn.votes.each do |vote| + @election.votes.each do |vote| voter_times << vote.time unless voter_times.any? {|utime| utime == vote.time} - end end + voter_times.sort! - #find all times in voter_times with the same date, and then concatenate - #that number onto votes_per_day - # - #doesn't work jsut yet + voter_times.each_with_index do |time, index| count = 1 unless unique_days.any? { |d1| d1.eql?(time.mon.to_s+"/"+time.day.to_s) } @@ -81,7 +77,7 @@ class GraphsController < ApplicationController return { "voters_per_day" => voters_per_day, "days_hash" => days_hash } end - #end copy/pasted section + #end section end diff --git a/app/controllers/quickvote_controller.rb b/app/controllers/quickvote_controller.rb index 10815b3..e7a285b 100644 --- a/app/controllers/quickvote_controller.rb +++ b/app/controllers/quickvote_controller.rb @@ -105,11 +105,16 @@ class QuickvoteController < ApplicationController else # record the ip address for posterity - @voter.ipaddress = request.env["HTTP_X_FORWARDED_FOR"] + @voter.ipaddress = request.env["BLAH"] @voter.save - # toggle the confirmation bit + # save the time the vote was made for statistical use, it doesn't + #work here unless I use a method that will save it to the db + @voter.vote.time = Time.now + + # toggle the confirmation bit @voter.vote.confirm! + @voter.reload render :action => 'thanks' end diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index dd049f7..f6b36a7 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -3,12 +3,12 @@ class SiteController < ApplicationController model :user, :election, :account def index - @quickvotes = QuickVote.find_all(["quickvote = 1"]).sort {|a,b| b.enddate <=> a.enddate}[0..1] + @quickvotes = QuickVote.find(:all, ["quickvote = 1"]).sort {|a,b| b.enddate <=> a.enddate}[0..1] # if the person claims they are logged in if session[:user] # check to see that we actually have record of them - if User.find_all(["id = ?", session[:user].id]).length == 1 + if User.find(:all, ["id = ?", session[:user].id]).length == 1 # if we have record of them, grab the list of their elections session[:user] = User.find(session[:user]) @current_elections = session[:user].elections.sort do |a,b| diff --git a/app/models/election.rb b/app/models/election.rb index 0907e68..ebd623a 100755 --- a/app/models/election.rb +++ b/app/models/election.rb @@ -10,7 +10,7 @@ class Election < ActiveRecord::Base def startdate read_attribute( :startdate ) || Time.now end - + def enddate date = read_attribute( :enddate ) || Time.now + 14 date - 1.second @@ -22,6 +22,14 @@ class Election < ActiveRecord::Base super(date) end + def votes + votes = Array.new + self.voters.each do |voter| + votes << voter.vote + end + return votes + end + def destroy self.candidates.each do |candidate| candidate.destroy diff --git a/app/models/vote.rb b/app/models/vote.rb index f263a75..62944e3 100755 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -8,6 +8,8 @@ class Vote < ActiveRecord::Base after_update :save_rankings before_destroy :destroy_rankings + + def to_s votes.join("") end @@ -51,6 +53,11 @@ class Vote < ActiveRecord::Base rankings.each { |ranking| ranking.destroy } end + def settime + self.time = Time.now + self.save + end + def confirm! self.confirmed = 1 self.save diff --git a/app/views/layouts/hc.rhtml b/app/views/layouts/hc.rhtml index 13b2e72..6046735 100755 --- a/app/views/layouts/hc.rhtml +++ b/app/views/layouts/hc.rhtml @@ -17,7 +17,6 @@ - <% if @flash[:notice]%> -
<%= @flash[:notice] %>
+ <% if flash[:notice]%> +
<%= flash[:notice] %>
<% end%>
diff --git a/app/views/quickvote/results.rhtml b/app/views/quickvote/results.rhtml index 8ce400a..321dbbc 100755 --- a/app/views/quickvote/results.rhtml +++ b/app/views/quickvote/results.rhtml @@ -161,3 +161,4 @@ by several other names.

<% end %> + diff --git a/app/views/site/index.rhtml b/app/views/site/index.rhtml index f2f5700..eb009b3 100755 --- a/app/views/site/index.rhtml +++ b/app/views/site/index.rhtml @@ -43,7 +43,7 @@ ongoing election, you can log in to vote using your token here.

<%= form_tag :controller => 'voter', :action => 'index' %> <%= text_field :vote, :password %> <%= submit_tag "Log In" %> -<%= end_form_tag %> +

<%= link_to 'Lost or forgot your token?', :controller => 'voter', :action => 'forgot_password' %>

<% if session[:user] %> diff --git a/config/environment.rb b/config/environment.rb index 7d3657e..77d020c 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -64,6 +64,7 @@ MAIL_CONFIG = { :from => 'Selectricity '} require 'uniq_token' require 'randarray' require 'rubyvote' +require 'gruff' class String # alternate capitalization method that does not lowercase the rest of -- 2.39.5