Skip to content

Commit

Permalink
Merge branch 'main' into SCRUM-1-UserAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenSanzas authored Oct 3, 2024
2 parents d30dd03 + 06e4ba8 commit 0e99bee
Show file tree
Hide file tree
Showing 27 changed files with 454 additions and 4 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
source "https://rubygems.org"
ruby "3.3.4"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.2.1"
Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,5 @@ DEPENDENCIES
tzinfo-data
uglifier

RUBY VERSION
ruby 3.3.4p94

BUNDLED WITH
2.5.18
98 changes: 98 additions & 0 deletions app/assets/stylesheets/games.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* app/assets/stylesheets/pages.css */

.container {
padding: 20px;
}

.header {
display: flex;
justify-content: space-between;
align-items: center;
}

h2 {
font-size: 24px;
}

.btn-login {
background-color: #4caf50;
color: white;
padding: 10px 20px;
text-align: center;
border: none;
border-radius: 5px;
cursor: pointer;
}

.btn-admin {
background-color: red;
}

.dropdown {
position: relative;
display: inline-block;
}

.dropbtn {
background-color: #4caf50;
color: white;
padding: 10px 20px;
font-size: 16px;
border: none;
cursor: pointer;
border-radius: 5px;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

.dropdown-content a:hover {
background-color: #f1f1f1;
}

.dropdown:hover .dropdown-content {
display: block;
}

.dropdown:hover .dropbtn {
background-color: #3e8e41;
}

.game-list {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
margin-top: 20px;
max-width: 1600px;
margin: 0 auto;
}

.game-item {
padding: 15px;
border: 1px solid #ddd;
text-align: center;
border-radius: 8px;
}

.btn-play {
background-color: #4caf50;
color: white;
padding: 10px 20px;
text-align: center;
border: none;
border-radius: 5px;
cursor: pointer;
}
75 changes: 75 additions & 0 deletions app/controllers/games_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class GamesController < ApplicationController
before_action :set_game, only: %i[ show edit update destroy ]

# GET /games or /games.json
def index
@games = Game.all
end

# GET /games/1 or /games/1.json
def show
@game = Game.find(params[:id])
redirect_to send(@game.game_path)
end

def demo_game
end

# GET /games/new
def new
@game = Game.new
end

# GET /games/1/edit
def edit
end

# POST /games or /games.json
def create
@game = Game.new(game_params)

respond_to do |format|
if @game.save
format.html { redirect_to @game, notice: "Game was successfully created." }
format.json { render :show, status: :created, location: @game }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @game.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /games/1 or /games/1.json
def update
respond_to do |format|
if @game.update(game_params)
format.html { redirect_to @game, notice: "Game was successfully updated." }
format.json { render :show, status: :ok, location: @game }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @game.errors, status: :unprocessable_entity }
end
end
end

# DELETE /games/1 or /games/1.json
def destroy
@game.destroy!

respond_to do |format|
format.html { redirect_to games_path, status: :see_other, notice: "Game was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_game
@game = Game.find(params[:id])
end

# Only allow a list of trusted parameters through.
def game_params
params.require(:game).permit(:name, :game_path)
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
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 < ApplicationRecord
validates :name, presence: true
end
27 changes: 27 additions & 0 deletions app/views/games/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= form_with(model: game) do |form| %>
<% if game.errors.any? %>
<div style="color: red">
<h2><%= pluralize(game.errors.count, "error") %> prohibited this game from being saved:</h2>

<ul>
<% game.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.label :name, style: "display: block" %>
<%= form.text_field :name %>
</div>

<div>
<%= form.label :game_path, style: "display: block" %>
<%= form.text_field :game_path %>
</div>

<div>
<%= form.submit %>
</div>
<% end %>
12 changes: 12 additions & 0 deletions app/views/games/_game.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="<%= dom_id game %>">
<p>
<strong>Name:</strong>
<%= game.name %>
</p>

<p>
<strong>Game path:</strong>
<%= game.game_path %>
</p>

</div>
2 changes: 2 additions & 0 deletions app/views/games/_game.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! game, :id, :name, :game_path, :created_at, :updated_at
json.url game_url(game, format: :json)
14 changes: 14 additions & 0 deletions app/views/games/_games.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>
<% content_for :title, "Games" %>

<h1>Games</h1>

<div class="game-list">
<% @games.each do |game| %>
<div class="game-item">
<h3><%= game.name %></h3>
<%= link_to 'Play', game_path(game), class: 'btn btn-play' %>
</div>
<% end %>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/games/demo_game.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p style="color: green"><%= notice %></p>

<div>
Demo Game Page
</div>
12 changes: 12 additions & 0 deletions app/views/games/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% content_for :title, "Editing game" %>

<h1>Editing game</h1>

<%= render "form", game: @game %>

<br>

<div>
<%= link_to "Show this game", @game %> |
<%= link_to "Back to games", games_path %>
</div>
32 changes: 32 additions & 0 deletions app/views/games/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="container">
<!-- Greeting and Login Section -->
<div class="header">
<h2>Hello, <%="Guest" %>!</h2>

<div>
<%# <% if true %>
<%# TODO, using if-else to display login button or account info button %>
<!-- My Account Dropdown -->
<div class="dropdown">
<button class="dropbtn">My Account</button>
<div class="dropdown-content">
<%= link_to 'Game Statistics', '#' %>
<%= link_to 'Update', '#' %>
<%= link_to 'Log Out', '#', method: :delete %>
</div>
</div>
<%# <% else %>
<!-- Login Button -->
<%= link_to 'Log In', '#', class: 'btn btn-login' %>
<%# <% end %>

<% if true %>
<%# TODO, only appear if the user is admin %>
<%= link_to 'All Users for Admin', '#', class: 'btn btn-login btn-admin' %>
<% end%>
</div>
</div>

<!-- Games Section -->

<%= render "games" %>
1 change: 1 addition & 0 deletions app/views/games/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @games, partial: "games/game", as: :game
11 changes: 11 additions & 0 deletions app/views/games/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% content_for :title, "New game" %>

<h1>New game</h1>

<%= render "form", game: @game %>

<br>

<div>
<%= link_to "Back to games", games_path %>
</div>
8 changes: 8 additions & 0 deletions app/views/games/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p style="color: green"><%= notice %></p>

<div>
<%= link_to "Edit this game", edit_game_path(@game) %> |
<%= link_to "Back to games", games_path %>

<%= button_to "Destroy this game", @game, method: :delete %>
</div>
1 change: 1 addition & 0 deletions app/views/games/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "games/game", game: @game
10 changes: 10 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@
get "/users/:id", to: "users#show", as: "user"
get "/logout", to: "sessions#logout", as: "logout"
get "/auth/google_oauth2/callback", to: "sessions#omniauth"

resources :games
root :to => redirect('/games')

get "up" => "rails/health#show", as: :rails_health_check

## stub paths to demo game landing page
get '/spellingbee/:id', to: 'games#demo_game', as: 'spellingbee'
get '/wordle/:id', to: 'games#demo_game', as: 'wordle'
get '/letterboxed/:id', to: 'games#demo_game', as: 'letterboxed'
end
9 changes: 9 additions & 0 deletions db/migrate/20241002002856_create_games.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateGames < ActiveRecord::Migration[7.2]
def change
create_table :games do |t|
t.string 'name'
t.string 'game_path'
t.timestamps
end
end
end
7 changes: 7 additions & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
# MovieGenre.find_or_create_by!(name: genre_name)
# end

initial_games = [
{:name => 'Spelling Bee', :game_path => 'spellingbee_path'},
{:name => 'Wordle', :game_path => 'wordle_path'},
{:name => 'Letter Boxed', :game_path => 'letterboxed_path'}
]

initial_games.each do |game|
Game.find_or_create_by!(game)
end
Binary file added features/.DS_Store
Binary file not shown.
Loading

0 comments on commit 0e99bee

Please sign in to comment.