]> projects.mako.cc - selectricity/commitdiff
Initital scaffolding of the website plus initial work on the adding and
author<mako@atdot.cc> <>
Wed, 12 Jul 2006 23:58:33 +0000 (19:58 -0400)
committer<mako@atdot.cc> <>
Wed, 12 Jul 2006 23:58:33 +0000 (19:58 -0400)
editing general information for votes and list of candidates. The first
steps toward importing voters has also been added.

24 files changed:
.bzrignore
app/controllers/elections_controller.rb [new file with mode: 0644]
app/helpers/elections_helper.rb [new file with mode: 0644]
app/models/candidate.rb [new file with mode: 0644]
app/models/election.rb [new file with mode: 0644]
app/views/elections/_candidate_line.rhtml [new file with mode: 0644]
app/views/elections/_candidates_form.rhtml [new file with mode: 0644]
app/views/elections/_overview_form.rhtml [new file with mode: 0644]
app/views/elections/edit.rhtml [new file with mode: 0644]
app/views/elections/edit_candidates.rhtml [new file with mode: 0644]
app/views/elections/edit_voters.rhtml [new file with mode: 0644]
app/views/elections/list.rhtml [new file with mode: 0644]
app/views/elections/new.rhtml [new file with mode: 0644]
app/views/elections/new_candidates.rhtml [new file with mode: 0644]
app/views/elections/show.rhtml [new file with mode: 0644]
app/views/layouts/elections.rhtml [new file with mode: 0644]
log/development.log [deleted file]
log/production.log [deleted file]
log/server.log [deleted file]
log/test.log [deleted file]
public/stylesheets/scaffold.css [new file with mode: 0644]
test/fixtures/elections.yml [new file with mode: 0644]
test/functional/elections_controller_test.rb [new file with mode: 0644]
test/unit/election_test.rb [new file with mode: 0644]

index b5649dd032e81aa0bf153efcb1d90e9bbfe20df4..1ef4de884f5cc39c975e05415327863b693ce328 100644 (file)
@@ -1 +1,2 @@
 database.yml
+log
diff --git a/app/controllers/elections_controller.rb b/app/controllers/elections_controller.rb
new file mode 100644 (file)
index 0000000..2b1f282
--- /dev/null
@@ -0,0 +1,73 @@
+class ElectionsController < ApplicationController
+  def index
+    list
+    render :action => 'list'
+  end
+
+  def list
+    @election_pages, @elections = paginate :elections, :per_page => 10
+  end
+
+  def show
+    @election = Election.find(params[:id])
+  end
+
+  def new
+    @election = Election.new
+  end
+
+  def create_election
+    @election = Election.new(params[:election])
+    if @election.save
+      flash[:notice] = 'Election was successfully created.'
+      redirect_to :action => 'new_candidates', :id => @election.id
+    else
+      render :action => 'new'
+    end
+  end
+
+  def new_candidates
+    @election = Election.find( params[:id] )
+  end
+
+  def add_candidate
+    election = Election.find( params[:id] )
+    @candidate = Candidate.new
+    @candidate.name = params[:newcandidate] 
+    @candidate.save
+    election.candidates << @candidate
+    render :partial => 'candidate_line'
+  end
+  
+  def delete_candidate
+    candidate = Candidate.find( params[:id] )
+    candidate.destroy
+  end
+
+  def edit
+    @election = Election.find(params[:id])
+  end
+
+  def edit_candidates
+    @election = Election.find( params[:id] )
+  end
+  
+  def edit_voters
+    @election = Election.find( params[:id] )
+  end
+  
+  def update
+    @election = Election.find(params[:id])
+    if @election.update_attributes(params[:election])
+      flash[:notice] = 'Election was successfully updated.'
+      redirect_to :action => 'show', :id => @election
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    election = Election.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+end
diff --git a/app/helpers/elections_helper.rb b/app/helpers/elections_helper.rb
new file mode 100644 (file)
index 0000000..09497b1
--- /dev/null
@@ -0,0 +1,2 @@
+module ElectionsHelper
+end
diff --git a/app/models/candidate.rb b/app/models/candidate.rb
new file mode 100644 (file)
index 0000000..41d743b
--- /dev/null
@@ -0,0 +1,2 @@
+class Candidate < ActiveRecord::Base
+end
diff --git a/app/models/election.rb b/app/models/election.rb
new file mode 100644 (file)
index 0000000..be828d0
--- /dev/null
@@ -0,0 +1,12 @@
+class Election < ActiveRecord::Base
+  has_many :candidates
+  validates_presence_of :name, :description
+
+  def destroy
+    self.candidates.each do |candidate|
+      candidate.destroy
+    end
+    super destroy
+  end
+  
+end
diff --git a/app/views/elections/_candidate_line.rhtml b/app/views/elections/_candidate_line.rhtml
new file mode 100644 (file)
index 0000000..7f68e6f
--- /dev/null
@@ -0,0 +1,11 @@
+<div id="cand<%= @candidate.id %>">
+  <li>
+    <%= @candidate.name %>
+    <% if @edit %>
+      <%= link_to_remote "Delete",
+                         :complete => "Element.remove('cand#{@candidate.id}')",
+                        :url => { :action => :delete_candidate, :id => @candidate.id } %>
+    <% end %>
+
+  </li>
+</div>
diff --git a/app/views/elections/_candidates_form.rhtml b/app/views/elections/_candidates_form.rhtml
new file mode 100644 (file)
index 0000000..d739dbf
--- /dev/null
@@ -0,0 +1,18 @@
+<p>Please enter candidates for <strong><%= @election.name %></strong>.</p>
+
+  <ul id="candidates_list">
+     <% @election.candidates.each do |candidate| %>
+       <% @candidate = candidate %>
+       <%= render :partial => 'candidate_line' %>
+     <% end %>
+  </ul>
+
+  <%= form_remote_tag(:update => "candidates_list",
+                      :url => { :action => :add_candidate, :id => @election.id },
+                      :position => "top" ) %>
+
+  <p>New candidate name:
+  <%= text_field_tag :newcandidate %>
+
+  <%= submit_tag "Add" %>
+  <%= end_form_tag %>
diff --git a/app/views/elections/_overview_form.rhtml b/app/views/elections/_overview_form.rhtml
new file mode 100644 (file)
index 0000000..b3715e1
--- /dev/null
@@ -0,0 +1,13 @@
+<%= error_messages_for 'election' %>
+
+<!--[form:election]-->
+<p><label for="election_name">Name</label><br/>
+<%= text_field 'election', 'name'  %></p>
+
+<p><label for="election_description">Description</label><br/>
+<%= text_area 'election', 'description'  %></p>
+
+<p><label for="election_anonymous">Anonymous Vote</label>
+<%= check_box 'election', 'anonymous', {}, 1, 0  %></p>
+<!--[eoform:election]-->
+
diff --git a/app/views/elections/edit.rhtml b/app/views/elections/edit.rhtml
new file mode 100644 (file)
index 0000000..af0cb49
--- /dev/null
@@ -0,0 +1,6 @@
+<h1><strong><%= @election.name %>:</strong> Edit Overview</h1>
+
+<%= start_form_tag :action => 'update', :id => @election %>
+  <%= render :partial => 'overview_form' %>
+  <%= submit_tag 'Done!' %>
+<%= end_form_tag %>
diff --git a/app/views/elections/edit_candidates.rhtml b/app/views/elections/edit_candidates.rhtml
new file mode 100644 (file)
index 0000000..2809d10
--- /dev/null
@@ -0,0 +1,5 @@
+<% @edit = true %>
+<h1><strong><%= @election.name %>:</strong> Edit Candidates</h1>
+
+<%= render :partial => 'candidates_form' %>
+<%= button_to "Done!", :action => 'show', :id => @election %>
diff --git a/app/views/elections/edit_voters.rhtml b/app/views/elections/edit_voters.rhtml
new file mode 100644 (file)
index 0000000..64ec446
--- /dev/null
@@ -0,0 +1,4 @@
+<% @edit = true %>
+<h1><strong><%= @election.name %>:</strong> Edit Voter Rolls</h1>
+
+<%= button_to "Done!", :action => 'show', :id => @election %>
diff --git a/app/views/elections/list.rhtml b/app/views/elections/list.rhtml
new file mode 100644 (file)
index 0000000..40e24b5
--- /dev/null
@@ -0,0 +1,27 @@
+<h1>Listing elections</h1>
+
+<table>
+  <tr>
+  <% for column in Election.content_columns %>
+    <th><%= column.human_name %></th>
+  <% end %>
+  </tr>
+  
+<% for election in @elections %>
+  <tr>
+  <% for column in Election.content_columns %>
+    <td><%=h election.send(column.name) %></td>
+  <% end %>
+    <td><%= link_to 'Show', :action => 'show', :id => election %></td>
+    <td><%= link_to 'Edit', :action => 'edit', :id => election %></td>
+    <td><%= link_to 'Destroy', { :action => 'destroy', :id => election }, :confirm => 'Are you sure?' %></td>
+  </tr>
+<% end %>
+</table>
+
+<%= link_to 'Previous page', { :page => @election_pages.current.previous } if @election_pages.current.previous %>
+<%= link_to 'Next page', { :page => @election_pages.current.next } if @election_pages.current.next %> 
+
+<br />
+
+<%= link_to 'New election', :action => 'new' %>
diff --git a/app/views/elections/new.rhtml b/app/views/elections/new.rhtml
new file mode 100644 (file)
index 0000000..5e6fa1f
--- /dev/null
@@ -0,0 +1,9 @@
+<h1>Create A New Election</h1>
+
+<h2>Step 1: Describe The Election</h2>
+
+<%= form_tag :action => 'create_election' %>
+  <%= render :partial => 'overview_form' %>
+  <%= submit_tag "Done!" %>
+<%= end_form_tag %>
+
diff --git a/app/views/elections/new_candidates.rhtml b/app/views/elections/new_candidates.rhtml
new file mode 100644 (file)
index 0000000..67525fd
--- /dev/null
@@ -0,0 +1,5 @@
+<% @edit = true %>
+<h1><strong><%= @election.name %>:</strong> Enter Candidates</h1>
+
+<%= render :partial => 'candidates_form' %>
+<%= button_to "Done!", :action => 'show', :id => @election %>
diff --git a/app/views/elections/show.rhtml b/app/views/elections/show.rhtml
new file mode 100644 (file)
index 0000000..0ef2fc5
--- /dev/null
@@ -0,0 +1,23 @@
+<h1>Information On <%= @election.name %></h1>
+
+<h2>Overview <%= link_to "edit", :action => 'edit', :id => @election.id %></h2> 
+
+<p><strong>Description</strong></p>
+
+<blockquote>
+<%= @election.description %>
+</blockquote>
+
+<h2>Candidates <%= link_to "edit", :action => 'edit_candidates', :id => @election.id %></h2> 
+
+
+The following are valid options or candidates in this election:
+
+<ul>
+<% @election.candidates.each do |candidate| %>
+   <% @candidate = candidate %>
+   <%= render :partial => 'candidate_line' %>
+<% end %>
+</ul>
+
+<h2>Voters <%= link_to "edit", :action => 'edit_voters', :id => @election.id %></h2>
diff --git a/app/views/layouts/elections.rhtml b/app/views/layouts/elections.rhtml
new file mode 100644 (file)
index 0000000..fbac7a9
--- /dev/null
@@ -0,0 +1,14 @@
+<html>
+<head>
+  <title>Elections: <%= controller.action_name %></title>
+  <%= javascript_include_tag "prototype", "effects" %>
+  <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= @content_for_layout %>
+
+</body>
+</html>
diff --git a/log/development.log b/log/development.log
deleted file mode 100644 (file)
index 607602c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-nil
diff --git a/log/production.log b/log/production.log
deleted file mode 100644 (file)
index 607602c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-nil
diff --git a/log/server.log b/log/server.log
deleted file mode 100644 (file)
index 607602c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-nil
diff --git a/log/test.log b/log/test.log
deleted file mode 100644 (file)
index 607602c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-nil
diff --git a/public/stylesheets/scaffold.css b/public/stylesheets/scaffold.css
new file mode 100644 (file)
index 0000000..de2ccc5
--- /dev/null
@@ -0,0 +1,74 @@
+body { background-color: #fff; color: #333; }
+
+body, p, ol, ul, td {
+  font-family: verdana, arial, helvetica, sans-serif;
+  font-size:   13px;
+  line-height: 18px;
+}
+
+pre {
+  background-color: #eee;
+  padding: 10px;
+  font-size: 11px;
+}
+
+a { color: #000; }
+a:visited { color: #666; }
+a:hover { color: #fff; background-color:#000; }
+
+.fieldWithErrors {
+  padding: 2px;
+  background-color: red;
+  display: table;
+}
+
+#ErrorExplanation {
+  width: 400px;
+  border: 2px solid red;
+  padding: 7px;
+  padding-bottom: 12px;
+  margin-bottom: 20px;
+  background-color: #f0f0f0;
+}
+
+#ErrorExplanation h2 {
+  text-align: left;
+  font-weight: bold;
+  padding: 5px 5px 5px 15px;
+  font-size: 12px;
+  margin: -7px;
+  background-color: #c00;
+  color: #fff;
+}
+
+#ErrorExplanation p {
+  color: #333;
+  margin-bottom: 0;
+  padding: 5px;
+}
+
+#ErrorExplanation ul li {
+  font-size: 12px;
+  list-style: square;
+}
+
+div.uploadStatus {
+  margin: 5px;
+}
+
+div.progressBar {
+  margin: 5px;
+}
+
+div.progressBar div.border {
+  background-color: #fff;
+  border: 1px solid grey;
+  width: 100%;
+}
+
+div.progressBar div.background {
+  background-color: #333;
+  height: 18px;
+  width: 0%;
+}
+
diff --git a/test/fixtures/elections.yml b/test/fixtures/elections.yml
new file mode 100644 (file)
index 0000000..8794d28
--- /dev/null
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+first:
+  id: 1
+another:
+  id: 2
diff --git a/test/functional/elections_controller_test.rb b/test/functional/elections_controller_test.rb
new file mode 100644 (file)
index 0000000..1873304
--- /dev/null
@@ -0,0 +1,88 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'elections_controller'
+
+# Re-raise errors caught by the controller.
+class ElectionsController; def rescue_action(e) raise e end; end
+
+class ElectionsControllerTest < Test::Unit::TestCase
+  fixtures :elections
+
+  def setup
+    @controller = ElectionsController.new
+    @request    = ActionController::TestRequest.new
+    @response   = ActionController::TestResponse.new
+  end
+
+  def test_index
+    get :index
+    assert_response :success
+    assert_template 'list'
+  end
+
+  def test_list
+    get :list
+
+    assert_response :success
+    assert_template 'list'
+
+    assert_not_nil assigns(:elections)
+  end
+
+  def test_show
+    get :show, :id => 1
+
+    assert_response :success
+    assert_template 'show'
+
+    assert_not_nil assigns(:election)
+    assert assigns(:election).valid?
+  end
+
+  def test_new
+    get :new
+
+    assert_response :success
+    assert_template 'new'
+
+    assert_not_nil assigns(:election)
+  end
+
+  def test_create
+    num_elections = Election.count
+
+    post :create, :election => {}
+
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_equal num_elections + 1, Election.count
+  end
+
+  def test_edit
+    get :edit, :id => 1
+
+    assert_response :success
+    assert_template 'edit'
+
+    assert_not_nil assigns(:election)
+    assert assigns(:election).valid?
+  end
+
+  def test_update
+    post :update, :id => 1
+    assert_response :redirect
+    assert_redirected_to :action => 'show', :id => 1
+  end
+
+  def test_destroy
+    assert_not_nil Election.find(1)
+
+    post :destroy, :id => 1
+    assert_response :redirect
+    assert_redirected_to :action => 'list'
+
+    assert_raise(ActiveRecord::RecordNotFound) {
+      Election.find(1)
+    }
+  end
+end
diff --git a/test/unit/election_test.rb b/test/unit/election_test.rb
new file mode 100644 (file)
index 0000000..60663cf
--- /dev/null
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ElectionTest < Test::Unit::TestCase
+  fixtures :elections
+
+  # Replace this with your real tests.
+  def test_truth
+    assert_kind_of Election, elections(:first)
+  end
+end

Benjamin Mako Hill || Want to submit a patch?