Working on a step-by-step workflow audit.
author<mako@atdot.cc> <>
Thu, 17 Aug 2006 03:46:31 +0000 (23:46 -0400)
committer<mako@atdot.cc> <>
Thu, 17 Aug 2006 03:46:31 +0000 (23:46 -0400)
14 files changed:
app/controllers/election_controller.rb
app/controllers/site_controller.rb
app/models/election.rb
app/models/user.rb [new file with mode: 0644]
app/views/election/_candidates_form.rhtml
app/views/election/_overview_form.rhtml
app/views/election/new_candidates.rhtml
app/views/layouts/vb.rhtml
app/views/site/_basic_login.rhtml
app/views/site/_user_summary.rhtml [new file with mode: 0644]
app/views/site/index.rhtml
app/views/user/login.rhtml [new file with mode: 0644]
db/create.sql
public/stylesheets/vb.css

index 625ce9320b284ee18f792913d74b0bd4f1526f23..f4b89b40cb9c291e41443c1bdf73f502589d4e1e 100644 (file)
@@ -4,35 +4,22 @@ class ElectionController < ApplicationController
 
   before_filter :login_required
 
-  ## general methods for dealing with elections
-  ####################################################################
-  def index
-    list
-    render :action => 'list'
-  end
-
-  def list
-    @election_pages, @elections = paginate :elections, :per_page => 10
-  end
-
   ## methods for displaying, creating,
   ## and manipulating election overview data
   ####################################################################
 
-  def show
-    @election = Election.find(params[:id])
-  end
-
   def new
     @election = Election.new
   end
   
-  def edit
-    @election = Election.find(params[:id])
-  end
-
   def create_election
     @election = Election.new(params[:election])
+    
+    # default options
+    @election.user = session[:user]
+    @election.anonymous = 1
+    @election.startdate = Time.now
+
     if @election.save
       flash[:notice] = 'Election was successfully created.'
       redirect_to :action => 'new_candidates', :id => @election.id
@@ -40,6 +27,16 @@ class ElectionController < ApplicationController
       render :action => 'new'
     end
   end
+  
+  # add filter to verify that the person working on or looking at
+  # something is the owner
+  def edit
+    @election = Election.find(params[:id])
+  end
+
+  def show
+    @election = Election.find(params[:id])
+  end
 
   def update
     @election = Election.find(params[:id])
@@ -66,7 +63,9 @@ class ElectionController < ApplicationController
   def add_candidate
     election = Election.find( params[:id] )
     @candidate = Candidate.new
-    @candidate.name = params[:newcandidate] 
+    @candidate.name = params[:newcandidate][:name]
+    @candidate.description = params[:newcandidate][:description]
+    
     @candidate.save
     election.candidates << @candidate
     render :partial => 'candidate_line'
index 6e77b48ef02835d4a176c8c2af24c852e37d0d6a..8d2f8b2a63c46a719efac7da711c7ad646f7e458 100644 (file)
@@ -1,6 +1,12 @@
 class SiteController < ApplicationController
   layout 'vb'
+  model :user, :election
 
   def index
+    @current_elections = session[:user].elections.sort do |a,b|
+      b.enddate <=> a.enddate
+    end
+
+    
   end
 end
index 61286e1c1829c00e5880dacffda74370de7033bb..69038e473946ceddd9a2a23e5fe7dae7571ba31f 100644 (file)
@@ -2,6 +2,7 @@ class Election < ActiveRecord::Base
   has_many :candidates
   has_many :voters
   has_many :votes
+  belongs_to :user
   validates_presence_of :name, :description
 
   require 'date'
diff --git a/app/models/user.rb b/app/models/user.rb
new file mode 100644 (file)
index 0000000..62c5d1d
--- /dev/null
@@ -0,0 +1,9 @@
+class User < ActiveRecord::Base
+  include LoginEngine::AuthenticatedUser
+  has_many :elections
+
+  def name
+    [ firstname, lastname].join(" ")
+  end
+end
+
index 814b38f29945295cb04af224505cb8f779410dc3..ca6e73ed91e9478c3dfb147a07fe2e83c1809884 100644 (file)
@@ -1,11 +1,15 @@
+<% %>
 <p>Please enter candidates for <strong><%= @election.name %></strong>.</p>
 
-  <%= form_remote_tag(:update => "candidate_list",
-                      :url => { :action => :add_candidate, :id => @election.id },
-                      :position => "top" ) %>
+<%= form_remote_tag(:update => "candidate_list",
+                    :url => { :action => :add_candidate, :id => @election.id },
+                    :position => "bottom" ) %>
 
-  <p>New candidate name:
-  <%= text_field_tag :newcandidate %>
+<p>New candidate name:<br />
+<%= text_field :newcandidate, :name %></p>
+<p>Candidate description/platform (optional):<br />
+<%= text_area :newcandidate, :description %></p>
 
-  <%= submit_tag "Add" %>
-  <%= end_form_tag %>
+<%= submit_tag "Add Candidate" %>
+<%= end_form_tag %>
index 4a76b81269ca3d4715c0eba797832c31a3c3bca2..899f00b72129407ea5192306703789e7f3461ff9 100644 (file)
@@ -7,13 +7,15 @@
 <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>
 
 <p>Election/Voting Start Date<br />
 <%= datetime_select :election, :startdate %></p>
+--> 
 
-<p>Election/Voting End Date<br />
+<p>Election End Date<br />
 <%= datetime_select :election, :enddate %></p>
 
 <!--[eoform:election]-->
index 67525fd4928fe33a02a6b071e5ced2233864d858..f95cd837dc88bc91b94504f4eb12501725c8b545 100644 (file)
@@ -1,5 +1,11 @@
 <% @edit = true %>
-<h1><strong><%= @election.name %>:</strong> Enter Candidates</h1>
+<h1><strong><%= @election.name %></strong> Candidates</h1>
+
+<ul id="candidate_list">
+<% for candidate in @election.candidates %>
+  <li><%= candidate.name %></li>
+<% end %>
+</ul>
 
 <%= render :partial => 'candidates_form' %>
 <%= button_to "Done!", :action => 'show', :id => @election %>
index d4cbb86a5021ef633100126c1f6b64ef4a9852fc..a05ae54ae56ab732d20e0ebd9df331b8bc935841 100644 (file)
              <% if session[:user] %>
                Welcome <strong><%= session[:user].login.capitalize %></strong>
              <% else %>
-               <%= link_to("Login",:controller => "account", :action => "login") %>/<%= link_to("Sign up", :controller => "account", :action => "signup")%>
+               <%= link_to("Login",:controller => "user", :action => "login")
+                %>/<%= link_to("Sign up", :controller => "user", :action => "signup")%>
              <% end %> |
          
-             <%= link_to("Home", :controller => "site", :action => "index")%> |
-             <%= link_to("Browse", :controller => "site", :action => "index")%> |
-
              <% if session[:user] %>
-               <%= link_to("Logout", :controller => "account", :action => "logout") %>  |
+               <%= link_to("Logout", :controller => "user", :action => "logout") %>  |
              <% end %>
              
             <%= link_to("Help/About", :controller => "site", :action => "about") %>
index f9bbd4a856dcdf7851f012b609418706addc6db4..cddd8f6af8caf45ca0d9adfc011b84200e156107 100644 (file)
@@ -6,7 +6,8 @@
     </table>
 
     <div class="button-bar">
-      <%= submit_tag 'Login' %>
-      <%= link_to 'Register for an account', :controller => 'user', :action => 'signup' %> |
-      <%= link_to 'Forgot my password', :controller => 'user', :action => 'forgot_password' %>      </div>
+      <p><%= submit_tag 'Login' %></p>
+      <p><%= link_to 'Register for a new account?', :controller => 'user', :action => 'signup' %></p>
+      <p><%= link_to 'Lost or forgot your password?', :controller => 'user', :action => 'forgot_password' %></p>
+    </div>
   <%= end_form_tag %>
diff --git a/app/views/site/_user_summary.rhtml b/app/views/site/_user_summary.rhtml
new file mode 100644 (file)
index 0000000..a231497
--- /dev/null
@@ -0,0 +1,17 @@
+<% %>
+
+<h2>Activity Summary</h2>
+
+<% if @current_elections.length < 1 %>
+  <em>You have not created any elections.</em>
+<% else %>
+  <ul>
+  <% for election in @current_elections %>
+    <li><%= election.name %> (ends <em><%= election.enddate %></em>)</li> 
+  <% end %>
+  </ul>
+<% end %>
+
+<p><%= link_to "Create a new election", :controller => 'election', :action => 'new' %></p>
+<p></p>
+
index 5fce40fe1d51bfeea3c4267c10a7a364c641e3a1..2e4240e2c3e80a3396336329f65d38e41515515d 100644 (file)
@@ -19,12 +19,16 @@ ongoing election, you can log in to vote using your token here.</p>
 <td width="6%"></td>
 
 <td width="47%" valign="top">
-<h2>Vote Administrators</h2>
 
-<p>You must have an account to start a new election or to administer an
-existing vote. You can log in or create a new account below.</p>
+<% if session[:user] %>
+  <%= render_partial 'user_summary' %> 
+<% else %>
+  <h2>Election Administrators</h2>
+  <p>You must have an account to start a new election or to administer an
+  existing vote. You can log in or create a new account below.</p>
 
-<%= render_partial 'basic_login' %>
+  <%= render_partial 'basic_login' %>
+<% end %>
 </td>
 </tr>
 </table>
diff --git a/app/views/user/login.rhtml b/app/views/user/login.rhtml
new file mode 100644 (file)
index 0000000..f4902a4
--- /dev/null
@@ -0,0 +1,18 @@
+<div title="<%= title_helper %>" class="form">
+  <h3>Please Login</h3>
+
+  <div class="form-padding">
+    <%= start_form_tag :action => 'login'  %>
+      <table>
+        <%= form_input :text_field, "Login ID", "login", :size => 30 %>
+        <%= form_input :password_field, "Password", "password", :size => 30 %>
+      </table>
+
+      <div class="button-bar">
+        <p><%= submit_tag 'Login' %></p>
+        <p><%= link_to 'Register for an account', :action => 'signup' %></p>
+        <p><%= link_to 'Forgot my password', :action => 'forgot_password' %></p>
+      </div>
+    <%= end_form_tag %>
+  </div>
+</div>
index 0b9b74e94e926b2b75128d4fa003f131995ad85c..4a2025f01ff542b820f699d40b5d48ad0586eae8 100644 (file)
@@ -24,7 +24,9 @@ create table elections (
  anonymous tinyint NOT NULL DEFAULT 0, 
  startdate datetime NOT NULL, 
  enddate datetime, 
- primary key (id)
+ user_id int NOT NULL,
+ primary key (id),
+ constraint fk_user_election foreign key (user_id) references users(id)
 );
 
 # CREATE candidates TABLE
@@ -35,6 +37,7 @@ create table candidates (
  id int NOT NULL auto_increment,
  election_id int NOT NULL,
  name varchar(100) NOT NULL, 
+ description text NULL,
  picture blob NOT NULL, 
  primary key (id)
 );
index 79800a819b51f1fb951ae102ee9e9807ca641189..a054b855ac1ba508c7f75c807a9eb2d40d15ebcd 100644 (file)
@@ -10,12 +10,12 @@ body        {
 p, blockquote, ul, ol, dl, dd, li, dir, menu {}
 
 h1, h2, h3, h4 {
-    border-bottom: 1px solid #009999;
+    border-bottom: 1px solid #BD7589;
     text-shadow: #999999 0.2em 0.2em 3px;
 
 }
-a:link { font-weight: bold; color: #066; text-decoration: underline; } 
-a:visited { color: #066; text-decoration: underline; }
+a:link { font-weight: bold; color: #BD7589; text-decoration: underline; } 
+a:visited { color: #BD7589; text-decoration: underline; }
 a:hover { color: #FFFFFF; text-decoration: none; background: #0063DC; }
 a:active { color: #FFFFFF; text-decoration: none; background: #0259C4; }
 
@@ -56,21 +56,18 @@ a:active { color: #FFFFFF; text-decoration: none; background: #0259C4; }
   list-style: square;
 }
 
-
-
-#top { margin : 0px;
-       padding : 3px;
+#top { padding-left: 10px;
+       padding-right: 10px;
+       padding-top: 5px;
+       padding-bottom: 5px;
        font-weight: normal;
-       background: #009999;
+       background: #BD7589;
        color: #FFFFFF;
-       
 }
 
 #top h3 { font-size: 30px; }
-
-#links { text-align : right;
-         margin-right: 50px; }
-#links a { color: #EAFFD0; }
+#links { text-align : right; }
+#links a { color: #FFF; }
 #links a:visited { font-weight: bold; }
 
 .ListLine0 {

Benjamin Mako Hill || Want to submit a patch?