Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Lots of Ajax features for placing bets, worked on determining current…

… week, different views for picks, weekly breakdowns, scores, etc
  • Loading branch information...
commit f9184a24b9fa88bffab550067ef50511d342dfe3 1 parent d02549d
unknown authored
Showing with 641 additions and 107 deletions.
  1. BIN  app/assets/images/Ob8gE.gif
  2. BIN  app/assets/images/default_large.png
  3. BIN  app/assets/images/default_small.png
  4. BIN  app/assets/images/default_thumb.png
  5. +3 −0  app/assets/javascripts/bet.js.coffee
  6. +7 −0 app/assets/stylesheets/application.css
  7. +3 −0  app/assets/stylesheets/bet.css.scss
  8. +4 −4 app/assets/stylesheets/bootstrap.css
  9. +1 −1  app/controllers/application_controller.rb
  10. +33 −0 app/controllers/bet_controller.rb
  11. +39 −2 app/controllers/picks_controller.rb
  12. +9 −0 app/controllers/season_controller.rb
  13. +30 −0 app/controllers/seasonmembership_controller.rb
  14. +2 −0  app/controllers/session_controller.rb
  15. +0 −5 app/controllers/user_controller.rb
  16. +2 −0  app/helpers/bet_helper.rb
  17. +5 −0 app/models/application.rb
  18. +8 −0 app/models/bet.rb
  19. +33 −0 app/models/game.rb
  20. +8 −0 app/models/season.rb
  21. +5 −0 app/models/seasonmembership.rb
  22. +70 −10 app/models/user.rb
  23. +30 −0 app/models/week.rb
  24. +17 −0 app/views/bet/create.js.erb
  25. +43 −7 app/views/layouts/application.html.erb
  26. +62 −0 app/views/picks/leaguepicks.html.erb
  27. +81 −0 app/views/picks/mypicks.html.erb
  28. +37 −0 app/views/picks/overview.html.erb
  29. +2 −2 app/views/season/index.html.erb
  30. +1 −0  app/views/season/show.html.erb
  31. +1 −0  app/views/seasonmembership/approve.js.erb
  32. +7 −0 app/views/seasonmembership/create.js.erb
  33. +1 −0  app/views/seasonmembership/deny.js.erb
  34. +3 −3 app/views/seasonmembership/index.html.erb
  35. +27 −7 app/views/session/new.html.erb
  36. +25 −0 app/views/user/index.html.erb
  37. +6 −3 app/views/user/profile.html.erb
  38. +1 −1  app/views/user/show.html.erb
  39. +10 −60 config/routes.rb
  40. +1 −1  db/migrate/20120125182840_create_seasons.rb
  41. +9 −0 db/migrate/20120315202319_add_week_start_to_week.rb
  42. +2 −1  db/schema.rb
  43. +2 −0  db/seeds.rb
  44. +7 −0 test/functional/bet_controller_test.rb
  45. +4 −0 test/unit/helpers/bet_helper_test.rb
BIN  app/assets/images/Ob8gE.gif
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  app/assets/images/default_large.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  app/assets/images/default_small.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  app/assets/images/default_thumb.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3  app/assets/javascripts/bet.js.coffee
View
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
7 app/assets/stylesheets/application.css
View
@@ -18,3 +18,10 @@
margin-top: 10px;
}
+
+.footer
+{
+ margin-top: 45px;
+ padding: 35px 0 36px;
+ border-top: 1px solid #E5E5E5;
+}
3  app/assets/stylesheets/bet.css.scss
View
@@ -0,0 +1,3 @@
+// Place all the styles related to the bet controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
8 app/assets/stylesheets/bootstrap.css
View
@@ -96,7 +96,7 @@ textarea {
}
body {
margin: 0;
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+ font-family: Helvetica, Arial, sans-serif;
font-size: 13px;
line-height: 18px;
color: #333333;
@@ -275,7 +275,7 @@ a:hover {
}
p {
margin: 0 0 9px;
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+ font-family: Helvetica, Arial, sans-serif;
font-size: 13px;
line-height: 18px;
}
@@ -520,7 +520,7 @@ input,
button,
select,
textarea {
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+ font-family: Helvetica, Arial, sans-serif;
font-size: 13px;
font-weight: normal;
line-height: 18px;
@@ -2459,7 +2459,7 @@ button.btn.small, input[type="submit"].btn.small {
}
.navbar-search .search-query {
padding: 4px 9px;
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+ font-family: Helvetica, Arial, sans-serif;
font-size: 13px;
font-weight: normal;
line-height: 1;
2  app/controllers/application_controller.rb
View
@@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
def authorize
@me ||= User.find_by_id(session[:user_id])
- @current_season ||= Season.find(:last)
+ @current_week = Week.get_current_week
unless @me
redirect_to login_url, :notice => "Please Log In"
33 app/controllers/bet_controller.rb
View
@@ -0,0 +1,33 @@
+class BetController < ApplicationController
+
+
+ def create
+
+ user = @me
+ game = Game.find(params[:game_id])
+ team = Team.find(params[:team_id])
+
+ #This will not allow someone to bet if they are not a member of this season
+ return nil unless (user.seasons.include?(game.week.season))
+
+ #This makes sure you are betting on a team that is playing in the game.
+ return nil unless (game.hometeam == team || game.awayteam == team)
+
+ #This makes sure you are not betting more than once for a game.
+ return nil if (Bet.where(:game_id => game.id, :user_id => @me.id).count > 0)
+
+ #This makes sure you are not betting a game that has already started.
+ return nil if (game.has_started_yet)
+
+ @bet = Bet.create(:user_id => @me.id, :game_id => game.id, :team_id => team.id)
+
+
+ if @bet then
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ end
+
+end
41 app/controllers/picks_controller.rb
View
@@ -1,12 +1,49 @@
class PicksController < ApplicationController
- def index
+ def mypicks
@season = Season.find(params[:season_id])
redirect_to error_url unless @me.seasons.include?(@season)
- @week = @season.weeks.where(:number => params[:week_id]).first
+ @week = @season.weeks.where(:number => params[:week_num]).first
+ end
+
+ def leaguepicks
+
+ @season = Season.find(params[:season_id])
+
+ redirect_to error_url unless @me.seasons.include?(@season)
+
+ @users = @season.users.sort {|x,y| y.points_for_season(@season) <=> x.points_for_season(@season)}
+
+ @week = @season.weeks.where(:number => params[:week_num]).first
+
+ end
+
+ def overview
+
+ @season = Season.find(params[:season_id])
+
+ @users = @season.users.sort {|x,y| y.points_for_season(@season) <=> x.points_for_season(@season)}
+
+
+ end
+
+ def clear
+
+ @season = Season.find(params[:season_id])
+
+ week = @season.weeks.where(:number => params[:week_num]).first
+
+ return nil if week.has_started_yet
+
+ week.bets.each do |bet|
+ bet.destroy
+ end
+
+ redirect_to action: "mypicks", :season_id => @season.id, :week_num => week.number
+
end
9 app/controllers/season_controller.rb
View
@@ -7,5 +7,14 @@ def index
end
+ def show
+ @season = Season.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @season }
+ end
+ end
+
end
30 app/controllers/seasonmembership_controller.rb
View
@@ -1,12 +1,42 @@
class SeasonmembershipController < ApplicationController
+ before_filter :authorize_role, :except => ['create']
+
def create
Seasonmembership.create(:season_id => params[:id], :user_id => @me.id, :approved => false) unless Seasonmembership.where(:season_id => params[:id], :user_id => @me.id).exists?
+
+ respond_to do |format|
+ format.js
+ end
+
end
def index
@awaiting_confirmation = Seasonmembership.where(:approved => false)
end
+ def approve
+
+ season_membership = Seasonmembership.find(params[:id])
+
+ season_membership.approve_season
+
+ respond_to do |format|
+ if season_membership.save
+ format.js
+ end
+ end
+
+ end
+
+ def deny
+
+ Seasonmembership.delete(params[:id])
+
+ respond_to do |format|
+ format.js
+ end
+ end
+
end
2  app/controllers/session_controller.rb
View
@@ -21,4 +21,6 @@ def destroy
redirect_to login_url, :notice => "Successfully Logged Out."
end
+
+
end
5 app/controllers/user_controller.rb
View
@@ -53,11 +53,6 @@ def profile
end
end
- def update_bank
- @user = User.find(session[:user_id])
- @user.bank = 9999.99
- @user.save
- end
def error
@user = User.find(session[:user_id])
2  app/helpers/bet_helper.rb
View
@@ -0,0 +1,2 @@
+module BetHelper
+end
5 app/models/application.rb
View
@@ -1,3 +1,8 @@
class Application < ActiveRecord::Base
+ def self.get_current_time
+ #Time.now
+ DateTime.new(2011, 10, 23, 10, 1, -4)
+ end
+
end
8 app/models/bet.rb
View
@@ -4,4 +4,12 @@ class Bet < ActiveRecord::Base
belongs_to :user
belongs_to :team
+ def won_bet
+ game.winning_team == self.team rescue nil
+ end
+
+ def lost_bet
+ game.losing_team == self.team rescue nil
+ end
+
end
33 app/models/game.rb
View
@@ -5,5 +5,38 @@ class Game < ActiveRecord::Base
belongs_to :week
has_many :bets
+ def winning_team
+
+ return nil unless hometeam_score && awayteam_score
+
+ if hometeam_score + spread > awayteam_score then
+ return hometeam
+ else
+ return awayteam
+ end
+
+ return nil #Error here, one team should have won.
+
+ end
+
+ def losing_team
+
+ return nil unless hometeam_score && awayteam_score
+
+ if hometeam_score + spread < awayteam_score then
+ return hometeam
+ else
+ return awayteam
+ end
+
+ return nil #Error here, one team should have won.
+
+ end
+
+ def has_started_yet
+ return self.gametime <= Application.get_current_time
+ end
+
+
end
8 app/models/season.rb
View
@@ -3,5 +3,13 @@ class Season < ActiveRecord::Base
has_many :weeks
has_many :seasonmemberships
has_many :users, :through => :seasonmemberships, :conditions => {'seasonmemberships.approved' => true}
+ has_many :games, :through => :weeks
+ has_many :bets, :through => :games
+
+
+ def self.get_current_season
+ #Assumes the last season added = current season
+ Season.find(:first, :order => 'year DESC')
+ end
end
5 app/models/seasonmembership.rb
View
@@ -3,4 +3,9 @@ class Seasonmembership < ActiveRecord::Base
belongs_to :season
belongs_to :user
+ def approve_season
+ self.user.bank -= self.season.cost
+ self.approved = true
+ end
+
end
80 app/models/user.rb
View
@@ -3,7 +3,7 @@
class User < ActiveRecord::Base
- has_attached_file :teamlogo, :styles => {:thumb=> "20x20>", :small => "30x30>" }, :default_url => '/assets/default_:style.png'
+ has_attached_file :teamlogo, :styles => {:thumb=> "20x20>", :small => "30x30>", :large => "150x150>" }, :default_url => '/assets/default_:style.png'
has_many :bets
has_many :seasonmemberships
@@ -33,6 +33,75 @@ def bank
end
+ def points_for_week(week)
+
+ points = 0
+
+ week.bets.where(:user_id => self.id).each do |bet|
+ points += 1 if bet.won_bet
+ end
+
+ points
+
+ end
+
+ def points_for_season(season)
+
+ points = 0
+
+ season.bets.where(:user_id => self.id).each do |bet|
+ points += 1 if bet.won_bet
+ end
+
+ points
+
+ end
+
+ def loss_points_for_season(season)
+
+ points = 0
+
+ season.bets.where(:user_id => self.id).each do |bet|
+ points += 1 if bet.lost_bet
+ end
+
+ points
+
+ end
+
+ def points_cumulative
+
+ points = 0
+
+ self.bets.each do |bet|
+ points += 1 if bet.won_bet
+ end
+
+ points
+
+ end
+
+ def reset_picks_for_week(week)
+
+ #Can only be used before the start of any games!
+
+
+ end
+
+ def my_pick_for_game(game)
+ self.bets.where(:game_id => game.id).first.team rescue nil
+ end
+
+ def password=(password)
+ @password = password
+
+ if password.present?
+ generate_salt
+ self.hashed_password = self.class.encrypt_password(password, salt)
+ end
+ end
+
+
class << self
def authenticate(username, password)
if user = find_by_username(username)
@@ -48,15 +117,6 @@ def encrypt_password(password, salt)
end
- def password=(password)
- @password = password
-
- if password.present?
- generate_salt
- self.hashed_password = self.class.encrypt_password(password, salt)
- end
- end
-
private
def password_must_be_present
30 app/models/week.rb
View
@@ -2,5 +2,35 @@ class Week < ActiveRecord::Base
belongs_to :season
has_many :games
+ has_many :bets, :through => :games
+
+ def self.get_current_week
+ #todo:fix dis shit to be accurate
+ Week.find(:first, :conditions => ["week_start > '#{Application.get_current_time}'"], :order => "week_start ASC")
+
+ end
+
+ def has_started_yet
+
+ #If at least one game this week has started, this returns true
+
+ return Application.get_current_time > self.week_start
+
+ end
+
+ def update_date_week_starts
+ #This is to be run after all the games are added to the weeks
+
+ earliest_date = DateTime.new(3000, 9, 7, 9, 0, -4)
+
+ self.games.each do |game|
+ earliest_date = game.gametime if earliest_date > game.gametime
+ end
+
+ self.week_start = earliest_date
+
+ self.save!
+
+ end
end
17 app/views/bet/create.js.erb
View
@@ -0,0 +1,17 @@
+<% if @bet %>
+ <% if (@bet.game.hometeam == @bet.team) %>
+ $(<%= "'#h#{@bet.game.id}'" %>).tooltip('hide');
+
+ $(<%= "'#h#{@bet.game.id}'" %>).attr('data-original-title', '');
+
+ $(<%= "'#lh#{@bet.game.id}'" %>).attr('href', '#');
+ $(<%= "'#a#{@bet.game.id}'" %>).fadeOut('fast');
+ <% else %>
+ $(<%= "'#a#{@bet.game.id}'" %>).tooltip('hide');
+
+ $(<%= "'#a#{@bet.game.id}'" %>).attr('data-original-title', '');
+
+ $(<%= "'#la#{@bet.game.id}'" %>).attr('href', '#');
+ $(<%= "'#h#{@bet.game.id}'" %>).fadeOut('fast');
+ <% end %>
+<% end %>
50 app/views/layouts/application.html.erb
View
@@ -18,14 +18,40 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin Options <b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><%= link_to "Season Management", seasons_path %></li>
<li><%= link_to "Team Management", teams_path %></li>
<li><%= link_to "Game Management", games_path %></li>
- <li><%= link_to "Season-Membership Management", admin_season_path %></li>
+ <li><%= link_to "Membership Management", admin_season_path %></li>
</ul>
</li>
</ul>
<% end %>
+
+ <ul class="nav">
+
+ <% if @current_week && @me.seasons.include?(@current_week.season) then %>
+ <li class="dropdown">
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown">Current Week <b class="caret"></b></a>
+ <ul class="dropdown-menu">
+ <li><%= link_to "My Picks", mypicks_url(:season_id => @current_week.season.id, :week_num => @current_week.number) %></li>
+ <li><%= link_to "League Picks", leaguepicks_url(:season_id => @current_week.season.id, :week_num => @current_week.number) %></li>
+ <li><%= link_to "Overview", overview_url(:season_id => @current_week.season.id) %></li>
+ </ul>
+ </li>
+ <% end %>
+
+ <li class="dropdown">
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown">Seasons <b class="caret"></b></a>
+ <ul class="dropdown-menu">
+ <li><%= link_to "Season Index", seasons_path %></li>
+ <% @me.seasons.each do |season| %>
+ <li><%= link_to "#{season.year} - #{season.year + 1}", season_path(season) %></li>
+ <% end %>
+ </ul>
+ </li>
+ </ul>
+
+
+
<ul class="nav pull-right">
<li class="divider-vertical"></li>
<li class="dropdown">
@@ -39,10 +65,6 @@
</ul>
</li>
</ul>
-
-
-
-
</div>
</div>
</div>
@@ -51,8 +73,22 @@
- <div class="container-fluid">
+ <div class="container">
+ <div class="inner">
<%= yield %>
+ <footer class="footer" style="text-align:center">
+ <div class="fill">
+ <p class="pull-right">
+ <a href="#">Back to top</a>
+ </p>
+ <p>
+ Designed and coded by <a href="mailto:ryanfuentesdev@gmail.com">Ryan Fuentes</a>.<br>
+ You can find the <a href="https://github.com/RyanFuentes/Football-Pool">source code</a> for this site, along with the rest of my projects at <a href="https://github.com/RyanFuentes">Github.com</a>
+ </p>
+ </div>
+ </footer>
+ </div>
</div>
+
</body>
</html>
62 app/views/picks/leaguepicks.html.erb
View
@@ -0,0 +1,62 @@
+<script>
+
+ $(document).ready(function() {
+
+ <% @week.games.each do |game| %>
+
+ <% if game.winning_team %>
+
+ $(<%= "'.g#{game.id}t#{game.winning_team.id}'" %>).attr('style', 'background-color:#D6FFC2;');
+
+ <% end %>
+
+ <% if game.losing_team %>
+
+ $(<%= "'.g#{game.id}t#{game.losing_team.id}'" %>).attr('style', 'background-color:#FAAFAF;');
+
+ <% end %>
+
+
+ <% end %>
+
+ });
+
+</script>
+<table class="table table-striped table-bordered table-condensed">
+ <tr>
+ <th></th>
+ <th></th>
+ <% @week.games.each do |game| %>
+
+ <th>
+ <%= image_tag(game.hometeam.big_logo_url, :size => '20x20') %>
+ <%= image_tag(game.awayteam.big_logo_url, :size => '20x20') %>
+ </th>
+
+ <% end %>
+
+ <th>Week Pts</th>
+ <th>Season Pts</th>
+
+ </tr>
+
+ <% @users.each do |user| %>
+
+ <tr>
+ <td><%= image_tag user.teamlogo.url(:small) %>
+ <td><%= link_to user.username, show_user_url(user.id) %></td>
+ <% @week.games.each do |game| %>
+ <% if user.my_pick_for_game(game) && (game.has_started_yet || user == @me) %>
+ <td class=<%= "'g#{game.id}t#{user.my_pick_for_game(game).id}'" %>><%= image_tag(user.my_pick_for_game(game).big_logo_url, :size => '40x40') rescue '' %></td>
+ <% else %>
+ <td>?</td>
+ <% end %>
+ <% end %>
+
+ <td><span class="badge"><%= user.points_for_week(@week) %></span></td>
+ <td><span class="badge badge-success"><%= user.points_for_season(@season) %></span></td>
+
+ </tr>
+
+ <% end %>
+ </table>
81 app/views/picks/mypicks.html.erb
View
@@ -0,0 +1,81 @@
+<script>
+
+
+$(document).ready(function() {
+ $('.logoimg').tooltip();
+ });
+
+
+</script>
+<h1><%= "#{@week.season.year} - #{@week.season.year + 1} Season, Week #{@week.number}" %></h1>
+<div class="row">
+ <div class="span10">
+
+ <table class="table table-striped table-bordered table-condensed">
+ <tr>
+ <th>Home Team</th>
+ <th>Away Team</th>
+ <th>Spread</th>
+ <th>Game Time</th>
+ <th>Your Pick</th>
+ </tr>
+
+ <% @week.games.each do |game| %>
+ <tr>
+ <tr>
+ <td <%= "id='tdh#{game.id}'" %>>
+ <%= image_tag(game.hometeam.big_logo_url, :size => '40x40') %>
+ <%= game.hometeam.teamname %>
+ </td>
+ <td <%= "id='tda#{game.id}'" %>>
+ <%= image_tag(game.awayteam.big_logo_url, :size => '40x40') %>
+ <%= game.awayteam.teamname %>
+ </td>
+ <td><%= game.spread %></td>
+ <td><%= label '', game.gametime.strftime("%B %d, %Y %I:%M%p"), :style => game.has_started_yet ? 'color: red;' : 'color: black;' %></td>
+ <td>
+
+ <% if game.has_started_yet %>
+
+ <%= image_tag(@me.my_pick_for_game(game).big_logo_url, :size => '40x40') rescue 'Unpicked' %>
+
+ <% else %>
+ <!-- This will show the picking options or your pick if the game has not started yet -->
+ <% if @me.my_pick_for_game(game) %>
+ <div>
+ <%= image_tag(@me.my_pick_for_game(game).big_logo_url, :size => '40x40') %>
+ </div>
+ <% else %>
+ <div <%= "id='gamepick#{game.id}'" %>>
+ <%= link_to image_tag(game.hometeam.big_logo_url, :size => '40x40', :id => "h#{game.id}", :class => 'logoimg', :rel => 'tooltip', :title => "+#{game.spread}"), create_bet_url(:game_id => game.id, :team_id => game.hometeam.id), :id => "lh#{game.id}", :method => :post, :remote => true %><%= link_to image_tag(game.awayteam.big_logo_url, :size => '40x40', :id => "a#{game.id}", :class => 'logoimg', :rel => 'tooltip', :title => "-#{game.spread}"), create_bet_url(:game_id => game.id, :team_id => game.awayteam.id), :id => "la#{game.id}", :method =>:post, :remote => true %>
+ </div>
+ <% end %>
+ <!-- ===================================================================================== -->
+ <% end %>
+
+ </td>
+ </tr>
+ <% end %>
+
+
+ </table>
+ </div>
+ <div class="span2">
+ <table class="table table-striped table-bordered table-condensed">
+ <tr>
+ <th>Options</th>
+ </tr>
+ <tr>
+ <% unless @week.has_started_yet then %>
+ <td>
+ <%= link_to clear_picks_url(:season_id => @week.season.id, :week_id => @week.number), :class => 'btn btn-danger', :confirm => 'Are you sure you want to clear your bets?' do %>
+ <i class='icon-trash icon-white'></i> Clear Bets
+ <% end %>
+ <% end %>
+ </td>
+ </tr>
+ </table>
+ </div>
+</div>
+
+
37 app/views/picks/overview.html.erb
View
@@ -0,0 +1,37 @@
+
+<h1>League Overview - Points by Week</h1>
+<table class="table table-striped table-bordered table-condensed">
+ <tr>
+ <th></th>
+ <th></th>
+ <% @season.weeks.each do |week| %>
+
+ <th>
+ <%= week.number %>
+ </th>
+
+ <% end %>
+
+ <th>Season Wins/Losses</th>
+
+ </tr>
+
+ <% @users.each do |user| %>
+
+ <tr>
+ <td><%= image_tag user.teamlogo.url(:small) %>
+ <td><%= link_to user.username, show_user_url(user.id) %></td>
+ <% @season.weeks.each do |week| %>
+ <% if week.has_started_yet %>
+ <td><%= user.points_for_week(week) %></td>
+ <% else %>
+ <td></td>
+ <% end %>
+ <% end %>
+
+ <td><span style="color:green"><%= user.points_for_season(@season) %></span> / <span style="color:red"><%= user.loss_points_for_season(@season) %></span></td>
+
+ </tr>
+
+ <% end %>
+ </table>
4 app/views/season/index.html.erb
View
@@ -19,7 +19,7 @@
<% elsif @my_seasons_pending.include?(season) %>
<%= 'Pending Approval' %>
<% else %>
- <%= button_to('Join!', create_seasonmembership_path(:id => season.id), :confirm => 'Are you sure you want to join this season?', :method => :post, :remote => true, :class => 'btn btn-primary') %>
+ <%= button_to('Join!', create_seasonmembership_path(:id => season.id), :confirm => 'Are you sure you want to join this season?', :method => :post, :remote => true, :class => 'btn btn-primary', :id => "btn#{season.id}") %>
<% end %>
</td>
</tr>
@@ -40,7 +40,7 @@
</tr>
<% season.users.each do |user| %>
<tr>
- <td style="text-align: middle;"><%= image_tag user.teamlogo.url(:thumb)%><p><%= user.teamname %></p></td>
+ <td style="text-align: middle;"><%= image_tag user.teamlogo.url(:small)%><p><%= user.teamname %></p></td>
<td style="vertical-align: middle;"><%= "#{user.username} (#{user.firstname} #{user.lastname})" %></td>
</tr>
<% end %>
1  app/views/season/show.html.erb
View
@@ -0,0 +1 @@
+<%= @season %>
1  app/views/seasonmembership/approve.js.erb
View
@@ -0,0 +1 @@
+$(<%= "'#row#{params[:id]}'" %>).fadeOut('fast');
7 app/views/seasonmembership/create.js.erb
View
@@ -0,0 +1,7 @@
+var parent_td = $(<%= "'#btn#{params[:id]}'" %>).parent()
+
+$(<%= "'#btn#{params[:id]}'" %>).fadeOut('fast', function() {
+
+ parent_td.append('Pending Approval')
+
+});
1  app/views/seasonmembership/deny.js.erb
View
@@ -0,0 +1 @@
+$(<%= "'#row#{params[:id]}'" %>).fadeOut('fast');
6 app/views/seasonmembership/index.html.erb
View
@@ -13,13 +13,13 @@
</thead>
<tbody>
<% @awaiting_confirmation.each do |membership| %>
- <tr>
+ <tr <%= "id='row#{membership.id}'" %>>
<td><%= "#{membership.season.year} - #{membership.season.year + 1} " %></td>
<td><%= "#{membership.user.username} (#{membership.user.firstname} #{membership.user.lastname})" %></td>
<td><%= number_to_currency(membership.user.bank, :unit => "$") %></td>
<td><%= number_to_currency(membership.season.cost, :unit => "$") %></td>
- <td><%= button_to('Approve', '#', :confirm => 'Are you sure you want to approve this user for this season?', :method => :post, :remote => true, :class => 'btn btn-success') %></td>
- <td><%= button_to('Deny', '#', :confirm => 'Are you sure you want to deny this user for this season?', :method => :post, :remote => true, :class => 'btn btn-danger') %></td>
+ <td><%= button_to('Approve', approve_season_url(:id => membership.id), :method => :post, :remote => true, :class => 'btn btn-success', :id => 'btn_approve_season') %></td>
+ <td><%= button_to('Deny', deny_season_url(:id => membership.id), :method => :post, :remote => true, :class => 'btn btn-danger') %></td>
</tr>
<% end %>
</tbody>
34 app/views/session/new.html.erb
View
@@ -1,12 +1,31 @@
+<script>
+
+ $(document).ready(function() {
+
+ $('#showemail').click(function(e) {
+ e.preventDefault();
+ $('#hiddenemail').slideDown();
+
+ });
+
+
+ });
+
+</script>
+
+
<% if notice %>
<p id="notice" class="alert alert-info"><%= notice %></p>
<% end %>
+
<% if alert %>
<p id="alert" class="alert alert-error"><%= alert %></p>
<% end %>
-<h1>Member Login</h1>
-<div class="row-fluid">
- <div class="span6">
+<div class="row">
+
+
+ <div class="span6 offset3">
+ <h1 style="text-align:center;">Member Login</h1>
<%= form_tag( {}, {:class => 'form-horizontal'}) do %>
<fieldset>
<legend></legend>
@@ -31,13 +50,14 @@
<div class="actions">
<%= submit_tag("Log In", { :name => 'login', :id => 'login_button', :class => 'btn btn-primary' })%>
<p><small>New User? <a href=<%= join_url %>>Register Here</a></small><br />
- <small>Forgot Password? Click Here</small></p>
- </div>
+ <small>Forgot Password? <a href="#" id="showemail">Click Here</a></small></p>
+ <div id="hiddenemail" style="display:none;">
+ <%= text_field_tag :email, params[:email], :style => 'width: 130px; float:left;', :placeholder => 'Email'%> <%= button_to "Get!",'#', :class => 'btn btn-success' %>
+ </div>
</div>
</fieldset>
<% end %>
</div>
- <div class="span6">
- </div>
+
</div>
25 app/views/user/index.html.erb
View
@@ -0,0 +1,25 @@
+<table class="table table-striped table-bordered table-condensed">
+ <tr>
+ <th>Team Logo</th>
+ <th>Username</th>
+ <th>Team Name</th>
+ <th>First Name</th>
+ <th>Last Name</th>
+ <th>Email</th>
+ <th>Role<th>
+ <th>Total Points</th>
+ <th></th>
+ </tr>
+
+<% @users.each do |user| %>
+ <tr>
+ <td><%= image_tag @user.teamlogo.url(:thumb) %></td>
+ <td><%= @user.username %></td>
+ <td><%= @user.teamname %></td>
+ <td><%= @user.firstname %></td>
+ <td><%= @user.lastname %></td>
+ <td><%= @user.email %></td>
+ <td><%= @user. %></td>
+ <td><%= @user. %></td>
+ </tr>
+</table>
9 app/views/user/profile.html.erb
View
@@ -5,7 +5,7 @@
<div class="row">
<div class="span12">
- <h1><%= image_tag @user.teamlogo.url(:small) %><%= " #{@user.username.capitalize} (#{@user.firstname.capitalize} #{@user.lastname.capitalize})" %></h1>
+ <h1><%= image_tag @user.teamlogo.url(:large) %><%= " #{@user.username.capitalize} (#{@user.firstname.capitalize} #{@user.lastname.capitalize})" %></h1>
<p><small><%= @user.role %></small></p>
<hr>
<div class="row">
@@ -15,6 +15,8 @@
<p><b>User Name:</b></p>
<p><b>Name:</b></p>
<p><b>Email:</b></p>
+ <p><b>Cumulative Points:</b></p>
+ <p><b>Seasons Played:</b></p>
<p><b>Bank:</b></p>
<p><b>Member Since:</b></p>
</div>
@@ -22,6 +24,8 @@
<p><%= @user.username %></p>
<p><%= "#{@user.firstname.capitalize} #{@user.lastname.capitalize}" %></p>
<p><%= mail_to @user.email %></p>
+ <p><%= @user.points_cumulative %></p>
+ <p><%= @user.seasons.length %></p>
<p><%= number_to_currency(@user.bank, :unit => "$") %></p>
<p><%= Date.strptime(@user.created_at.to_s,"%Y-%m-%d %H:%M:%S %Z").strftime("%m/%d/%Y") %></p>
</div>
@@ -30,5 +34,4 @@
<div class="span8"></div>
</div>
</div>
-</div>
-<%= button_to('Add Bank', update_bank_url, :confirm => 'Are you sure you want to add money?', :method => :post, :remote => true, :class => 'btn btn-primary') %>
+</div>
2  app/views/user/show.html.erb
View
@@ -4,7 +4,7 @@
<div class="row">
<div class="span12">
- <h1><%= image_tag @user.teamlogo.url(:small) %><%= " #{@user.username.capitalize} (#{@user.firstname.capitalize} #{@user.lastname.capitalize})" %></h1>
+ <h1><%= image_tag @user.teamlogo.url(:large) %><%= " #{@user.username.capitalize} (#{@user.firstname.capitalize} #{@user.lastname.capitalize})" %></h1>
<p><small><%= @user.role %></small></p>
<hr>
<div class="row">
70 config/routes.rb
View
@@ -16,7 +16,7 @@
match 'join' => 'user#new', :via => :get
match 'users' => 'user#create', :via => :post
match 'users' => 'user#index', :via => :get
- match 'users/:id' => 'user#show'
+ match 'users/:id' => 'user#show', :as => 'show_user'
match 'profile' => 'user#profile'
controller :session do
@@ -27,72 +27,22 @@
match 'seasons' => 'season#index'
match 'seasons/:id/join' => 'seasonmembership#create', :as => 'create_seasonmembership'
+ match 'seasons/:id/approve' => 'seasonmembership#approve', :as => 'approve_season'
+ match 'seasons/:id/deny' => 'seasonmembership#deny', :as => 'deny_season'
match 'seasons/admin' => 'seasonmembership#index', :as => 'admin_season'
+ match 'seasons/:id' => 'season#show', :as => 'season'
match 'update_bank' => 'user#update_bank', :as => 'update_bank'
- match 'seasons/:season_id/weeks/:week_id/mypicks' => 'picks#index'
+ match 'seasons/:season_id/weeks/:week_num/mypicks' => 'picks#mypicks', :as => 'mypicks'
+ match 'seasons/:season_id/weeks/:week_num/leaguepicks' => 'picks#leaguepicks', :as => 'leaguepicks'
+ match 'seasons/:season_id/overview' => 'picks#overview', :as => 'overview'
+ match 'seasons/:season_id/weeks/:week_num/clearpicks' => 'picks#clear', :as => 'clear_picks'
- match 'error' => 'user#error'
-
-
-
-
- # The priority is based upon order of creation:
- # first created -> highest priority.
-
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
+ match 'games/:game_id/placebet/:team_id' => 'bet#create', :as => 'create_bet'
- # Sample resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
- # root :to => 'welcome#index'
-
- # See how all your routes lay out with "rake routes"
+ match 'error' => 'user#error'
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
end
2  db/migrate/20120125182840_create_seasons.rb
View
@@ -2,7 +2,7 @@ class CreateSeasons < ActiveRecord::Migration
def self.up
create_table :seasons do |t|
t.integer :year
- t.decimal :cost
+ t.decimal :cost, :scale => 2
t.timestamps
end
9 db/migrate/20120315202319_add_week_start_to_week.rb
View
@@ -0,0 +1,9 @@
+class AddWeekStartToWeek < ActiveRecord::Migration
+ def up
+ add_column :weeks, :week_start, :datetime
+ end
+
+ def down
+ drop_column :weeks, :week_start, :datetime
+ end
+end
3  db/schema.rb
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120209164856) do
+ActiveRecord::Schema.define(:version => 20120315202319) do
create_table "applications", :force => true do |t|
t.string "membership_password"
@@ -95,6 +95,7 @@
t.integer "season_id"
t.datetime "created_at"
t.datetime "updated_at"
+ t.datetime "week_start"
end
end
2  db/seeds.rb
View
@@ -92,6 +92,8 @@ def format_datetime(str_date, str_time)
Game.create(gametime: x[:gametime], hometeam_id: Team.where(:teamname => x[:hometeam]).first.id, awayteam_id: Team.where(:teamname => x[:awayteam]).first.id, week_id: x[:week], spread: 0.00)
end
+Week.find(:all).each {|w| w.update_date_week_starts}
+
User.create(username: 'admin', password: 'admin', password_confirmation: 'admin', firstname: 'ryan', lastname: 'ryan', email: 'ryan@aol.com', teamname: 'bullys', role: 'admin')
Seasonmembership.create(user_id: 1, season_id: 1)
7 test/functional/bet_controller_test.rb
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class BetControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
4 test/unit/helpers/bet_helper_test.rb
View
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class BetHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.