summaryrefslogtreecommitdiff
path: root/app/views/matches/index.html.erb
blob: 031b2a9342d89eec766f20e41415fe973bb06334 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<h1><%= @tournament.name %> - Matches</h1>


<table class="table">
  <thead>
    <tr>
      <th>Status</th>
      <th>Name</th>
      <th>Winner</th>
      <th></th>
    </tr>
  </thead>

  <tbody class="table-hover">
    <% @tournament.matches.each do |match| %>
      <tr>
        <td><%= match.status %></td>
        <td><%= match.id%></td>
        <td><%= match.name %></td>
        <td><%= link_to "Show", tournament_match_path(@tournament, match) %>
        <td><%= submit_tag("Start Match") %>
      </tr>
    <% end %>
  </tbody>
</table>

<br>

<div id="match-tree">
<SVG version="1.1"
   baseProfile="full"
   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 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>