From: Date: Thu, 17 Aug 2006 03:46:31 +0000 (-0400) Subject: Working on a step-by-step workflow audit. X-Git-Url: https://projects.mako.cc/source/selectricity/commitdiff_plain/4efa3e9bc47cc649205a399fde51ed7e61bef7f8 Working on a step-by-step workflow audit. --- diff --git a/app/controllers/election_controller.rb b/app/controllers/election_controller.rb index 625ce93..f4b89b4 100644 --- a/app/controllers/election_controller.rb +++ b/app/controllers/election_controller.rb @@ -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' diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index 6e77b48..8d2f8b2 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -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 diff --git a/app/models/election.rb b/app/models/election.rb index 61286e1..69038e4 100644 --- a/app/models/election.rb +++ b/app/models/election.rb @@ -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 index 0000000..62c5d1d --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,9 @@ +class User < ActiveRecord::Base + include LoginEngine::AuthenticatedUser + has_many :elections + + def name + [ firstname, lastname].join(" ") + end +end + diff --git a/app/views/election/_candidates_form.rhtml b/app/views/election/_candidates_form.rhtml index 814b38f..ca6e73e 100644 --- a/app/views/election/_candidates_form.rhtml +++ b/app/views/election/_candidates_form.rhtml @@ -1,11 +1,15 @@ +<% %>

Please enter candidates for <%= @election.name %>.

- <%= 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" ) %> -

New candidate name: - <%= text_field_tag :newcandidate %> +

New candidate name:
+<%= text_field :newcandidate, :name %>

+ +

Candidate description/platform (optional):
+<%= text_area :newcandidate, :description %>

- <%= submit_tag "Add" %> - <%= end_form_tag %> +<%= submit_tag "Add Candidate" %> +<%= end_form_tag %> diff --git a/app/views/election/_overview_form.rhtml b/app/views/election/_overview_form.rhtml index 4a76b81..899f00b 100644 --- a/app/views/election/_overview_form.rhtml +++ b/app/views/election/_overview_form.rhtml @@ -7,13 +7,15 @@


<%= text_area 'election', 'description' %>

+ -

Election/Voting End Date
+

Election End Date
<%= datetime_select :election, :enddate %>

diff --git a/app/views/election/new_candidates.rhtml b/app/views/election/new_candidates.rhtml index 67525fd..f95cd83 100644 --- a/app/views/election/new_candidates.rhtml +++ b/app/views/election/new_candidates.rhtml @@ -1,5 +1,11 @@ <% @edit = true %> -

<%= @election.name %>: Enter Candidates

+

<%= @election.name %> Candidates

+ + <%= render :partial => 'candidates_form' %> <%= button_to "Done!", :action => 'show', :id => @election %> diff --git a/app/views/layouts/vb.rhtml b/app/views/layouts/vb.rhtml index d4cbb86..a05ae54 100644 --- a/app/views/layouts/vb.rhtml +++ b/app/views/layouts/vb.rhtml @@ -20,14 +20,12 @@ <% if session[:user] %> Welcome <%= session[:user].login.capitalize %> <% 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") %> diff --git a/app/views/site/_basic_login.rhtml b/app/views/site/_basic_login.rhtml index f9bbd4a..cddd8f6 100644 --- a/app/views/site/_basic_login.rhtml +++ b/app/views/site/_basic_login.rhtml @@ -6,7 +6,8 @@
- <%= submit_tag 'Login' %> - <%= link_to 'Register for an account', :controller => 'user', :action => 'signup' %> | - <%= link_to 'Forgot my password', :controller => 'user', :action => 'forgot_password' %>
+

<%= submit_tag 'Login' %>

+

<%= link_to 'Register for a new account?', :controller => 'user', :action => 'signup' %>

+

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

+ <%= end_form_tag %> diff --git a/app/views/site/_user_summary.rhtml b/app/views/site/_user_summary.rhtml new file mode 100644 index 0000000..a231497 --- /dev/null +++ b/app/views/site/_user_summary.rhtml @@ -0,0 +1,17 @@ +<% %> + +

Activity Summary

+ +<% if @current_elections.length < 1 %> + You have not created any elections. +<% else %> + +<% end %> + +

<%= link_to "Create a new election", :controller => 'election', :action => 'new' %>

+

+ diff --git a/app/views/site/index.rhtml b/app/views/site/index.rhtml index 5fce40f..2e4240e 100644 --- a/app/views/site/index.rhtml +++ b/app/views/site/index.rhtml @@ -19,12 +19,16 @@ ongoing election, you can log in to vote using your token here.

-

Vote Administrators

-

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.

+<% if session[:user] %> + <%= render_partial 'user_summary' %> +<% else %> +

Election Administrators

+

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.

-<%= render_partial 'basic_login' %> + <%= render_partial 'basic_login' %> +<% end %> diff --git a/app/views/user/login.rhtml b/app/views/user/login.rhtml new file mode 100644 index 0000000..f4902a4 --- /dev/null +++ b/app/views/user/login.rhtml @@ -0,0 +1,18 @@ +
+

Please Login

+ +
+ <%= start_form_tag :action => 'login' %> + + <%= form_input :text_field, "Login ID", "login", :size => 30 %> + <%= form_input :password_field, "Password", "password", :size => 30 %> +
+ +
+

<%= submit_tag 'Login' %>

+

<%= link_to 'Register for an account', :action => 'signup' %>

+

<%= link_to 'Forgot my password', :action => 'forgot_password' %>

+
+ <%= end_form_tag %> +
+
diff --git a/db/create.sql b/db/create.sql index 0b9b74e..4a2025f 100644 --- a/db/create.sql +++ b/db/create.sql @@ -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) ); diff --git a/public/stylesheets/vb.css b/public/stylesheets/vb.css index 79800a8..a054b85 100644 --- a/public/stylesheets/vb.css +++ b/public/stylesheets/vb.css @@ -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 {