From 2d097c71a32646fce3b90608cbffde9992c979ef Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Sun, 6 Apr 2014 23:29:40 -0400 Subject: holy shit matches actually move forward --- app/controllers/matches_controller.rb | 41 ++++++++++++++++--- app/models/match.rb | 2 +- app/models/user.rb | 1 + app/views/matches/show.html.erb | 77 ++++++++++++++++++++++++++++++----- 4 files changed, 103 insertions(+), 18 deletions(-) (limited to 'app') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index ee68e11..8ef5e76 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -143,8 +143,8 @@ class MatchesController < ApplicationController handle_asynchronously :is_match_over def show - if @match.id == 1 - is_match_over + if (@match.status == 1) + @scores = @match.scores end @@ -153,17 +153,41 @@ class MatchesController < ApplicationController def update case params[:update_action] when "start" - check_permission(:edit, @tournament) - status = 1 + @match.status = 1 respond_to do |format| - if @match - format.html { redirect_to tournament_match_path(@tournament, self), notice: 'Match has started.' } + if @match.save + format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match has started.' } 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 "score" + 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 + respond_to do |format| + if @match.save + format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Peer evaluation started.' } + 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 "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 else respond_to do |format| format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity } @@ -188,4 +212,9 @@ class MatchesController < ApplicationController def match_params params.require(:match).permit(:status, :tournament_id, :name, :winner_id, :remote_id) end + + # Turn of check_edit, since our #update is flexible + def check_edit + set_match + end end diff --git a/app/models/match.rb b/app/models/match.rb index c596ced..48d6b83 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,6 +1,6 @@ class Match < ActiveRecord::Base belongs_to :tournament - + has_many :scores has_and_belongs_to_many :teams belongs_to :winner, class_name: "Team" diff --git a/app/models/user.rb b/app/models/user.rb index 0b77ab1..0446b35 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,6 +3,7 @@ class User < ActiveRecord::Base has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", foreign_key: "host_id", join_table: "hosts_tournaments" has_and_belongs_to_many :teams has_many :sessions + has_many :scores apply_simple_captcha diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 25be7b8..109aa70 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -26,36 +26,71 @@ Note:- The change of status from 1 to 2 is coming from League Data Pull (RIOT API) --> +<% if (@match.status== 0) || !@tournament.players.include?(current_user) %> + <% @match.teams.each do |team| %> +
    + <% team.users.collect{|u| u.user_name}.each do |k| %> +
  1. <%= k %>
  2. + <% end %> +
+ <% end %> + -<% if (@match.status==1) %> - <% if (@tournament.players.include?(current_user) || @tournament.hosts.include?(current_user)) %> +<% elsif (@match.status==1) %> + <% if @tournament.hosts.include?(current_user) && @scores.empty? %> + <%= form_tag(tournament_match_path(@tournament, @match), method: "put") do %> + + <% @match.teams.each do |team| %> +
Team <%= team.id.to_s %> + <% team.users.collect{|u| u.user_name}.each do |k| %> + + <% end %> +
+ <% end %> + <%= submit_tag("Enter Scores") %> + <% end %> + <% else %> + <% if @scores.empty? %> +

The host has yet to post the scores of the match

<% @match.teams.each do |team| %>
    <% team.users.collect{|u| u.user_name}.each do |k| %>
  1. <%= k %>
  2. <% end %>
- <% end %> + <% end %> + <% else %> + <% @match.teams.each do |team| %> +
    + <% team.users.each do |user| %> +
  1. <%= user.user_name %> - SCORE: <%= @scores.select{|s| s.user == user}.first.value %>
  2. + <% end %> +
+ <% end %> + <% end %> <% end %> -<% end %> -<% if (@match.status==0) %> +<% elsif (@match.status==2) %> <% if (@tournament.players.include?(current_user)) %> <% @match.teams.each do |team| %> -
    - <% team.users.collect{|u| u.user_name}.each do |k| %> -
  1. <%= k %>
  2. - <% end %> -
- + <% if team.users.include?(current_user) %> +
    + <% team.users.collect{|u| u.user_name}.each do |k| %> +
  1. <%= k %>
  2. + <% end %> +
+ <% end %> <% end %> <% elsif (@tournament.hosts.include?(current_user)) %> @@ -69,3 +104,23 @@

<% end %> +<% if @tournament.hosts.include?(current_user) %> +
+
+ <%= form_tag(tournament_match_path(@tournament, @match), method: "put") do %> + <% case @match.status %> + <% when 0 %> + + <%= submit_tag("Start Match") %> + <% when 1 %> + + <%= submit_tag("Begin Peer Evaluation") %> + <% when 2 %> + + <%= submit_tag("End Match") %> + <% end %> + <% end %> + + +
+<% end %> -- cgit v1.2.3