Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Becca and Brittany 2048 rails #4

Open
wants to merge 39 commits into
base: bkrm/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
fae80db
added gmes and routes for Oauth
rmtolmach Feb 8, 2016
c4c1890
omniauth gem and sessions controller
rmtolmach Feb 8, 2016
2e4454b
generated user model
rmtolmach Feb 8, 2016
fb9cd1e
can login with facebook. yay
rmtolmach Feb 8, 2016
72bffd8
Adding nav, needs to be fixed
brittanykohler Feb 9, 2016
2e3a84f
Fixing nav
brittanykohler Feb 9, 2016
38d99f2
Fixing typo in nav
brittanykohler Feb 9, 2016
8bc3fa9
Adding save function, need to fill in API call
brittanykohler Feb 9, 2016
1cfb0be
generated game controller
rmtolmach Feb 9, 2016
d041523
some ajax added. not working
rmtolmach Feb 9, 2016
1ba9e11
Posting to rails save api endpoint is working, need to get actual gam…
brittanykohler Feb 9, 2016
44e04f0
Values are now saving in rails game model for save API endpoint, need…
brittanykohler Feb 9, 2016
87aa00b
created remote storage manager and copied stuff in it
rmtolmach Feb 9, 2016
6850417
requiring new remote_storage_manager file
brittanykohler Feb 9, 2016
a61d269
we can now access info from the game and save it to our database
rmtolmach Feb 9, 2016
e1c496b
Adding view for saved games
brittanykohler Feb 9, 2016
3e2c8fe
adding route for loading saved game
brittanykohler Feb 9, 2016
91df7f8
lots of things
rmtolmach Feb 10, 2016
2c5b013
Updated paths, nested games in users, updating API endpoint for getti…
brittanykohler Feb 10, 2016
f83fdaa
Kai helping us debug things. We can now load a saved game. Asynchrono…
rmtolmach Feb 11, 2016
ad93390
Created hidden divs to dynamically pull correct data for selected game
brittanykohler Feb 11, 2016
bb2d091
Updating saving/retrieving game data so that score now shows up
brittanykohler Feb 11, 2016
ae73a36
Fixing storage manager logic, now new game will load
brittanykohler Feb 11, 2016
c2a9349
Created leaderboard
brittanykohler Feb 11, 2016
64ea5af
Moving saved games to game#index page
brittanykohler Feb 11, 2016
9256fdb
Adding some basic styling to leaderboard page
brittanykohler Feb 11, 2016
64bdb07
css for login page
rmtolmach Feb 11, 2016
47600cc
Merge branch 'bkrm/master' of github.com:brittanykohler/2048-rails in…
rmtolmach Feb 11, 2016
54fdaff
score and best divs look better
rmtolmach Feb 11, 2016
140b9f9
save game button is rebeccapurple
rmtolmach Feb 11, 2016
7fa66e0
css for leaderboard page
rmtolmach Feb 11, 2016
9f31dd0
Adding basic styling for saved games page
brittanykohler Feb 11, 2016
ce43324
styling everything
rmtolmach Feb 12, 2016
bbfb506
Merge branch 'bkrm/master' of github.com:brittanykohler/2048-rails in…
rmtolmach Feb 12, 2016
6306cfb
Changing background color of index page
brittanykohler Feb 12, 2016
f7547e7
Changing color of home page link
brittanykohler Feb 12, 2016
c3b13b6
Removing console.logs and unneccessary comments, adding tictactoe code
brittanykohler Feb 12, 2016
755bf39
Adding tictactoe route, view, controller action
brittanykohler Feb 12, 2016
4c8ae65
added links to nav bar for tic tac
rmtolmach Feb 12, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/log/*
!/log/.keep
/tmp
/.env


# From https://github.com/github/gitignore/blob/master/Rails.gitignore
Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'omniauth'
gem 'omniauth-facebook'

group :production do
gem 'pg'
gem 'rails_12factor'
Expand All @@ -31,6 +34,7 @@ group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'rspec-rails'
gem 'dotenv-rails'
end

group :development do
Expand All @@ -43,4 +47,3 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ GEM
concurrent-ruby (1.0.0)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
dotenv (2.1.0)
dotenv-rails (2.1.0)
dotenv (= 2.1.0)
railties (>= 4.0, < 5.1)
erubis (2.7.0)
execjs (2.6.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
globalid (0.3.6)
activesupport (>= 4.1.0)
hashie (3.4.3)
i18n (0.7.0)
jbuilder (2.4.0)
activesupport (>= 3.0.0, < 5.1)
Expand All @@ -69,6 +76,7 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
jwt (1.5.1)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.3)
Expand All @@ -78,8 +86,24 @@ GEM
mini_portile2 (2.0.0)
minitest (5.8.4)
multi_json (1.11.2)
multi_xml (0.5.5)
multipart-post (2.0.0)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
oauth2 (1.1.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0, < 1.5.2)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
omniauth (1.3.1)
hashie (>= 1.2, < 4)
rack (>= 1.0, < 3)
omniauth-facebook (3.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-oauth2 (1.4.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
pg (0.18.4)
pry (0.10.3)
coderay (~> 1.1.0)
Expand Down Expand Up @@ -179,8 +203,11 @@ DEPENDENCIES
binding_of_caller
byebug
coffee-rails (~> 4.1.0)
dotenv-rails
jbuilder (~> 2.0)
jquery-rails
omniauth
omniauth-facebook
pg
pry
rails (= 4.2.5)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/game.coffee
Original file line number Diff line number Diff line change
@@ -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://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/sessions.coffee
Original file line number Diff line number Diff line change
@@ -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://coffeescript.org/
8 changes: 8 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
*= require_tree .
*= require_self
*/
a {
text-decoration: none;
}

.restart-button:hover {
color: #fff;
text-decoration: none;
}
29 changes: 29 additions & 0 deletions app/assets/stylesheets/game.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Place all the styles related to the game controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/


.leaderboard {
width: 450px;
margin: 80px auto;
padding-left: 50px;
}

.leaderboard-header {
width: 220px;
margin-top: 80px;
margin-left: auto;
margin-right: auto;
}

.rank {
width: 100px;
}

.score {
width: 100px;
}

.name {
width: 200px;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sessions.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
32 changes: 32 additions & 0 deletions app/assets/stylesheets/site.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
// Place all the styles related to the site controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

.navbar {
background-color: red;
}


.game-list {
margin-top: 80px;
width: 400px;
margin-left: auto;
margin-right: auto;
}

.game-num {
width: 100px;
}

.game-score {
width: 100px;
}

.game-time {
width: 200px;
}

.game-num a, .game-time a, .game-score a {
font-size: 16px;
}
.game-num a:hover, .game-time a:hover, .game-score a:hover {
text-decoration: none;
color: #000;
}
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ 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
helper_method :current_user

def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
end
39 changes: 39 additions & 0 deletions app/controllers/game_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class GameController < ApplicationController

def save
# does the game exist or do we need to create a new one?
game = Game.new
game.score = params[:score] #something we get from JS
game.board_state = params[:board_state] #some kind of string
game.lost = params[:lost]
game.user_id = current_user.id
game.save
render :json => [], :status => :ok
end

def show
respond_to do |format|
format.json {
game = Game.find_by(id: params[:id])
if game
render :json => game.as_json(except: [:created_at, :updated_at]), :status => :ok
else
# the request itself was fine, but there was just no content associated with the response, so use status code 204
render :json => [], :status => 204
end
}
format.html {
@user_id = current_user.id
@game_id = params[:id]
render template: "site/index"
}
end
end


def index
@username = current_user.name
@games = current_user.games
end

end
16 changes: 16 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class SessionsController < ApplicationController
skip_before_filter :verify_authenticity_token

def create
user = User.from_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
redirect_to root_path
end

def destroy
session[:user_id] = nil
redirect_to root_path
end


end
22 changes: 22 additions & 0 deletions app/controllers/site_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
class SiteController < ApplicationController

def index
if current_user
@username = current_user.name
end
if params[:id]

end
end

def games
@username = current_user.name
@games = current_user.games
end

def leaderboard
@games = Game.order(score: :desc).limit(10)
end

def tictac
if current_user
@username = current_user.name
end
render template: :tictactoe
end
end
2 changes: 2 additions & 0 deletions app/helpers/game_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module GameHelper
end
2 changes: 2 additions & 0 deletions app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SessionsHelper
end
3 changes: 3 additions & 0 deletions app/models/game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Game < ActiveRecord::Base
belongs_to :user
end
23 changes: 23 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class User < ActiveRecord::Base
has_many :games

def self.from_omniauth(auth)
where(uid: auth.uid).first_or_create do |user|
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
end


# def self.from_omniauth(auth)
# where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
# user.provider = auth.provider
# user.uid = auth.uid
# user.name = auth.info.name
# user.save
# end
# end
28 changes: 28 additions & 0 deletions app/views/game/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<link href="/style/main.css" rel="stylesheet" type="text/css">

<%= render "shared/nav" %>

<h1 class="leaderboard-header">Saved Games</h1>

<div class="game-list">
<table>
<tr>
<th>Game</th>
<th>Score</th>
<th>Time Saved</th>
</tr>
<% @games.each do |game| %>
<tr>
<td class="game-num">
<%= link_to "#{game.id}", "/users/#{current_user.id}/game/#{game.id}.html" %>
</td>
<td class="game-score">
<%= link_to "#{game.score}", "/users/#{current_user.id}/game/#{game.id}.html" %>
</td>
<td class="game-time">
<%= link_to "#{game.created_at.in_time_zone("Pacific Time (US & Canada)").strftime("%m/%d/%Y %I:%M%p")}", "/users/#{current_user.id}/game/#{game.id}.html" %>
</td>
</tr>
<% end %>
</table>
</div>
8 changes: 8 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</head>
<body>

Expand Down
33 changes: 33 additions & 0 deletions app/views/shared/_nav.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<nav class="navbar navbar-fixed-top navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<% if current_user %>
<li><%= link_to root_path do %> Welcome, <%= current_user.name %><% end %></li>
<% end %>
</ul>

<ul class="nav navbar-nav navbar-right">
<% if current_user %>
<li><%= link_to "Play Tic Tac Toe on our partner site", tictac_path %></li>
<li><%= link_to "2048", root_path %></li>
<li><%= link_to "Leaderboard", leaderboard_path %></li>
<li><%= link_to "Saved Games", user_game_index_path(user_id: current_user.id) %></li>
<li><%= link_to "Log Out", signout_path %></li>
<% end %>
</ul>
</div>
</div>
</nav>
Loading