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

2048-rails Dfparh/master #2

Open
wants to merge 102 commits into
base: dfparh/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
81d414c
Delete excess words from game page
dezshino Feb 8, 2016
14ffc5b
Add gems for omniauth
lacuchilla Feb 8, 2016
6eb9339
Add dotenv-rails to gemfiles, add .env to gitignore
dezshino Feb 8, 2016
ba1d6fb
Set up for omniauth, add sessions controller
dezshino Feb 8, 2016
25411ab
Add a user model
dezshino Feb 8, 2016
31d5e7c
Add uid to user model
dezshino Feb 8, 2016
2e27c56
Add login and log out routes, add to sessions controller
dezshino Feb 8, 2016
a28c7af
Correct typo in nav file and add some methods to user model
lacuchilla Feb 8, 2016
73fa07b
Remove navbar until working to test other parts
dezshino Feb 9, 2016
a68ea5e
Add login path view for now
dezshino Feb 9, 2016
38860b7
change file name
dezshino Feb 9, 2016
086cd8b
Remove script
dezshino Feb 9, 2016
af63575
Add bootstrap
dezshino Feb 9, 2016
0e51f88
Bootstrap config
dezshino Feb 9, 2016
f53980d
Styled navbar to remove whitespace above it
lacuchilla Feb 9, 2016
1a24526
Define current user
dezshino Feb 9, 2016
91b96a2
Move navbar to right of screen and add thoughts file.
lacuchilla Feb 9, 2016
51cf1d2
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
lacuchilla Feb 9, 2016
faad39b
Add fixed-top-class to navbar and remove unneeded code
dezshino Feb 9, 2016
af99b66
Trying things
lacuchilla Feb 9, 2016
ccf92d2
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
lacuchilla Feb 9, 2016
be16715
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
lacuchilla Feb 9, 2016
c029d86
Merge branch 'amy' into dfparh/master
lacuchilla Feb 9, 2016
b1bd184
Add find_or_create_from_omniauth method to User model
dezshino Feb 9, 2016
cc5a4c7
Add method to find or create from omniauth to user model
dezshino Feb 9, 2016
ff062b7
Merge branch 'desiree' into dfparh/master
dezshino Feb 9, 2016
8adf557
add a few methods
lacuchilla Feb 9, 2016
90f856f
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
lacuchilla Feb 9, 2016
0742c72
Create a game model
dezshino Feb 9, 2016
a16bbd1
Set up active record relation between users and games
dezshino Feb 9, 2016
d29d913
Merge branch 'desiree' into dfparh/master
dezshino Feb 9, 2016
18b4280
Add games controller
dezshino Feb 9, 2016
fcfc582
More work on logging in
lacuchilla Feb 9, 2016
5bc3578
Change game_state in the game model from a string to a text
dezshino Feb 9, 2016
a59eeee
fix login/logout. Things seem to be working
lacuchilla Feb 9, 2016
7093c60
Change game state from string to text
dezshino Feb 10, 2016
d1f6004
Begin to add controller methods for api endpoints
lacuchilla Feb 10, 2016
720a33a
Clean up navbar code, move login and out links to the right
dezshino Feb 10, 2016
0731c9e
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
dezshino Feb 10, 2016
d89c438
More additions to games controller
lacuchilla Feb 10, 2016
1a048a3
set default order for games association
dezshino Feb 10, 2016
5d7ef1c
fix order to have lambda
dezshino Feb 10, 2016
3d43f39
Add resource for games
dezshino Feb 10, 2016
b08d370
Working on saving a game to the database
dezshino Feb 10, 2016
4a9da5a
Able to save games to database
dezshino Feb 10, 2016
a2929ee
Able to load from database on refresh
dezshino Feb 10, 2016
8d2e401
Add commented out notes
dezshino Feb 10, 2016
5c86971
Fix height of score containers
dezshino Feb 10, 2016
0263621
Adjust navbar links
dezshino Feb 10, 2016
4b08896
Add container class for bootstrap, Create a view for a users games
dezshino Feb 10, 2016
813d016
Remove excess div
dezshino Feb 10, 2016
c66d808
Add migration for adding the provider and image url to users model
lacuchilla Feb 10, 2016
8334b7f
Fix merge conflict in games controller
lacuchilla Feb 10, 2016
6e78ac5
Working on code for creating and saving games
dezshino Feb 10, 2016
88d9e74
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
dezshino Feb 10, 2016
bfea777
Add user image and blank default image
lacuchilla Feb 10, 2016
3d28bf3
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
lacuchilla Feb 10, 2016
825d5ba
Begin working on leaderboard view
lacuchilla Feb 10, 2016
e737f22
Game is updated with every move
dezshino Feb 10, 2016
aad60d5
More messing around with leaderboard
lacuchilla Feb 11, 2016
586c581
New game works and games autosave/patch with every move
dezshino Feb 11, 2016
852699d
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
dezshino Feb 11, 2016
56e6f1d
Remove unused code
dezshino Feb 11, 2016
31abb5d
Remove line of code that was causing refresh to error
dezshino Feb 11, 2016
e1f3d2e
Send MyGames navbar link to games index
dezshino Feb 11, 2016
48d3cdd
Start building My Games page
dezshino Feb 11, 2016
410d29b
Create a table for My Games
dezshino Feb 11, 2016
774c2bb
2048 link in navbar goes to root_path now
dezshino Feb 11, 2016
d04421b
Begin work on adding score to game object
lacuchilla Feb 11, 2016
2657b21
Format dates for now
dezshino Feb 11, 2016
29e9cd6
Display a message instead of table if there are no games
dezshino Feb 11, 2016
01b176d
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
dezshino Feb 11, 2016
ad931f5
Fix broken code
lacuchilla Feb 11, 2016
ee27497
Fix spacing
dezshino Feb 11, 2016
e297c14
Can delete games now in My Games page
dezshino Feb 11, 2016
266e8c2
Improve navbar styling
dezshino Feb 11, 2016
f0e1061
Make dates more readable
dezshino Feb 11, 2016
bd42c84
Update create method in games controller
lacuchilla Feb 11, 2016
872e3b7
Fix merge conflict in game params
lacuchilla Feb 11, 2016
84e3b7b
Add best score attribute to user model
lacuchilla Feb 11, 2016
9be4232
Add score
dezshino Feb 12, 2016
0e837b1
Fix update, also has score now
dezshino Feb 12, 2016
7610d50
Resume game works
dezshino Feb 12, 2016
aed6401
Commented out notes
dezshino Feb 12, 2016
5a80948
Remove unneccessary instance variable symbols
dezshino Feb 12, 2016
34b7b73
Require login
dezshino Feb 12, 2016
0b356e4
Undo for now
dezshino Feb 12, 2016
82d856a
Add require login back in, wasn't the issue
dezshino Feb 12, 2016
196205d
Add table-hover style to My Games table
dezshino Feb 12, 2016
64ee9e2
Update styling
dezshino Feb 12, 2016
f2a406d
Match games index font color to gameboard color
dezshino Feb 12, 2016
7f871dd
Populate leaderboard with user id and high scores
lacuchilla Feb 12, 2016
057aecb
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
lacuchilla Feb 12, 2016
3e23f30
Setup flash notices
dezshino Feb 12, 2016
7438d7e
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
dezshino Feb 12, 2016
3f7fe70
Move flash message down so they show
dezshino Feb 12, 2016
1932046
Add leaderboard ranking
lacuchilla Feb 12, 2016
7113d2d
Merge branch 'dfparh/master' of github.com:desireepoland/2048-rails i…
lacuchilla Feb 12, 2016
72a1d6d
Add bootstrap rows to header info in line
dezshino Feb 12, 2016
8c53d8d
Add another row, everything centered now
dezshino Feb 12, 2016
fe80903
Game works for non signed in users now
dezshino Feb 12, 2016
fe886e0
Styling for table on leaderboard page
lacuchilla 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

/.env

# Ignore bundler config.
/.bundle

Expand Down
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
ruby '2.2.3'


gem 'bootstrap-sass', '~> 3.3.6'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use SCSS for stylesheets
Expand All @@ -19,13 +19,16 @@ gem 'jquery-rails'
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-twitter"

group :production do
gem 'pg'
gem 'rails_12factor'
end

group :development, :test do
gem 'dotenv-rails'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand All @@ -43,4 +46,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

25 changes: 25 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
autoprefixer-rails (6.3.1)
execjs
json
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.6)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.2)
byebug (8.2.2)
coderay (1.1.0)
Expand All @@ -56,10 +62,15 @@ 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)
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 @@ -80,6 +91,16 @@ GEM
multi_json (1.11.2)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
oauth (0.4.7)
omniauth (1.3.1)
hashie (>= 1.2, < 4)
rack (>= 1.0, < 3)
omniauth-oauth (1.1.0)
oauth
omniauth (~> 1.0)
omniauth-twitter (1.2.1)
json (~> 1.3)
omniauth-oauth (~> 1.1)
pg (0.18.4)
pry (0.10.3)
coderay (~> 1.1.0)
Expand Down Expand Up @@ -177,10 +198,14 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
dotenv-rails
jbuilder (~> 2.0)
jquery-rails
omniauth
omniauth-twitter
pg
pry
rails (= 4.2.5)
Expand Down
Binary file added app/assets/images/blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require bootstrap-sprockets
9 changes: 9 additions & 0 deletions app/assets/javascripts/games.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$(document).ready(function(){
$(".resume-link").on("click", function(){
var gameID = $(this).data("id");
// make a new LocalStorageManager and save to variable
var storageManager = new LocalStorageManager;
// call the setID function on the LocalStorageManager instance
storageManager.saveID(gameID);
});
});
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/
3 changes: 3 additions & 0 deletions app/assets/javascripts/users.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/
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,45 @@
*= require_tree .
*= require_self
*/
@import "bootstrap-sprockets";
@import "bootstrap";

.score-container {
height: 300px;
}

.login {
margin-top: 200px;
}

.leaders {
margin-top: 200px;
}

.navbar-brand {
float: right;
}

.games-index{
padding-top: 60px;
font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
color: #373E66;
}

.welcome {
margin-top: 12px;
margin-right: 15px;
}

.leaderboard {
color: #373E66;
}

.top-scores {
margin-top: 100px;
color: #373E66;
}

.alert {
margin-top: 75px;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/games.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the games controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
17 changes: 17 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,21 @@ 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 :current_user, :except => {:games =>:show}

helper_method :current_user

def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end

helper_method :current_user
# The helper_method line allows us to use @current_user in our view files.

def require_login
unless current_user
flash[:error] = "Please log in."
redirect_to login_path
end
end
end
61 changes: 61 additions & 0 deletions app/controllers/games_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class GamesController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :require_login, only: [:index, :edit, :new]

def index
@games = current_user.games
end

def show
if current_user
if params[:id]
@game = current_user.games.find_by(id: params[:id])
else
@game = current_user.games.first
end
end
# render json: @game
render :json => @game.as_json, :status => :ok
end

def new
# binding.pry
@game = current_user.games.new(game_params)
end

def create

@game = current_user.games.new(game_params)

if @game.save
# pass an array of acceptable formats - [:json]
render json: @game, status: 201
else
render json: {error: "Game could not be created."}, status: 422
end
end


def update
@game = Game.find(game_params[:id])
if @game.update_attributes(game_params)
# pass an array of acceptable formats - [:json]
render json: @game, status: 200
else
render json: {error: "Game could not be updated."}, status: 422
end

@top_games = Game.order(score: :desc).limit(5)
end

def destroy
Game.find(params[:id]).destroy
redirect_to games_path
end

private

def game_params
params.permit(:id, :game_state, :score)
end
end
32 changes: 32 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class SessionsController < ApplicationController
skip_before_filter :verify_authenticity_token, only: :create
before_action :current_user
protect_from_forgery with: :null_session

def new
end

def create
auth_hash = request.env['omniauth.auth']
if auth_hash["uid"]
@user = User.find_or_create_from_omniauth(auth_hash)
if @user
session[:user_id] = @user.id
else
flash[:notice] = "Failed to save the user"
end
else
flash[:notice] = "Failed to authenticate"
end
redirect_to root_path
end

def logged_in?
!current_user.nil?
end

def destroy
session[:user_id] = nil
redirect_to root_path
end
end
8 changes: 8 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class UsersController < ApplicationController
def leaderboard
@users = User.all
@games = Game.all
@top_games = Game.order(score: :desc).limit(5)
end

end
14 changes: 14 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
module ApplicationHelper
def bootstrap_class_for flash_type
case flash_type
when "success"
"alert-success"
when "error"
"alert-danger"
when "alert"
"alert-block"
when "notice"
"alert-info"
else
flash_type.to_s
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/games_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module GamesHelper
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
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
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
25 changes: 25 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class User < ActiveRecord::Base
has_many :games, -> { order "updated_at DESC" }

def self.find_or_create_from_omniauth(auth_hash)
user = self.find_by(uid: auth_hash["uid"])
if !user.nil?
return user
else
user = User.new
user.uid = auth_hash["uid"]
user.name = auth_hash["info"]["name"]
user.provider = auth_hash["provider"]
user.image_url = auth_hash["info"]["image"]
if !user.image_url.present?
user.image_url = "blank.png"
end
if user.save
user
else
nil
end
end
end

end
28 changes: 28 additions & 0 deletions app/views/games/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div class="games-index">
<h1>My Games</h1>
<% if @games.length == 0 %>
<h3>You have no current games.</h3>
<% else %>
<table class="table table-striped table-hover">
<tbody>
<tr>
<th>First Played</th>
<th>Last Played</th>
<th>Score</th>
<th>Resume</th>
<th>Delete</th>
</tr>
<% @games.each do |game| %>
<tr>
<td><%= game.created_at.localtime.strftime("%b. %d, %Y at %l:%M %p") %></td>
<td><%= game.updated_at.localtime.strftime("%b. %d, %Y at %l:%M %p") %></td>
<td><%= game.score %></td>
<td><%= link_to "▷", root_path, class: "resume-link", data: {id: game.id}%></td>
<td><%= link_to "✕", { :controller=>"games", action: :destroy, :id => game.id}, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
<script src="js/local_storage_manager.js"></script>
Loading