diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/matches_controller.rb | 41 | ||||
-rw-r--r-- | app/models/tournament.rb | 10 | ||||
-rw-r--r-- | app/views/matches/index.html.erb | 38 | ||||
-rw-r--r-- | app/views/matches/show.html.erb | 199 |
4 files changed, 139 insertions, 149 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 9c0a740..9e376f7 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -144,9 +144,6 @@ class MatchesController < ApplicationController handle_asynchronously :is_match_over def show - if (@match.status == 1) - @scores = @match.scores - end if Tournament.find_by_id(@match.tournament_id).game_id == 1 file_blue = "blue.yaml" file_purple = "purple.yaml" @@ -168,11 +165,32 @@ class MatchesController < ApplicationController format.json { render json: "Permission denied", status: :forbidden } end end - when "score" + when "finish" + @match.status = 2 + + # Individual scores scores = params["scores"] 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 + 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] + + # Schedule next match + cur_match_num = @tournament.matches_ordered.invert[@match] + unless cur_match_num == 1 + @match.winner.matches.push(@tournament.matches_ordered[cur_match_num/2]) + end + respond_to do |format| if @match.save format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Peer evaluation started.' } @@ -183,17 +201,6 @@ class MatchesController < ApplicationController end end when "peer" - @match.status = 2; - respond_to do |format| - if @match.save - format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Scores Submitted' } - format.json { head :no_content } - else - format.html { redirect_to @tournament, notice: "You don't have permission to start this match." } - format.json { render json: "Permission denied", status: :forbidden } - end - end - when "finish" order = params[:review_action] base_score = 2 next_score = 3 @@ -214,7 +221,7 @@ class MatchesController < ApplicationController end respond_to do |format| if @match.save - format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Peer Review Submitted' } + format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Scores Submitted' } format.json { head :no_content } else format.html { redirect_to @tournament, notice: "You don't have permission to start this match." } @@ -232,7 +239,6 @@ class MatchesController < ApplicationController format.json { render json: "Permission denied", status: :forbidden } end end - else respond_to do |format| format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity } @@ -247,7 +253,6 @@ class MatchesController < ApplicationController def set_match set_tournament @match = @tournament.matches.find(params[:id]) - @first = @match.teams.first.users.first.user_name.downcase end def set_tournament @tournament = Tournament.find(params[:tournament_id]) diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 10d7b30..aa331f0 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -5,6 +5,16 @@ class Tournament < ActiveRecord::Base has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments" has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments" + def matches_ordered + h = {} + i = 1 + matches.order(:id).each do |m| + h[i] = m + i += 1 + end + return h + end + def preferences @preferences ||= Preferences.new(self) end diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 78c97bb..15b59f4 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -4,32 +4,30 @@ <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| %> - <tr> - <td><%= match.status %></td> - <td><%= match.id%></td> - <td><%= match.name %></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") %> - <% end %> - <% end %> -</div></td> - </tr> - <% end %> - </tbody> + <tbody class="table-hover"> + <% @tournament.matches.order(:id).reverse.each do |match| %><tr> + <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"> + <% @startable = (match.status == 0) and (match.teams.count >= @tournament.min_teams_per_match) %> + <%= submit_tag("Start Match", :disabled => ! @startable) %> + <% end %> + <% end %> + </td> + </tr><% end %> + </tbody> </table> <br> diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index a0540f9..c92aea3 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -1,21 +1,21 @@ <p> - <strong>Status:</strong> - <%= @match.status %> + <strong>Status:</strong> + <%= @match.status %> </p> <p> - <strong>Tournament:</strong> - <%= @match.tournament.id %> + <strong>Tournament:</strong> + <%= @match.tournament.id %> </p> <p> - <strong>Name:</strong> - <%= @match.name %> + <strong>Name:</strong> + <%= @match.name %> </p> <!-- - Match Status 0 => Pairings Stage - Match Status 1 => Match Active - Match Status 2 => Match Finished (Peer Review Starts) - Match Status 3 => Match Completed (Scores Completed OR Results Page) + Match Status 0 => Created, waiting to start + Match Status 1 => Match is running, waiting to finish + Match Status 2 => Match finished, waiting for peer reviews + Match Status 3 => Totally done. Four views:- (status is Match status) A. Pairings, when status is 0 for either Host or Player Or when status is 1 for player @@ -27,85 +27,22 @@ --> -<% if (@match.status== 0) || !@tournament.players.include?(current_user) %> +<div> + <h2>Teams/users</h2> + <ul> <% @match.teams.each do |team| %> - <ol> - <% team.users.collect{|u| u.user_name}.each do |k| %> - <li><%= k %></li> + <li>Team <%= team.id %><ul> + <% team.users.each do |user| %> + <% if @match.status <= 1 %> + <li><%= user.user_name %></li> + <% else %> + <li><%= user.user_name %> - SCORE: <%= @match.scores.select{|s| s.user == user}.first.value %></li> + <% end %> <% end %> - </ol> + </ul></li> <% end %> - - -<!-- - This is what the Players and the Hosts of the tournament will view when the Match Status is 1 ---> -<% elsif (@match.status==1) %> - <% if @tournament.hosts.include?(current_user) && @scores.empty? %> - <%= form_tag(tournament_match_path(@tournament, @match), method: "put") do %> - <input type="hidden" name="update_action" value="score"> - <% @match.teams.each do |team| %> - <fieldset><legend>Team <%= team.id.to_s %></legend> - <% team.users.collect{|u| u.user_name}.each do |k| %> - <label>Score for <%= k %> - <br> - <%= text_field_tag("scores[#{k}]", 0, size: 3) %> - </label> - <% end %> - </fieldset> - <% end %> - <%= submit_tag("Enter Scores") %> - <% end %> - <% else %> - <% if @scores.empty? %> - <p> The host has yet to post the scores of the match </p> - <% @match.teams.each do |team| %> - <ol> - <% team.users.collect{|u| u.user_name}.each do |k| %> - <li><%= k %></li> - <% end %> - </ol> - <% end %> - <% else %> - <% @match.teams.each do |team| %> - <ol> - <% team.users.each do |user| %> - <li><%= user.user_name %> - SCORE: <%= @scores.select{|s| s.user == user}.first.value %></li> - <% end %> - </ol> - <% end %> - <% end %> - <% end %> - -<!-- - When Match Status is 2 - Players see the Peer Review Page - Host see the Game Status ---> -<% elsif (@match.status==2) %> - <% if (@tournament.players.include?(current_user)) %> - <% @match.teams.each do |team| %> - <% if team.users.include?(current_user) %> - <ol id="boxes" class="sortable"> - <% team.users.collect{|u| u.user_name}.each do |k| %> - <li><%= k%> - <br> - <% if (@tournament.game_id == 1) %> - <%= if @blue2["#{k}"] == nil - "Level: #{@purp2["#{k}"]["level"]} K/D/A: #{@purp2["#{k}"]["championsKilled"]}/#{@purp2["#{k}"]["numDeaths"]}/#{@purp2["#{k}"]["assists"]} Gold:#{@purp2["#{k}"]["goldEarned"]}" - else - "Level: #{@blue2["#{k}"]["level"]} K/D/A: #{@blue2["#{k}"]["championsKilled"]}/#{@blue2["#{k}"]["numDeaths"]}/#{@blue2["#{k}"]["assists"]} Gold:#{@blue2["#{k}"]["goldEarned"]}" - end %> - <% end %> - </li> - <% end %> - </ol> - <% end %> - <% end %> - <% elsif (@tournament.hosts.include?(current_user)) %> - <label>Game Status Page Goes here! Because you are a Host that is not a player!</label> - <% end %> -<% end %> + </ul> +</div> <% unless @match.winner.nil? %> <p> @@ -114,40 +51,80 @@ </p> <% end %> -<% if @tournament.players.include?(current_user) %> -<br /> -<div id="host"> - <%= form_tag(tournament_match_path(@tournament, @match), method: "put", name: "peeris") do %> - <% case @match.status %> +<div id="action"> + <%= form_tag(tournament_match_path(@tournament, @match), method: "put") do %> + <% case @match.status %> <% when 0 %> - <input type="hidden" name="update_action" value="start"> - <%= submit_tag("Start Match") %> - <% when 1 %> - <input type="hidden" name="update_action" value="peer"> - <%= submit_tag("Begin Peer Evaluation") %> - <% when 2 %> - <input type="hidden" name="review_action" value=""> - <input type="hidden" name="update_action" value="finish"> - <%= submit_tag("End Peer Evaluation", :onsubmit => "score_peers()") %> - <% when 3 %> - <input type="hidden" name="update_action" value="reset"> - <%= submit_tag("Reset Status") %> - <% end %> - <% end %> - + <!-- Created, waiting to start --> + <% if @tournament.hosts.include? current_user %> + <input type="hidden" name="update_action" value="start"> + <%= submit_tag("Start Match", :disabled => @match.teams.count < @tournament.min_teams_per_match) %> + <% else %> + <p>Match is waiting to start.</p> + <% end %> + <% when 1 %> + <!-- Started, waiting to finish --> + <% if @tournament.hosts.include? current_user %> + <input type="hidden" name="update_action" value="finish"> + <% @match.teams.each do |team| %> + <fieldset><legend>Team <%= team.id.to_s %></legend> + <% team.users.collect{|u| u.user_name}.each do |k| %><label> + Score for <%= k %><br> + <%= text_field_tag("scores[#{k}]", 0, size: 3) %> + </label><% end %> + </fieldset> + <% end %> + <%= submit_tag("Finish match") %> + <% else %> + <p>The match is running; the host has yet to post the scores of the match.</p> + <% end %> + <% when 2 %> + <!-- Finished, waiting for peer reviews --> + <input type="hidden" name="update_action" value="peer"> + <input type="hidden" name="review_action" value=""> + <% users = []; @match.teams.each{|t| users.concat(t.users)}; %> + <% if users.include? current_user %> + <% @match.teams.each do |team| %> + <% if team.users.include?(current_user) %> + <ol id="boxes" class="sortable"> + <% team.users.collect{|u| u.user_name}.each do |k| %> + <li><%= k%> + <br> + <% if (@tournament.game_id == 1) %> + <%= if @blue2["#{k}"] == nil + "Level: #{@purp2["#{k}"]["level"]} K/D/A: #{@purp2["#{k}"]["championsKilled"]}/#{@purp2["#{k}"]["numDeaths"]}/#{@purp2["#{k}"]["assists"]} Gold:#{@purp2["#{k}"]["goldEarned"]}" + else + "Level: #{@blue2["#{k}"]["level"]} K/D/A: #{@blue2["#{k}"]["championsKilled"]}/#{@blue2["#{k}"]["numDeaths"]}/#{@blue2["#{k}"]["assists"]} Gold:#{@blue2["#{k}"]["goldEarned"]}" + end %> + <% end %> + </li> + <% end %> + </ol> + <% end %> + <% end %> + <%= submit_tag("Submit peer evaluation", :onsubmit => "score_peers()") %> + <% else %> + Waiting for peer evaluations to be submitted. + <% end %> + <% when 3 %> + <!-- Totally done --> + This match is done. + <input type="hidden" name="update_action" value="reset"> + <%= submit_tag("Reset Status") %> + <% end # case %> + <% end # form %> </div> -<% end %> <script type="text/javascript"> +function score_peers() { //get each player in order and assign score here! - var $lisp = $('ol li peeris'); + var $lisp = $('ol#boxes'); var comma = "," for(var i=0; i < $lisp.length; i++) { if ( i == lisp.length-1) { comma = ""; } - $('review_action').value += $('ol li peeris:eq(' + i + ')').text() + comma; + $('review_action').value += $('ol#boxes:eq(' + i + ')').text() + comma; } +} </script> - - |