summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/matches_controller.rb12
-rw-r--r--app/views/matches/index.html.erb11
2 files changed, 17 insertions, 6 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index 93b5514..8e7cc9e 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -172,6 +172,18 @@ class MatchesController < ApplicationController
scores.each do |user_name, score|
Score.create(user: User.find_by_user_name(user_name), match: @match, value: score.to_i)
end
+
+ team_scores = {}
+ @match.teams.each do |team|
+ team_scores[team] = 0
+ team.users.each do |user|
+ team_scores[team] += scores[user.user_name].to_i
+ end
+ end
+
+ teams = team_scores.invert
+ @match.winner = teams[teams.keys.sort.last]
+
respond_to do |format|
if @match.save
format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Peer evaluation started.' }
diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb
index def97ba..80d12ab 100644
--- a/app/views/matches/index.html.erb
+++ b/app/views/matches/index.html.erb
@@ -4,26 +4,25 @@
<table class="table">
<thead>
<tr>
- <th>Status</th>
<th>Name</th>
+ <th>Status</th>
<th>Winner</th>
<th></th>
</tr>
</thead>
<tbody class="table-hover">
- <% @tournament.matches.each do |match| %>
+ <% @tournament.matches.order(:id).reverse.each do |match| %>
<tr>
- <td><%= match.status %></td>
- <td><%= match.id%></td>
<td><%= match.name %></td>
+ <td><%= match.status %></td>
+ <td><%= (match.winner.nil? ? "-" : "Team #{match.winner.id}") %></td>
<td><%= link_to "Show", tournament_match_path(@tournament, match) %>
<td> <%# 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 %>
<input type="hidden" name="update_action" value="start">
- <%= submit_tag("Start Match") %>
+ <%= submit_tag("Start Match", :dissabled => match.teams.count < @tournament.min_teams_per_match) %>
<% end %>
<% end %>
</div></td>