Skip to content
14 changes: 14 additions & 0 deletions app/assets/stylesheets/games.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,18 @@

.stats {
padding-top: 20px;
}

.available-games {
height: 310px;
overflow: auto;
padding: 10px;
border-radius: 5px;
background: #fff;
}

.join-button {
}

.available-game {
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ body {
}

.new-account {
padding-top: 45px;
padding-top: 20px;
}

.team-profile {
Expand Down
6 changes: 1 addition & 5 deletions app/assets/stylesheets/navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
padding-top: 10px;
}

.navbar-checkbox {
padding-left: 35px;
}

.navbar-forgot-password {
padding-left: 125px;
padding-left: 80px;
}

ul.nav.navbar-nav.navbar-right li a {
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?

protected

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
end
end
18 changes: 12 additions & 6 deletions app/controllers/games_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Main controller for chess session for CRUD
# logic for our app
class GamesController < ApplicationController
before_action :authenticate_user!, only: [:create, :new]
before_action :authenticate_user!, only: [:create]

def index
@games = Game.all
end

def create
@game = Game.new
@game = Game.create
@game.white.update(user_id: current_user.id)

@lasley lasley Sep 4, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this doing? IIRC there isn't a white attribute on game NVM

@lasley lasley Sep 4, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is performing three db writes + a read, and is inefficient. The game should be created and populated with the player all in one fell swoop.

@game.populate!
redirect_to game_path(@game)
end

def show
Expand All @@ -20,10 +24,6 @@ def show
end
end

def new
@game = Game.new
end

def update
@game = Game.find(params[:id])
@piece = @game.pieces.find(params[:piece_id])
Expand All @@ -32,6 +32,12 @@ def update
@piece.move!(x, y)
end

def join
@game = Game.find(params[:id])
@game.black.update(user_id: current_user.id)
redirect_to game_path(@game)
end

private

def game_params
Expand Down
16 changes: 8 additions & 8 deletions app/models/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def checkmate_coords(x, y)
end
end

def white

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These helpers seem unnecessary and are ambiguously named

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my understand that the way we have our model set up, these are necessary to populate one "player" on the board and all the color pieces they come with...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, these were already defined. What was the change here then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to make the methods public so I could access them.

players.find_by(color: 'white')
end

def black
players.find_by(color: 'black')
end

private

# Generates all avilable coords around the current
Expand Down Expand Up @@ -100,14 +108,6 @@ def populate_right_white_half!
create_piece('Rook', 'white', 7, 7)
end

def white
players.find_by(color: 'white')
end

def black
players.find_by(color: 'black')
end

def create_piece(type, color, x_pos, y_pos)
if color == 'white'
white.pieces.create(type: type, x_position: x_pos, y_position: y_pos,
Expand Down
9 changes: 5 additions & 4 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<%= f.email_field :email, required: true, autofocus: true, class:'devise-inputs', placeholder: 'Email Address' %>
<%= f.text_field :username, required: true, autofocus: true, class:'devise-inputs', placeholder: 'Username' %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
<%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %>
<%= f.input :password_confirmation, required: false %>
<%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %>
<%= f.password_field :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false, placeholder: 'New Password', class:'devise-inputs' %>
<%= f.password_field :password_confirmation, required: false, class:'devise-inputs', placeholder:'Confirm New Password' %>
<%= f.password_field :current_password, hint: "we need your current password to confirm your changes", required: true, class:'devise-inputs', placeholder:'Current Password' %>
</div>
<div class="form-actions">
<%= f.button :submit, "Update", class: 'btn btn-success' %>
Expand Down
1 change: 1 addition & 0 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<%= f.email_field :email, required: true, autofocus: true, class:'devise-inputs', placeholder: 'Email Address' %>
<%= f.text_field :username, class:'devise-inputs', placeholder: 'Username' %>
<%= f.password_field :password, required: true, class:'devise-inputs', placeholder: 'Password', hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.password_field :password_confirmation, required: true, class: 'devise-inputs', placeholder:'Confirm Password' %>
<%= f.button :submit, "Sign up", class: 'btn btn-success' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h2>Log in</h2>
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="deviseNewLogIn">
<%= f.email_field :email, required: false, autofocus: true, class:'devise-inputs', placeholder: 'Email Address' %>
<%= f.email_field :email, required: false, autofocus: true, class:'devise-inputs', placeholder: 'Username' %>
<%= f.password_field :password, required: false, class: 'devise-inputs', placeholder: 'Password' %>
<div class="checkbox">
<label>
Expand Down
23 changes: 9 additions & 14 deletions app/views/games/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
<div class="col-sm-5 col-sm-offset-1">
<%= image_tag 'chess.jpg', class: 'img-responsive feature-pic' %>
</div>
<div class="col-sm-5">
<div class="available-games col-sm-5">
<h2 class="join-headline text-center">Your opponent awaits you! Join the battle!</h2>
<h4>Available game<a class="btn btn-success pull-right" href="#" role="button">Join game!</a></h4>
<br class="clr" />
<h4>Available game<a class="btn btn-success pull-right" href="#" role="button">Join game!</a></h4>
<br class="clr" />
<h4>Available game<a class="btn btn-success pull-right" href="#" role="button">Join game!</a></h4>
<br class="clr" />
<h4>Available game<a class="btn btn-success pull-right" href="#" role="button">Join game!</a></h4>
<br class="clr" />
<h4>Available game<a class="btn btn-success pull-right" href="#" role="button">Join game!</a></h4>
<% @games.each do |game| %>
<h4 class="available-game">Available game<%= button_to "Join game!", join_game_path(game), class: "btn btn-success pull-right join-button" %></h4>
<br class="clr">
<% end %>
</div>
</div>
</section>
Expand All @@ -25,17 +20,17 @@
<a class="btn btn-info dash-button" href="<%= user_path(current_user) %>" role="button">User Dashboard</a>
</div>
<div class="col-sm-offset-2 col-sm-2">
<a class="center-block btn btn-success btn-lg dash-button" href="#" role="button">Create a Game</a>
<%= link_to "Create a Game", games_path, method: :post, class: "center-block btn btn-success btn-lg dash-button" %>
</div>
<div class="col-sm-offset-2 col-sm-1">
<a class="btn btn-info" href="#" role="button">Account Settings</a>
</div>
</div>
<br class="clr" />
<div class="row">
<div class="stats col-sm-offset-2 col-sm-2">
<h2 class="text-center"><%= current_user.email %></h2>
<%= image_tag 'yoda.jpg', class: 'img-responsive' %>
<div class="stats col-sm-offset-2 col-sm-2 col-xs-offset-2 col-xs-8">
<h2 class="text-center"><%= current_user.username %></h2>
<%= image_tag 'yoda.jpg', class: 'stats-pic img-responsive' %>
</div>
<div class="stats col-sm-offset-1 col-sm-5">
<h2 class="text-center">Quick Stats</h2>
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-inline">
<div class="form-group">
<%= f.input :email, class: 'form-control', required: false, autofocus: true %>
<%= f.email_field :email, class: 'form-control', placeholder: 'Email Address', required: false, autofocus: true %>
</div>
<div class="form-group">
<%= f.input :password, class: 'form-control', required: false %>
<%= f.password_field :password, class: 'form-control', placeholder: 'Password', required: false %>
</div>
<div class="form-group">
<%= f.button :submit, "Log In", class: "btn btn-success form-control" %>
Expand Down
10 changes: 7 additions & 3 deletions app/views/static_pages/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
<div class="form-group">
<%= f.email_field :email, class: 'form-control', required: true, autofocus: true, placeholder: 'Email Address' %>
</div>
<br />
<br>
<div class="form-group">
<%= f.text_field :username, required: true, autofocus: true, class:'form-control', placeholder: 'Username' %>
</div>
<br>
<div class="form-group">
<%= f.password_field :password, class: 'form-control', required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length), placeholder: 'Password' %>
</div>
<br />
<br>
<div class="form-group">
<%= f.password_field :password_confirmation, class: 'form-control', required: true, placeholder: 'Confirm Password' %>
</div>
<br />
<br>
<div class="form-group">
<%= f.button :submit, "Create An Account", class: "btn btn-success form-control" %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="row">
<div class="user col-sm-offset-1 col-sm-2">
<%= image_tag 'user.png', class:'img-responsive' %>
<h4><%= current_user.email %></h4>
<h4><%= current_user.username %></h4>
<h4>Member Since: <%= current_user.created_at.strftime("%B %d, %Y") %></h4>
<a class="btn-block btn btn-info account-settings" href="#" role="button">Account Settings</a>
</div>
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
root 'static_pages#index'

resources :games

post 'games/:id', to: 'games#join', as: :join_game
resources :players, only: [:show]

resources :users, only: [:show]



# The priority is based upon order of creation: first created ->
# highest priority.

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20160811200617_add_username_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUsernameToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :username, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160806192848) do
ActiveRecord::Schema.define(version: 20160811200617) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -59,6 +59,7 @@
t.inet "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "username"
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
Expand Down
8 changes: 4 additions & 4 deletions spec/integration/home_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
it 'should sign me in' do
visit '/users/sign_in'
within('.deviseNewLogIn') do
fill_in 'Email Address', with: 'user@example.com'
fill_in 'Username', with: 'testuser'
fill_in 'Password', with: 'password'
click_button 'Log in'
expect(page).to have_content # 'Signed in successfully.'
end # Above altered to pass tests after re-routing
end # user registration to root_path
expect(page).to have_content
end
end
end