From:
Date: Fri, 28 Nov 2008 18:35:26 +0000 (-0500)
Subject: Major update of Selectricity to work with Rails 2.2.2 from 1.2!
X-Git-Url: https://projects.mako.cc/source/selectricity-live/commitdiff_plain/ad088c1324d08a65f6f5336bedf7a88a8a8950e7?ds=inline
Major update of Selectricity to work with Rails 2.2.2 from 1.2!
This included a large number of changes:
- removal of randarray.rb (features are not in the new version or ruby)
- removal of sparklines plugin and replacement with gemified version of
sparklines and sparklines_generator
- addition of act_as_list plugin which is no longer in rails
- disabling of all API code because action_web_service is deprecated in
favor of active_resource (!!!!)
- large number of miscellaneous updates to do the new rails 2ish
I've commented out the new features in the views (i.e., embedded) as
this is going to replace the LIVE version of Selectricity. We should
then test this well, slowly enable the new features, and get the tests i
old_api_code back work with an active_resource interface.
---
diff --git a/app/controllers/election_controller.rb b/app/controllers/election_controller.rb
index 3e16964..5c13a81 100644
--- a/app/controllers/election_controller.rb
+++ b/app/controllers/election_controller.rb
@@ -45,6 +45,7 @@ class ElectionController < ApplicationController
@election.user = session[:user]
@election.anonymous = 1
@election.startdate = Time.now
+ @election.type = 'Election'
holder = create_theme_hash
unless holder.values.all? {|v| v.has_value?("")}
diff --git a/app/controllers/quickvote_controller.rb b/app/controllers/quickvote_controller.rb
index 768bdea..c32d585 100644
--- a/app/controllers/quickvote_controller.rb
+++ b/app/controllers/quickvote_controller.rb
@@ -17,6 +17,7 @@
# .
class QuickvoteController < ApplicationController
+ helper :sparklines
layout 'main'
require_dependency "quick_voter"
require_dependency "quick_vote"
@@ -94,7 +95,7 @@ class QuickvoteController < ApplicationController
end
end
flash.keep(:candidate_names)
- render_partial 'candidate_list'
+ render :partial => 'candidate_list'
end
#############################################################
@@ -163,9 +164,6 @@ class QuickvoteController < ApplicationController
@voter.ipaddress = request.env["REMOTE_ADDR"]
@voter.save
- # save the time the vote was made for statistical use
- @voter.vote.time = Time.now
-
# toggle the confirmation bit
@voter.vote.confirm!
diff --git a/app/controllers/sparklines_controller.rb b/app/controllers/sparklines_controller.rb
index d08bbc5..50a330f 100644
--- a/app/controllers/sparklines_controller.rb
+++ b/app/controllers/sparklines_controller.rb
@@ -1,61 +1,30 @@
-# Selectricity: Voting Machinery for the Masses
-# Copyright (C) 2007, 2008 Benjamin Mako Hill
-# Copyright (C) 2007 Massachusetts Institute of Technology
+
+# Handles requests for sparkline graphs.
#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# You shouldn't need to edit or extend this, but you can read
+# the documentation for SparklinesHelper to see how to call it from
+# another view.
#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
+# AUTHOR
+#
+# Geoffrey Grosenbach[mailto:boss@topfunky.com]
+#
+# http://topfunky.com
#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# .
-
class SparklinesController < ApplicationController
- # Handles requests for sparkline graphs from views.
- #
- # Params are generated by the sparkline_tag helper method.
- #
- def index
- # Make array from comma-delimited list of data values
- ary = []
- if params.has_key?('results') && !params['results'].nil?
- params['results'].split(',').each do |s|
- ary << s.to_i
- end
- end
+ layout nil
+
+ def index
+ # Make array from comma-delimited list of data values
+ ary = []
+ params['results'].split(',').each do |s|
+ ary << s.to_i
+ end
+
+ send_data( Sparklines.plot( ary, params ),
+ :disposition => 'inline',
+ :type => 'image/png',
+ :filename => "spark_#{params[:type]}.png" )
+ end
- send_data( Sparklines.plot( ary, params ),
- :disposition => 'inline',
- :type => 'image/png',
- :filename => "spark_#{params[:type]}.png" )
- end
-
- def spark_pie
- send_data(Sparklines.plot( ))
- end
- # Use this type of method for sparklines that can be cached. (Doesn't work with the helper.)
- #
- # To make caching easier, add a line like this to config/routes.rb:
- # map.sparklines "sparklines/:action/:id/image.png", :controller => "sparklines"
- #
- # Then reference it with the named route:
- # image_tag sparklines_url(:action => 'show', :id => 42)
- def show
- send_data(Sparklines.plot(
- [42, 37, 89, 74, 70, 50, 40, 30, 40, 50],
- :type => 'bar', :above_color => 'orange'
- ),
- :disposition => 'inline',
- :type => 'image/png',
- :filename => "sparkline.png")
- end
-
-
-
end
diff --git a/app/controllers/voter_controller.rb b/app/controllers/voter_controller.rb
index 9e88e9e..45b9a1a 100644
--- a/app/controllers/voter_controller.rb
+++ b/app/controllers/voter_controller.rb
@@ -17,6 +17,7 @@
# .
class VoterController < ApplicationController
+ helper :sparklines
layout 'main'
require_dependency "voter"
require_dependency "vote"
@@ -106,8 +107,8 @@ class VoterController < ApplicationController
def details
if authenticate
@election = @voter.election
- @votes = @election.votes.select {|v| v.confirmed? }.randomize
- @voters = @votes.collect {|v| v.voter}.randomize
+ @votes = @election.votes.select {|v| v.confirmed? }.shuffle
+ @voters = @votes.collect {|v| v.voter}.shuffle
render :action => 'details'
else
redirect_to :action => 'index'
diff --git a/app/helpers/front_helper.rb b/app/helpers/front_helper.rb
deleted file mode 100644
index c879486..0000000
--- a/app/helpers/front_helper.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-module SiteHelper
-end
diff --git a/vendor/plugins/sparklines/lib/sparklines_helper.rb b/app/helpers/sparklines_helper.rb
similarity index 55%
rename from vendor/plugins/sparklines/lib/sparklines_helper.rb
rename to app/helpers/sparklines_helper.rb
index c8958d3..9376e89 100644
--- a/vendor/plugins/sparklines/lib/sparklines_helper.rb
+++ b/app/helpers/sparklines_helper.rb
@@ -1,18 +1,30 @@
+
# Provides a tag for embedding sparklines graphs into your Rails app.
#
+# To use, load it in your controller with
+#
+# helper :sparklines
+#
+# AUTHOR
+#
+# Geoffrey Grosenbach[mailto:boss@topfunky.com]
+#
+# http://topfunky.com
+#
+# License
+#
+# This code is licensed under the MIT license.
+#
module SparklinesHelper
# Call with an array of data and a hash of params for the Sparklines module.
- #
- # sparkline_tag [42, 37, 43, 182], :type => 'bar', :line_color => 'black'
- #
# You can also pass :class => 'some_css_class' ('sparkline' by default).
def sparkline_tag(results=[], options={})
url = { :controller => 'sparklines',
:results => results.join(',') }
options = url.merge(options)
- %()
+ ""
end
end
diff --git a/app/models/vote.rb b/app/models/vote.rb
index bef3502..d3010df 100644
--- a/app/models/vote.rb
+++ b/app/models/vote.rb
@@ -39,7 +39,7 @@ class Vote < ActiveRecord::Base
if rankings.empty?
@votes = Array.new
else
- @votes = rankings.sort.collect { |ranking| ranking.candidate.id }
+ @votes = self.rankings.sort.collect { |ranking| ranking.candidate.id }
end
end
@@ -51,6 +51,9 @@ class Vote < ActiveRecord::Base
end
def save_rankings
+ self.votes # i need to initalize this before destroying rankings
+ # or else the ranks themselves show up as nil
+
destroy_rankings
self.votes.each_with_index do |candidate_id, index|
ranking = Ranking.new
diff --git a/app/views/common/_methodinfo_condorcet.rhtml b/app/views/common/_methodinfo_condorcet.rhtml
index 1cb5fae..743dd45 100644
--- a/app/views/common/_methodinfo_condorcet.rhtml
+++ b/app/views/common/_methodinfo_condorcet.rhtml
@@ -13,7 +13,7 @@ another Condorcet system.
<% candidates = @election.ssd_result.ranked_candidates.flatten -%>
<% if candidates.size <= 7 -%>
- <%= render_partial 'common/pref_tables' %>
+ <%= render :partial => 'common/pref_tables' %>
<% else %>
There are too many candidates in your elections to show the result
diff --git a/app/views/common/_methodinfo_ssd.rhtml b/app/views/common/_methodinfo_ssd.rhtml
index 25bc354..00f9feb 100644
--- a/app/views/common/_methodinfo_ssd.rhtml
+++ b/app/views/common/_methodinfo_ssd.rhtml
@@ -25,7 +25,7 @@ Beatpath Winner, Path Voting, and Path Winner.
<% candidates = @election.ssd_result.ranked_candidates.flatten -%>
<% if candidates.size <= 7 -%>
- <%= render_partial 'common/pref_tables' %>
+ <%= render :partial => 'common/pref_tables' %>
<% else %>
There are too many candidates in your elections to show the result
diff --git a/app/views/common/pref_tables.rhtml b/app/views/common/pref_tables.rhtml
index 1215c7b..55b864f 100644
--- a/app/views/common/pref_tables.rhtml
+++ b/app/views/common/pref_tables.rhtml
@@ -1 +1 @@
-<%= render_partial 'common/pref_tables' %>
+<%= render :partial => 'common/pref_tables' %>
diff --git a/app/views/election/_overview_form.rhtml b/app/views/election/_overview_form.rhtml
index 8d1861d..eed92da 100644
--- a/app/views/election/_overview_form.rhtml
+++ b/app/views/election/_overview_form.rhtml
@@ -23,10 +23,11 @@
<% type_hash = {}; ELECTION_TYPES.each {|k,v| type_hash[v] = k} %>
<%= select_tag 'election[election_method]', options_for_select(type_hash, @election.election_method) %>
-