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
---
Gemfile | 1 +
app/controllers/matches_controller.rb | 41 ++++++++++++++++---
app/models/match.rb | 2 +-
app/models/user.rb | 1 +
app/views/matches/show.html.erb | 77 ++++++++++++++++++++++++++++++-----
config/routes.rb | 2 +-
6 files changed, 105 insertions(+), 19 deletions(-)
diff --git a/Gemfile b/Gemfile
index c33683a..bb38ab5 100644
--- a/Gemfile
+++ b/Gemfile
@@ -67,3 +67,4 @@ end
# Use debugger
# gem 'debugger', group: [:development, :test]
+#gem 'byebug'
\ No newline at end of file
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| %>
+ <%= k %>
+ <% 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| %>
+ Score for <%= k %>
+
+ <%= text_field_tag("scores[#{k}]", 0, size: 3) %>
+
+ <% 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| %>
<%= k %>
<% end %>
- <% end %>
+ <% end %>
+ <% else %>
+ <% @match.teams.each do |team| %>
+
+ <% team.users.each do |user| %>
+ <%= user.user_name %> - SCORE: <%= @scores.select{|s| s.user == user}.first.value %>
+ <% 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| %>
- <%= k %>
- <% end %>
-
-
+ <% if team.users.include?(current_user) %>
+
+ <% team.users.collect{|u| u.user_name}.each do |k| %>
+ <%= k %>
+ <% end %>
+
+ <% end %>
<% end %>
<% elsif (@tournament.hosts.include?(current_user)) %>
Game Status Page Goes here! Because you are a Host that is not a player!
@@ -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 %>
diff --git a/config/routes.rb b/config/routes.rb
index 3a23a68..fb92118 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -15,7 +15,7 @@ Leaguer::Application.routes.draw do
resources :teams
resources :tournaments do
- resources :matches, only: [:index, :show]
+ resources :matches, only: [:index, :show, :update]
end
root to: 'static#homepage'
--
cgit v1.2.3-2-g168b