From: Date: Thu, 12 Oct 2006 13:40:47 +0000 (-0400) Subject: Made a large number of mostly cosmetic fixes after a detailed X-Git-Url: https://projects.mako.cc/source/selectricity/commitdiff_plain/ac5e3489e8b886b7b8a7252ab56ddeb3d3bdadc7 Made a large number of mostly cosmetic fixes after a detailed run-through of quickvotes. Also added support for tracking IP addresses into the database. --- diff --git a/app/controllers/quickvote_controller.rb b/app/controllers/quickvote_controller.rb index c3510f6..9ae1748 100644 --- a/app/controllers/quickvote_controller.rb +++ b/app/controllers/quickvote_controller.rb @@ -11,7 +11,7 @@ class QuickvoteController < ApplicationController session.session_id, @election.id])[0] unless @voter @voter = QuickVoter.new - @voter.election = Election.find_all( [ "name = ?", params[:votename] ] )[0] + @voter.election = QuickVote.find_all( [ "name = ?", params[:votename] ] )[0] end end @@ -42,6 +42,7 @@ class QuickvoteController < ApplicationController @voter = QuickVoter.new() @voter.election = election @voter.session_id = session.session_id + @voter.ipaddress = request.env["REMOTE_ADDR"] @voter.save @voter.reload @@ -53,7 +54,7 @@ class QuickvoteController < ApplicationController end def results - @election = Election.find_all( ["name = ?", params[:votename]] )[0] + @election = QuickVote.find_all( ["name = ?", params[:votename]] )[0] preference_tally = [] plurality_tally = [] diff --git a/app/models/election.rb b/app/models/election.rb index 0860a42..eaf0727 100644 --- a/app/models/election.rb +++ b/app/models/election.rb @@ -44,4 +44,12 @@ class Election < ActiveRecord::Base quickvote.to_i == 1 end + def shortdesc + shortdesc = description.split(/\n/)[0] + end + + def longdesc + longdesc = description.split(/\n/)[1..-1].join("") + longdesc.length > 0 ? longdesc : nil + end end diff --git a/app/models/vote.rb b/app/models/vote.rb index 08dd1e7..014899d 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -76,4 +76,8 @@ class Vote < ActiveRecord::Base self.votes = rel_votes.collect { |vote| candidate_ids[ vote - 1 ] } end + def votestring + self.votes.join("") + end + end diff --git a/app/models/voter.rb b/app/models/voter.rb index 44efee6..6246675 100644 --- a/app/models/voter.rb +++ b/app/models/voter.rb @@ -6,8 +6,6 @@ class Voter < ActiveRecord::Base vote.destroy if vote super end - end - diff --git a/app/views/quickvote/_result.rhtml b/app/views/quickvote/_result.rhtml index a326459..e10890a 100644 --- a/app/views/quickvote/_result.rhtml +++ b/app/views/quickvote/_result.rhtml @@ -1,10 +1,10 @@ <% %> <% if result.winner? and result.winners.length == 1%>

The winner is: - <%= @candidates[result.winner].name %>

+ <%= @candidates[result.winner].name.capitalize %>

<% elsif result.winner? and result.winners.length > 1 %>

There was a tie. The winners are: <%= - result.winners.collect {|w| @candidates[w]}.join(", ") %>

+ result.winners.collect {|w| @candidates[w].to_s.capitalize}.join(", ") %>

<% else %>

There is no winner using this method.

<% end %> diff --git a/app/views/quickvote/create.rhtml b/app/views/quickvote/create.rhtml index 7074218..0a5d4aa 100644 --- a/app/views/quickvote/create.rhtml +++ b/app/views/quickvote/create.rhtml @@ -1,15 +1,16 @@ <% -%> -

Create QuickVote

+

<%= @quickvote ? "Review and Confirm" : "Create QuickVote" %>

<%= error_messages_for 'quickvote' %> <% if @quickvote %> -

Please review the data you've entered and confirm. The candidates for -the election submitted include:

+ +

Please review the data you've entered and confirm it. The candidates +for the vote you've submitted include:

@@ -18,27 +19,27 @@ the election submitted include:

<%= form_tag :action => 'create' %> -


+required; 5-12 characters; only letters and numbers; no spaces
-<%= text_field 'quickvote', 'name' %>

+<%= text_field 'quickvote', 'name', :size => 15, :maxsize => 12 %>

-


+


-<%= text_area 'quickvote', 'description', :rows => 2 %>

+<%= text_area 'quickvote', 'description', :cols => 50, :rows => 4 %>


+seperate choices with a ";"; at least two are required
-<%= text_area 'quickvote', 'candidatelist', :rows => 3 %>

+<%= text_area 'quickvote', 'candidatelist', :cols => 50, :rows => 2 %>

<% if @quickvote -%> <%= submit_tag "Confirm" -%> <%= hidden_field :quickvote, :reviewed, :value => 1 %> <% else %> - <%= submit_tag "Create QuickVote" -%> + <%= submit_tag "Submit" -%> <%- end -%>

diff --git a/app/views/quickvote/index.rhtml b/app/views/quickvote/index.rhtml index 2c5bcd1..84211ff 100644 --- a/app/views/quickvote/index.rhtml +++ b/app/views/quickvote/index.rhtml @@ -1,10 +1,18 @@ <% %> -

QuickVote: <%= @voter.election.name %>

-

Description:

-
<%= @voter.election.description %>
+<% if @voter.election.shortdesc %> +

<%= @voter.election.shortdesc %>

+<% else %> +

QuickVote

+<% end %> + +<% if @voter.election.longdesc %> +

Description:

+
<%= @voter.election.longdesc %>
+ +

Vote

+<% end %> -

Vote in Election

<% if @voter.session_id %>

You have already voted. You can:

diff --git a/app/views/quickvote/results.rhtml b/app/views/quickvote/results.rhtml index ad71fa6..e3644c8 100644 --- a/app/views/quickvote/results.rhtml +++ b/app/views/quickvote/results.rhtml @@ -1,36 +1,77 @@ <% %> +

Results

-

<%= @election.name %> Results

+<% if @election.shortdesc %> +

Description:

+
<%= @election.shortdesc %> + <% if @election.longdesc -%> +
+ <%= h(@election.longdesc) -%> + <% end -%> +
+<% end %> + +

Candidates/choices:

+ +
    + <% for candidate in @election.candidates.sort %> +
  1. <%= candidate.name.capitalize %>
  2. + <% end %> +
+ +

Number of voters:

+
+ <%= @election.voters.length %> (see below for details) +
+ +

Winners

-

Total Votes: <%= @election.voters.length %>

-

Condorcet (w/ Cloneproof SSD) Results

+

Condorcet (w/ Cloneproof SSD) Results

<%= render :partial => 'result', :object => @ssd_result %>
-

Plurality Results

+

Plurality Results

<%= render :partial => 'result', :object => @plurality_result %>
-

Approval Result

+

Approval Result

(Assuming top two choices are "approved.")

<%= render :partial => 'result', :object => @approval_result %>
-

Simple Condorcet Results

+

Simple Condorcet Results

<%= render :partial => 'result', :object => @condorcet_result %>
-

Borda Count Results

+

Borda Count Results

<%= render :partial => 'result', :object => @borda_result %>
-

Instant Runoff (IRV) Results

+

Instant Runoff (IRV) Results

<%= render :partial => 'result', :object => @runoff_result %>
- + +
+ +

Voters

+ + + + + + + +<% for voter in @election.voters %> + + + + + +<% end %> +
IP AddressDNS/HostVote
<%= voter.ipaddress %><%= `host #{voter.ipaddress}`.sub(/^.*pointer (.*)\.$/, '\1') %><%= voter.vote.votestring %>
diff --git a/app/views/quickvote/success.rhtml b/app/views/quickvote/success.rhtml index 982fd12..93d6882 100644 --- a/app/views/quickvote/success.rhtml +++ b/app/views/quickvote/success.rhtml @@ -1,14 +1,16 @@ -<% %> +<% -%> +

Your QuickVote Was Created

-

Vote Created +

Please direct voters to:

+ +
+ <%= quickvote_url( :votename => @quickvote.name ) -%> +
+ +

This vote will close on <%= @quickvote.enddate %>

QuickVotes are open to the public but are not publicly listed on the HyperChad site. Voters do not need to log in or authenticate to participate in this election.

-

Direct voters to:

-
<%= quickvote_url( :votename => @quickvote.name ) %>
- -

This vote will expire on <%= @quickvote.enddate %>

- -

<%= link_to "Visit in or vote in your QuickVote", quickvote_url( :votename => @quickvote.name ) %>

+

<%= link_to "Jump to your QuickVote.", quickvote_url( :votename => @quickvote.name ) %>

diff --git a/app/views/quickvote/thanks.rhtml b/app/views/quickvote/thanks.rhtml index 794f412..4104612 100644 --- a/app/views/quickvote/thanks.rhtml +++ b/app/views/quickvote/thanks.rhtml @@ -1,11 +1,11 @@ <% %> - +

Vote Recorded

Your vote has been recorded with the following ranked preferences:

    <% for rank in @voter.vote.rankings.sort %> -
  1. <%= rank.candidate.name %>
  2. +
  3. <%= rank.candidate.name.capitalize %>
  4. <% end %>
diff --git a/app/views/site/index.rhtml b/app/views/site/index.rhtml index b005cb5..92c38cc 100644 --- a/app/views/site/index.rhtml +++ b/app/views/site/index.rhtml @@ -6,11 +6,10 @@

QuickVotes

-

QuickVotes are unstructured votes, more like polls, without -the voter verifiability, anonymity, and other more complex features of -HyperChad. They are the quickest way to make a decision using a variety -of preferential and non-preficial election methods, or to compare -between methods.

+

QuickVotes are like polls: unstructured, non-anonymous and +without the complex features of HyperChad. They are the +quickest way to make a decision or to compare between voting +methods.

<%= link_to "Create QuickVote.", :controller => 'quickvote', :action => 'create' %>

diff --git a/app/views/voter/_vote.rhtml b/app/views/voter/_vote.rhtml index b9a2688..dc240af 100644 --- a/app/views/voter/_vote.rhtml +++ b/app/views/voter/_vote.rhtml @@ -3,12 +3,13 @@

Candidates or choices:

    <% for candidate in @voter.election.candidates.sort %> -
  1. <%= candidate.name %>
  2. +
  3. <%= candidate.name.capitalize %>
  4. <% end %>

In the box below, list each choice in order of most preferred to -least preferred. (For example, 123 or 321 or 213, etc.)

+least preferred. Please list all choices in every vote. +(For example, 123 or 321 or 213, etc.)

<% if @voter.election.quickvote? %> <%= form_tag quickaction_url( :votename => @voter.election.name, :action => 'confirm') %> diff --git a/config/environment.rb b/config/environment.rb index dcc9fad..9eb4d57 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -57,6 +57,16 @@ require 'uniq_token' require 'randarray' require 'rubyvote' +class String + def capitalize + if self.length <= 1 + self.upcase + else + self.split(//)[0].upcase + self..split(//)[1..-1].join("") + end + end +end + module LoginEngine config :salt, "voothingboat" config :email_from, MAIL_CONFIG[:from] diff --git a/db/create.sql b/db/create.sql index a9d430c..e0c264f 100644 --- a/db/create.sql +++ b/db/create.sql @@ -42,6 +42,7 @@ create table voters ( contacted tinyint NOT NULL DEFAULT 0, election_id int NOT NULL, session_id varchar(32) DEFAULT NULL, + ipaddress varchar(32) DEFAULT NULL, constraint fk_election_voter foreign key (election_id) references election(id), primary key (id) ); diff --git a/public/stylesheets/vb.css b/public/stylesheets/vb.css index e694069..0a9f362 100644 --- a/public/stylesheets/vb.css +++ b/public/stylesheets/vb.css @@ -14,8 +14,9 @@ h1, h2, h3, h4 { text-shadow: #999999 0.2em 0.2em 3px; } + a:link { font-weight: bold; color: #BD7589; text-decoration: underline; } -a:visited { color: #BD7589; text-decoration: underline; } +a:visited { font-weight: bold; color: #BD7589; text-decoration: underline; } a:hover { color: #FFFFFF; text-decoration: none; background: #0063DC; } a:active { color: #FFFFFF; text-decoration: none; background: #0259C4; } @@ -67,8 +68,8 @@ a:active { color: #FFFFFF; text-decoration: none; background: #0259C4; } #top h3 { font-size: 30px; } #links { text-align : right; } -#links a { color: #FFF; } -#links a:visited { font-weight: bold; } +#links a { color: #FFF; font-weight: bold; } +#links a:visited { color: #FFF; font-weight: bold; } .ListLine0 { background: #e0f8f8; @@ -112,8 +113,8 @@ a:active { color: #FFFFFF; text-decoration: none; background: #0259C4; } .mainresultbox { width: 100%; padding: 7px; - margin-right: 10px; - margin-bottom: 10px; + margin-right: 30px; + margin-bottom: 30px; border-style: dotted; border-width: 1px; } @@ -131,4 +132,8 @@ a:active { color: #FFFFFF; text-decoration: none; background: #0259C4; } border-width: 1px; } +.clearbox { + clear: both; + margin: 30px; +}