diff options
-rw-r--r-- | app/controllers/tournaments_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 2 | ||||
-rw-r--r-- | app/models/tournament.rb | 14 | ||||
-rw-r--r-- | app/models/user.rb | 4 | ||||
-rw-r--r-- | app/views/tournaments/join.html.erb | 2 | ||||
-rw-r--r-- | app/views/tournaments/show.html.erb | 16 | ||||
-rwxr-xr-x[-rw-r--r--] | stop.sh | 0 |
7 files changed, 41 insertions, 10 deletions
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 74a1f56..3583ec3 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -11,8 +11,10 @@ class TournamentsController < ApplicationController # GET /tournaments/1 # GET /tournaments/1.json def show - unless @tournament.status - redirect_to tournament_matches_page(@tournament) + case @tournament.status + when 0 + when 1..2 + redirect_to "/tournaments/" + @tournament.id.to_s + "/matches" #tournament_matches_page(@tournament) end end @@ -25,15 +27,20 @@ class TournamentsController < ApplicationController # GET /tournaments/1/edit def edit + if params['close_action'] == 'close' + @tournament.status = 1 + @tournament.save + redirect_to "/tournaments" + end end # POST /tournaments # POST /tournaments.json def create @tournament = Tournament.new(tournament_params) - respond_to do |format| if @tournament.save + @tournament.hosts.push(current_user) format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' } format.json { render action: 'show', status: :created, location: @tournament } else diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 907958b..70facca 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -28,7 +28,7 @@ class UsersController < ApplicationController # POST /users.json def create @user = User.new(user_params) - + @user.groups = 0 respond_to do |format| if @user.save sign_in @user diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 44b22f5..fe781e1 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -25,9 +25,17 @@ class Tournament < ActiveRecord::Base for i in 0..num_matches self.matches.create(name: "Match #{i}") end - #self.players.each_slice(num_teams) do |team_players| - # Team.new(users: team_players) - #end + match_num = 0 + team_num = 0 + self.players.each_slice(@tournament.max_players) do |players| + matches[match_num].teams[team_num] = Team.new(users: players) + if (team_num == 0 and team_num % @tournament.max_teams_per_match == 0) + match_num += 1 + team_num = 0 + else + team_num += 1 + end + end end diff --git a/app/models/user.rb b/app/models/user.rb index ff212e4..bd1a9ac 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ActiveRecord::Base - has_and_belongs_to_many :tournaments_played, class_name: "Tournament", foreign_key: "tournament_id", join_table: "players_tournaments" - has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", foreign_key: "tournament_id", join_table: "hosts_tournaments" + has_and_belongs_to_many :tournaments_played, class_name: "Tournament", foreign_key: "player_id", join_table: "players_tournaments" + has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", foreign_key: "host_id", join_table: "hosts_tournaments" before_save { self.email = email.downcase } before_save { self.user_name = user_name } diff --git a/app/views/tournaments/join.html.erb b/app/views/tournaments/join.html.erb new file mode 100644 index 0000000..1d38d68 --- /dev/null +++ b/app/views/tournaments/join.html.erb @@ -0,0 +1,2 @@ + <%= @user.name %> + diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index 0cda6c1..c3a40e7 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -1,10 +1,11 @@ <% if @tournament.joinable_by?(current_user) %> <%= form_tag(tournament_path(@tournament), method: "put") do %> <input type="hidden" name="update_action" value="join"> - <%= submit_tag("Join") %> + <%= current_user.name %><%= submit_tag("Join") %> <% end %> <% end %> +<% if current_user.in_group?(:host) %> <p> <strong>Game:</strong> <%= @tournament.game %> @@ -45,5 +46,18 @@ <%= @tournament.randomized_teams %> </p> +<p> + <strong>Status:</strong> + <%= @tournament.status %> +</p> + +<%= form_tag(tournaments_path.to_s + "/" + @tournament.id.to_s + "/edit", method: "get") do %> + <input type="hidden" name="close_action" value="close"> + <%= submit_tag("Close Tournament Registration") %> +<% end %> + <%= link_to 'Edit', edit_tournament_path(@tournament) %> | <%= link_to 'Back', tournaments_path %> + +<% end %> + |