<%= @tournament.name %> - Matches

<% @tournament.matches.order(:id).reverse.each do |match| %><% end %>
Name Status Winner
<%= match.name %> <%= match.status %> <%= (match.winner.nil? ? "-" : "Team #{match.winner.id}") %> <%= link_to "Show", tournament_match_path(@tournament, match) %> <%# If user is the host, let them start the tournment %> <% if @tournament.hosts.include?(current_user) %> <%= form_tag(tournament_match_path(@tournament, match), method: "put") do %> <% @startable = (match.status == 0) and (match.teams.count >= @tournament.min_teams_per_match) %> <%= submit_tag("Start Match", :disabled => ! @startable) %> <% end %> <% end %>

<% lastrx = 0 lastry = 0 lastrh = 0 lastrw = 0 %> <% (1..@matches.count).each do |i| %> <% 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 %> /> " /> <% if @matches[i-1].teams.first %> Team <%= @matches[i-1].teams.first.id %> <% end %> VS " /> <% if @matches[i-1].teams[1] %> Team <%= @matches[i-1].teams[1].id %> <% end %> <% if i > 1 %> <% end %> <% if Math.log2(i+1) == Math.log2(i+1).ceil %> <% lastrx = rx lastry = ry lastrh = rh lastrw = rw %> <% end %> <% end %>