diff options
-rw-r--r-- | app/controllers/matches_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/tournaments_controller.rb | 2 | ||||
-rw-r--r-- | app/models/tournament.rb | 4 | ||||
-rw-r--r-- | app/views/matches/index.html.erb | 32 | ||||
-rw-r--r-- | app/views/matches/show.html.erb | 4 |
5 files changed, 36 insertions, 10 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 31fc9ad..e773667 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -8,6 +8,10 @@ class MatchesController < ApplicationController def index @matches = @tournament.matches + # width of SVG + @width = 300 * (Math.log2(@matches.count).floor + 1) + 300; + # height of SVG + @height = 200 * 2**Math.log2(@matches.count).floor + 100; end def get_riot_info diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index a9e91b0..2fc82ed 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -99,7 +99,7 @@ class TournamentsController < ApplicationController format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } format.json { head :no_content } else - format.html { render action: 'permission_denied', status: :forbidden } + format.html { redirect_to @tournament, notice: "You don't have permission to start this tournament." } format.json { render json: "Permission denied", status: :forbidden } end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index e408cfe..0029de7 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -31,7 +31,7 @@ class Tournament < ActiveRecord::Base for i in 1..num_matches self.matches.create(name: "Match #{i}", status: 0) end - match_num = 0 + match_num = num_matches-1 team_num = 0 #for each grouping of min_players_per_team self.players.each_slice(min_players_per_team) do |players| @@ -39,7 +39,7 @@ class Tournament < ActiveRecord::Base self.matches[match_num].teams.push(Team.create(users: players)) #if the match is full, move to the next match, otherwise move to the next team if (team_num != 0 and team_num % max_teams_per_match == 0) - match_num += 1 + match_num -= 1 team_num = 0 else team_num += 1 diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 219507d..031b2a9 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -26,17 +26,39 @@ <br> - +<div id="match-tree"> <SVG version="1.1" baseProfile="full" - width="<%= 300 * @matches.count / 2 + 50 %>" height="<%= 200 * @matches.count + 50 %>" + width="<%= @width %>" height="<%= @height = [@height, 500].max %>" xmlns="http://www.w3.org/2000/svg"> - + <line x1="300" y1="0" x2="300" y2="<%= @height %>" stroke="black" /> <% (1..@matches.count).each do |i| %> <g class="svg-match"> - <rect rx="10" - + <rect height="120px" width="213px" + x="<%= @width - (i-1)*50 - 250*(Math.log2(i).floor+1) %>" + y="<%= (@height/(Math.log2(i).floor+2)) - 60 + 250*(i - 2**(Math.log2(i).floor)) %>" + fill="#ffd281" + rx="20px" + stroke-width="2" + <% case @matches[i-1].status %> + <% when 0 %> + <% if @matches[i-1].teams.count < @tournament.min_teams_per_match %> + stroke="red" + fill-opacity="0.6" + <% else %> + stroke="green" + <% end %> + <% when 1 %> + stroke="orange" + <% when 2 %> + stroke="yellow" + <% when 3 %> + stroke="grey" + <% end %> + /> </g> <% end %> + </SVG> +</div>
\ No newline at end of file diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 6fb4042..20860e2 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -61,8 +61,8 @@ Players see the Peer Review Page Host see the Game Status --> -<% if (@match.status==0) %> - <% if (@tournament.players.include?(current_user) %> +<% if @match.status == 0 %> + <% if @tournament.players.include?(current_user) %> <% @match.teams.each do |team| %> <ul> <% team.users.collect{|u| u.user_name}.each do |k| %> |