Permalink
Browse files

Updated to handle games with a bye

  • Loading branch information...
1 parent 8e8b261 commit 886938a8ea8f7bc6680fda3dee74e47e1469eec2 stevetuckner@stewdle.com committed Aug 18, 2011
View
@@ -5,6 +5,7 @@ gem 'pg'
gem 'validate_email'
gem 'devise', '1.3.1'
+gem 'cancan'
gem 'jquery-rails', '~> 0.2.6'
gem 'haml-rails'
gem 'sass'
View
@@ -31,6 +31,7 @@ GEM
arel (2.0.9)
bcrypt-ruby (2.1.4)
builder (2.1.2)
+ cancan (1.6.5)
cgi_multipart_eof_fix (2.5.0)
columnize (0.3.2)
daemons (1.1.3)
@@ -141,6 +142,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ cancan
devise (= 1.3.1)
factory_girl_rails
formtastic
View
@@ -8,7 +8,7 @@ class Game < ActiveRecord::Base
class << self
def unplayed
- where("actual_start_datetime is NULL").order("expected_start_date ASC")
+ where("actual_start_datetime is NULL and (bye = false or bye is null)").order("expected_start_date ASC").select {|game| game.game_roles.size == 2}
end
def recent
@@ -21,12 +21,20 @@ def description
"#{white_player.name} vs. #{black_player.name}"
else
players = game_roles.map{|gr| gr.user}
- "#{players.first.name} vs. #{players.second.name}"
+ if (players.size == 1)
+ "#{players.first.name} (Bye)"
+ else
+ "#{players.first.name} vs. #{players.second.name}"
+ end
end
end
+ def bye?
+ self.bye
+ end
+
def opponent(user)
- raise "more than two players for this game" unless game_roles.size == 2
+ return nil if self.bye?
opponents = game_roles.inject([]) {|sum,gr| gr.user != user ? (sum + [gr]) : sum }
if opponents.size == 0 then
@@ -21,5 +21,8 @@
%td= link_to game_text(game, date_only_datetime_text(game.actual_start_datetime)), game_path(game)
- else
%td= link_to game.users.first.name, user_path(game.users.first.name)
- %td= link_to game.users.second.name, user_path(game.users.second.name)
+ - if game.bye?
+ %td Bye
+ - else
+ %td= link_to game.users.second.name, user_path(game.users.second.name)
%td= link_to "unplayed", edit_game_path(game)
@@ -30,10 +30,13 @@
%td= date_only_datetime_text(game.expected_start_date)
- if finished_games
%td= full_datetime_text(game.actual_start_datetime)
- %td= link_to opponent.name, user_path(opponent.user)
+ - if opponent
+ %td= link_to opponent.name, user_path(opponent.user)
+ - else
+ %td Bye
- if verbose
%td= game.actual_start_datetime ? opponent.role : ""
%td= game.actual_start_datetime ? link_to(game_text(game, game.result_for_user(@user)), game_path(game)) : link_to("unplayed", edit_game_path(game))
- if verbose
- %td= opponent.record
- %td= formatted_rating(opponent.rating)
+ %td= opponent ? opponent.record : ""
+ %td= opponent ? formatted_rating(opponent.rating) : ""
@@ -23,13 +23,16 @@
.med-title
Players
.med-value
- = @game.users.map{|x| x.name}.join(" vs ")
+ - if @game.users.size == 1 then
+ = @game.users.map{|x| x.name}.first + " (Bye)"
+ - else
+ = @game.users.map{|x| x.name}.join(" vs ")
.med-title
Expected start time
.med-value
= date_only_datetime_text(@game.expected_start_date)
.clear
- - if @game.editable_by_user(current_user)
+ - if @game.editable_by_user(current_user) && !@game.bye?
= link_to('update game', edit_game_path(@game), :class => "button")
%section.game-board
- if @game.actual_start_datetime && !@game.pgn.blank?
@@ -40,6 +40,14 @@
Opponent's Rating
.medsmall-value
= formatted_rating(opponent.rating)
+ .medsmall-title
+ Round
+ .medsmall-value
+ = next_game.round
+ .medsmall-title
+ Expected Start Date
+ .medsmall-value
+ = date_only_datetime_text(next_game.expected_start_date)
.clear
- if @user.games.unplayed.size > 1
@@ -1,6 +1,5 @@
-%article.edit-user-profile
- %header
- %h1 Edit Profile
+%article.user
+ %h1 Edit Profile
%section.edit-user-form
- semantic_form_for @user do |f|
- f.inputs do
@@ -1,58 +0,0 @@
-ChessTalk::Application.routes.draw do
- # 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
-
- # 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"
-
- # 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
@@ -1,62 +0,0 @@
-ChessTalk::Application.routes.draw do
- devise_for :models
-
- # 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
-
- # 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"
-
- # 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)))'
-
- root :to => "home#index"
-end
@@ -0,0 +1,9 @@
+class AddByeColumn < ActiveRecord::Migration
+ def self.up
+ add_column "games", "bye", :boolean, :default => false
+ end
+
+ def self.down
+ remove_column "games", "bye"
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110813154436) do
+ActiveRecord::Schema.define(:version => 20110816222556) do
create_table "comments", :force => true do |t|
t.integer "user_id"
@@ -35,6 +35,7 @@
t.datetime "actual_start_datetime"
t.integer "round"
t.integer "scheduleable_id"
+ t.boolean "bye", :default => false
end
create_table "leagues", :force => true do |t|
@@ -157,6 +157,12 @@ section.game-board
section.user-details
margin-bottom: 20px
+section.edit-user-form form
+ margin-bottom: 20px
+
+section.edit-user-form
+ padding-bottom: 10px
+
// These can be used to pull an image at the start of a paragraph, so
// that the text flows around it (usage: <p><img class="left">Text</p>)
@@ -136,6 +136,12 @@ section.game-board {
section.user-details {
margin-bottom: 20px; }
+section.edit-user-form form {
+ margin-bottom: 20px; }
+
+section.edit-user-form {
+ padding-bottom: 10px; }
+
.left {
float: left;
margin: 1.5em 1.5em 1.5em 0;

0 comments on commit 886938a

Please sign in to comment.