diff --git a/app/controllers/seats_controller.rb b/app/controllers/seats_controller.rb
index 9551ef1b..eb9e0439 100644
--- a/app/controllers/seats_controller.rb
+++ b/app/controllers/seats_controller.rb
@@ -66,10 +66,18 @@ class SeatsController < ApplicationController
# POST /seats/1
def sit
@message = @seat.sit current_user
+ respond_to do |format|
+ if @seat.save
+ format.html { redirect_to @seat.table, notice: 'Seat was successfully sat in.' }
+ else
+ format.html { redirect_to @seat.table, notice: 'Failed to sit.' }
+ end
+ end
end
def stand
@message = @seat.stand current_user
+ redirect_to @seat.table, notice: @message
end
private
diff --git a/app/controllers/tables_controller.rb b/app/controllers/tables_controller.rb
index deb22a34..cc1f7878 100644
--- a/app/controllers/tables_controller.rb
+++ b/app/controllers/tables_controller.rb
@@ -67,6 +67,8 @@ class TablesController < ApplicationController
# Use callbacks to share common setup or constraints between actions.
def set_table
@table = Table.find(params[:id])
+ @game = @table.current_game
+ @seats = @table.seats.order(:id)
end
# Never trust parameters from the scary internet, only allow the white list through.
diff --git a/app/models/seat.rb b/app/models/seat.rb
index e00008f6..c8dc1208 100644
--- a/app/models/seat.rb
+++ b/app/models/seat.rb
@@ -21,11 +21,11 @@ class Seat < ActiveRecord::Base
end
end
- def stand(current_user)
- unless self.occupied_by?(current_user)
+ def stand(user)
+ unless self.occupied_by?(user)
return "Error. Seat not occupied by you."
else
- self.table.current_game.remove_player_from_user(current_user)
+ self.table.current_game.remove_player_from_user(user)
self.user_id = nil
self.user_soft_token = nil
self.player_id = nil
diff --git a/app/views/games/show.html.haml b/app/views/games/show.html.haml
index 6a2756a2..8b91b283 100644
--- a/app/views/games/show.html.haml
+++ b/app/views/games/show.html.haml
@@ -1,32 +1,31 @@
-#game-component-container-container= react_component 'Game', props = {id: @game.id, current_user: current_user}, html_options = {id: "game-component-container"}
+-# #game-component-container-container= react_component 'Game', props = {id: @game.id, current_user: current_user}, html_options = {id: "game-component-container"}
-# TODO: Remove deprecated commented out code
--#%p
%b Status:
+%p
= @game.status
--#%p
+%p
%b Title:
= @game.title
--#- if @game.can_accomodate(current_user)
+- if @game.can_accomodate(current_user)
= link_to 'Join', game_join_path(@game)
--#- if @game.startable? && @game.already_has?(current_user)
+- if @game.startable? && @game.already_has?(current_user)
= link_to 'Start', game_start_path(@game)
-#.debug
= button_to 'Debug Start', game_start_path(@game), method: :get
= link_to 'Edit Game', edit_game_path(@game)
--#.players
+.players
%b Players:
%ol
- @game.players.each do |player|
%li
- // Show the users email TODO show username instead
- = player.user.email
+ = player.display_name
// Show the user which player they are
= "Me" if player.user == current_user
@@ -39,9 +38,10 @@
- if player.user == current_user && player.inventory.empty? == false
-##inventory
+
-# TODO better logic, not in view
--#- unless @game.status == nil
- -#.table
+- unless @game.status == nil
+ .table
-# TODO better logic, not in view. Set play to beat = nil; instead of view logic
- if @game.play_to_beat && @game.player_to_beat != @game.controlling_player
- if @game.play_to_beat.play
@@ -49,9 +49,9 @@
Hand to beat
%span.hand-type= @game.play_to_beat.play.hand_type
%div= @game.play_to_beat.play.to_s
- -#- @game.play_to_beat.play.player_cards.each do |card|
+ - @game.play_to_beat.play.player_cards.each do |card|
= card.to_s
- %span.player= @game.play_to_beat.play.player.user.email
+ %span.player= @game.play_to_beat.play.player.display_name
- else
%h1 Open table
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 53a3cf31..90bc2e27 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -1,5 +1,5 @@
-
+
ThirteenTienLen
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
diff --git a/app/views/tables/show.html.haml b/app/views/tables/show.html.haml
index 84261a07..5ea42456 100644
--- a/app/views/tables/show.html.haml
+++ b/app/views/tables/show.html.haml
@@ -3,4 +3,100 @@
= 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"}
+-# #table-component-container-container= react_component 'Table', props = {url: "#{table_path @table}"}, html_options = {id: "table-component-container"}
+%h1= @table.title
+
+- if @game.startable? && @game.already_has?(current_user)
+ = link_to 'Start', game_start_path(@game)
+
+-#.debug
+ = button_to 'Debug Start', game_start_path(@game), method: :get
+ = link_to 'Edit Game', edit_game_path(@game)
+
+.players
+ %b Players:
+ %ol
+ - @game.players.each do |player|
+ %li
+ = player.display_name
+ // Show the user which player they are
+ = "Me" if player.soft_token == current_user.soft_token
+
+ // Show whose turn it is
+ - if @game.controlling_player_id
+ %strong= "My Turn " if @game.controlling_player == player
+
+ // Show the players' cards
+ - if player.user == current_user && player.inventory.empty? == false
+ -##inventory
+
+%p
+ %b Game:
+ = @game.title
+
+%p
+ = @game.status
+
+
+-# TODO better logic, not in view
+- unless @game.status == nil
+ .table
+ -# TODO better logic, not in view. Set play to beat = nil; instead of view logic
+ - if @game.play_to_beat && @game.player_to_beat != @game.controlling_player
+ - if @game.play_to_beat.play
+ %h1
+ Hand to beat
+ %span.hand-type= @game.play_to_beat.play.hand_type
+ %div= @game.play_to_beat.play.to_s
+ - @game.play_to_beat.play.player_cards.each do |card|
+ = card.to_s
+ %span.player= @game.play_to_beat.play.player.display_name
+ - else
+ %h1 Open table
+
+ .controls
+ - if @game.control_user == current_user
+ // Play hand form
+ = form_for @game, :url => play_hand_game_path(@game), remote: true do |f|
+ // Provide id of current game
+ -#= f.hidden_field :id
+ = f.submit "Play Hand"
+ = form_for @game, :url => play_hand_game_path(@game) do |f|
+ // Provide id of current game
+ -#= f.hidden_field :id
+ = f.hidden_field :hand_type, value: 'pass'
+ = f.submit "Pass"
+
+
+#game-component
+ %h1= @game.title
+
+ - if @game.started?
+ - else
+ %section#game-controls
+ -# TODO: If not joinable, show why. i.e. game full
+ -# TODO: DEPRECATED use seat sit instead this.state.data.is_joinable ? : null
+ -# TODO: If not startable, show why. i.e. need more players
+ -# - if @game.can_accomodate(current_user)
+ = button_to "Join", join_game_path(@game)
+
+
+ #playerList
+ #top
+ .game-seat.position-1
+ .seat
+ .seat-controls
+ - if @seats[0].occupied?
+ - if @seats[0].occupied_by? current_user
+ = button_to "Stand",
+ stand_seat_path(@seats[0])
+ - else
+ = button_to "Sit",
+ sit_seat_path(@seats[0])
+
+ - if @seats[0].player
+ .player
+ .user-name= @seats[0].player.display_name
+ - if @game.started?
+ .inventory-count= @seats[0].player.inventory.count
+
diff --git a/config/routes.rb b/config/routes.rb
index 62d517bf..2ad13b1a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -7,9 +7,20 @@ Rails.application.routes.draw do
patch 'stand'
end
end
- resources :games
+ resources :games do
+ # member do
+ # post :join
+ # end
+ end
end
+ resources :seats do
+ member do
+ post 'sit'
+ post 'stand'
+ end
+ end
+
resources :games do
member do
get 'my-inventory'
diff --git a/stashtable.txt b/stashtable.txt
new file mode 100644
index 00000000..440aedf1
--- /dev/null
+++ b/stashtable.txt
@@ -0,0 +1,69 @@
+ {/* Show player controls if player is owned by current_user */}
+ {(this.props.soft_token == this.props.game.current_user_soft_token) && (this.props.game.is_started == true)
+ ? ( )
+ :
+
+ {[...Array(this.props.inventory_count)].map((card, index) =>

)}
+
+ }
+
+
+
+
+
+
+
+
+
+
+ : "Empty" }
+
+
+
+
+
+
+
+
+