diff options
-rw-r--r-- | app/controllers/tournaments_controller.rb | 14 | ||||
-rw-r--r-- | app/models/tournament.rb | 8 | ||||
-rw-r--r-- | app/views/matches/index.html.erb | 4 | ||||
-rw-r--r-- | app/views/tournaments/show.html.erb | 8 |
4 files changed, 16 insertions, 18 deletions
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 9cf3404..4bba997 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -36,12 +36,7 @@ class TournamentsController < ApplicationController # GET /tournaments/1/edit def edit - if params['close_action'] == 'close' - @tournament.status = 1 - @tournament.save - @tournament.setup(@tournament) - redirect_to "/tournaments" - end + end # POST /tournaments @@ -96,7 +91,10 @@ class TournamentsController < ApplicationController format.html {redirect_to @tournament, notice: 'You were\'t a part of this tournament.' } format.json { render json: "Permission denied", status: :forbidden } end - when "open" + when "start" + @tournament.status = 1 + @tournament.save + @tournament.setup() respond_to do |format| if @tournament.setup format.html { render action: 'show', notice: 'You have joined this tournament.' } @@ -105,8 +103,6 @@ class TournamentsController < ApplicationController format.html { render action: 'permission_denied', status: :forbidden } format.json { render json: "Permission denied", status: :forbidden } end - #when "close" - # TODO else respond_to do |format| format.html { render action: 'show', notice: "Invalid action", status: :unprocessable_entity } diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 4483535..6d92f3d 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -20,12 +20,12 @@ class Tournament < ActiveRecord::Base end def leave(user) - if players.include?(user) + if players.include?(user) && status == 0 players.delete(user) end end - def setup(tournament) + def setup() num_teams = (self.players.count/self.max_players_per_team).floor num_matches = num_teams - 1 for i in 1..num_matches @@ -33,9 +33,9 @@ class Tournament < ActiveRecord::Base end match_num = 0 team_num = 0 - self.players.each_slice(tournament.max_players_per_team) do |players| + self.players.each_slice(max_players_per_team) do |players| self.matches[match_num].teams.push(Team.create(users: players)) - if (team_num != 0 and team_num % tournament.max_teams_per_match == 0) + if (team_num != 0 and team_num % max_teams_per_match == 0) match_num += 1 team_num = 0 else diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 0f86da6..babf45e 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -1,6 +1,6 @@ <h1><%= @tournament.name %> Matches</h1> -<!-- + <table> <thead> <tr> @@ -29,7 +29,7 @@ </table> <br> ---> + <SVG version="1.1" baseProfile="full" diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index 9939d02..b654804 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -79,8 +79,8 @@ <%# If user is the host, let them start the tournment %> <% if @tournament.hosts.include?(current_user) %> - <%= form_tag(tournaments_path.to_s + "/" + @tournament.id.to_s + "/edit", method: "get") do %> - <input type="hidden" name="close_action" value="close"> + <%= form_tag(tournament_path(@tournament), method: "put") do %> + <input type="hidden" name="update_action" value="start"> <% if @tournament.players.count >= @tournament.min_players_per_team * @tournament.min_teams_per_match %> <%= submit_tag("Start Tournament") %> <% else %> @@ -117,8 +117,10 @@ function donehandle( tournament ) { //if there are enough players to start, enable the button, else disable it. $("input[value=\"Start Tournament\"]").prop('disabled', (pct_complete >= 1)? false : true); + if (tournament["status"] == 1) + window.location.reload(true); } - setTimeout(function(){$.ajax({url: "<%= url_for @tournament %>.json"}).done(donehandle)}, 3000); + setTimeout(function(){$.ajax({url: "<%= url_for @tournament %>.json"}).done(donehandle)}, 2000); } $.ajax({url: "<%= url_for @tournament %>.json"}) |