stash
This commit is contained in:
parent
0de80ca307
commit
bcc059ee33
19
README.md
19
README.md
@ -25,10 +25,11 @@ first play
|
||||
## Proposed Schema
|
||||
|
||||
Table
|
||||
Seat
|
||||
has_many Seats
|
||||
User
|
||||
Games
|
||||
has_many Games
|
||||
players from seats.users
|
||||
has_one :current_game
|
||||
|
||||
## Game Lifecycle
|
||||
|
||||
@ -123,3 +124,17 @@ Attributions
|
||||
|
||||
Source: http://subtlepatterns.com/felt/
|
||||
Author: http://atle.co/
|
||||
|
||||
## Extra suits
|
||||
|
||||
> R. Wayne Schmittberger, in his classic game design primer New Rules for
|
||||
> Classic Games (1992), describes how you can make your own six-suited
|
||||
> deck. Obtain two standard decks with the same backs. Set one aside, and
|
||||
> take the Hearts and Diamonds from the second. Draw an arrow through each
|
||||
> Heart with a permanent black marker to make a suit of Valentines, and
|
||||
> draw an 'X' through each Diamond to make a Kites suit. Shuffle these two
|
||||
> new suits together with the deck you set aside, and presto! a six-suited
|
||||
> Schmittberger deck! (Of course, you can remove either Kites or
|
||||
> Valentines to create a five-suited deck like the Stardeck.)
|
||||
|
||||
http://www.thegamesjournal.com/articles/GameSystems2.shtml
|
||||
|
||||
3
app/assets/javascripts/tables.js.coffee
Normal file
3
app/assets/javascripts/tables.js.coffee
Normal file
@ -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/
|
||||
@ -40,6 +40,7 @@ h1
|
||||
|
||||
header
|
||||
font-size: 3vmin
|
||||
margin-bottom: 10vmin
|
||||
nav
|
||||
padding: 1vmin
|
||||
background: #222
|
||||
|
||||
3
app/assets/stylesheets/tables.css.scss
Normal file
3
app/assets/stylesheets/tables.css.scss
Normal file
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the Tables controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
74
app/controllers/tables_controller.rb
Normal file
74
app/controllers/tables_controller.rb
Normal file
@ -0,0 +1,74 @@
|
||||
class TablesController < ApplicationController
|
||||
before_action :set_table, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /tables
|
||||
# GET /tables.json
|
||||
def index
|
||||
@tables = Table.all
|
||||
end
|
||||
|
||||
# GET /tables/1
|
||||
# GET /tables/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /tables/new
|
||||
def new
|
||||
@table = Table.new
|
||||
end
|
||||
|
||||
# GET /tables/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /tables
|
||||
# POST /tables.json
|
||||
def create
|
||||
@table = Table.new(table_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @table.save
|
||||
format.html { redirect_to @table, notice: 'Table was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @table }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @table.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /tables/1
|
||||
# PATCH/PUT /tables/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @table.update(table_params)
|
||||
format.html { redirect_to @table, notice: 'Table was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @table }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @table.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /tables/1
|
||||
# DELETE /tables/1.json
|
||||
def destroy
|
||||
@table.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to tables_url, notice: 'Table was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_table
|
||||
@table = Table.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def table_params
|
||||
params.require(:table).permit(:title)
|
||||
end
|
||||
end
|
||||
2
app/helpers/tables_helper.rb
Normal file
2
app/helpers/tables_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module TablesHelper
|
||||
end
|
||||
@ -1,5 +1,6 @@
|
||||
class Table < ActiveRecord::Base
|
||||
has_many :seats
|
||||
has_many :users, through: :seats
|
||||
has_many :games
|
||||
has_one :current_game, :class_name => "Game", :primary_key => "current_game_id"
|
||||
end
|
||||
|
||||
25
app/policies/table_policy.rb
Normal file
25
app/policies/table_policy.rb
Normal file
@ -0,0 +1,25 @@
|
||||
class TablePolicy
|
||||
attr_reader :current_user, :model
|
||||
|
||||
def initialize(current_user, model)
|
||||
@current_user = current_user || User.new
|
||||
@table = model
|
||||
end
|
||||
|
||||
def index?
|
||||
@current_user.admin?
|
||||
end
|
||||
|
||||
def show?
|
||||
@current_user.admin? || @current_user == @user
|
||||
end
|
||||
|
||||
def update?
|
||||
@current_user.admin? # TODO: Allow table owner to edit || @table.owner == @current_user
|
||||
end
|
||||
|
||||
def destroy?
|
||||
return false if @current_user == @user
|
||||
@current_user.admin?
|
||||
end
|
||||
end
|
||||
@ -1,7 +1,7 @@
|
||||
<nav>
|
||||
<ul>
|
||||
<li><%= link_to 'Main Menu', root_path %></li>
|
||||
<li><%= link_to 'Games', games_path %></li>
|
||||
<li><%= link_to 'Tables', tables_path %></li>
|
||||
<% if user_signed_in? %>
|
||||
<li><%= link_to 'Edit account', edit_user_registration_path %></li>
|
||||
<li><%= link_to 'Sign out', destroy_user_session_path, :method=>'delete' %></li>
|
||||
|
||||
8
app/views/tables/_form.html.haml
Normal file
8
app/views/tables/_form.html.haml
Normal file
@ -0,0 +1,8 @@
|
||||
= simple_form_for(@table) do |f|
|
||||
= f.error_notification
|
||||
|
||||
.form-inputs
|
||||
= f.input :title
|
||||
|
||||
.form-actions
|
||||
= f.button :submit
|
||||
7
app/views/tables/edit.html.haml
Normal file
7
app/views/tables/edit.html.haml
Normal file
@ -0,0 +1,7 @@
|
||||
%h1 Editing table
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Show', @table
|
||||
\|
|
||||
= link_to 'Back', tables_path
|
||||
15
app/views/tables/index.html.haml
Normal file
15
app/views/tables/index.html.haml
Normal file
@ -0,0 +1,15 @@
|
||||
%h1 Listing tables
|
||||
|
||||
.button= link_to 'New Table', new_table_path
|
||||
|
||||
.tables-container
|
||||
- @tables.each do |table|
|
||||
.table
|
||||
.title= link_to table.title, table
|
||||
.player-count= "#{table.users.count} Players"
|
||||
|
||||
- if policy(table).update?
|
||||
.owner-controls
|
||||
= link_to 'Edit', edit_table_path(table)
|
||||
= link_to 'Destroy', table, :method => :delete, :data => { :confirm => 'Are you sure?' }
|
||||
|
||||
5
app/views/tables/new.html.haml
Normal file
5
app/views/tables/new.html.haml
Normal file
@ -0,0 +1,5 @@
|
||||
%h1 New table
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Back', tables_path
|
||||
6
app/views/tables/show.html.haml
Normal file
6
app/views/tables/show.html.haml
Normal file
@ -0,0 +1,6 @@
|
||||
- if policy(@table).update?
|
||||
.owner-controls
|
||||
= link_to 'Edit', edit_table_path(@table)
|
||||
= link_to 'Destroy', game, :method => :delete, :data => { :confirm => 'Are you sure?' }
|
||||
|
||||
#table-component-container-container= react_component 'Table', props = {url: "#{table_path @table}"}, html_options = {id: "table-component-container"}
|
||||
@ -1,5 +1,6 @@
|
||||
Rails.application.routes.draw do
|
||||
resources :players
|
||||
resources :tables
|
||||
|
||||
resources :games do
|
||||
member do
|
||||
|
||||
@ -9,6 +9,7 @@ RSpec.describe Table, type: :model do
|
||||
|
||||
it { should respond_to :title }
|
||||
it { should respond_to :seats }
|
||||
it { should respond_to :users }
|
||||
it { should respond_to :games }
|
||||
it { should respond_to :current_game }
|
||||
|
||||
@ -20,6 +21,10 @@ RSpec.describe Table, type: :model do
|
||||
expect(@table.seats.class).to match Seat::ActiveRecord_Associations_CollectionProxy
|
||||
end
|
||||
|
||||
it '#users returns Users collection' do
|
||||
expect(@table.users.class).to match User::ActiveRecord_Associations_CollectionProxy
|
||||
end
|
||||
|
||||
it '#games returns Games collection' do
|
||||
expect(@table.games.class).to match Game::ActiveRecord_Associations_CollectionProxy
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user