summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAndrewMurrell <amurrel@purdue.edu>2014-04-06 23:48:54 -0400
committerAndrewMurrell <amurrel@purdue.edu>2014-04-06 23:48:54 -0400
commit15eaa246ae30cc0050fd59a0864b445229464c31 (patch)
tree3b11caffa5e4fcb704ecc7d2c73719077cc9f5af /app
parent4ac5229d216bd6d18a2b6e39bf90f76cbdfbb7c3 (diff)
parent3602d46e95f9a13ec2a8ff0b0909059af64c55ba (diff)
Merge branch 'master' of http://github.com/LukeShu/leaguer
Diffstat (limited to 'app')
-rw-r--r--app/controllers/matches_controller.rb41
-rw-r--r--app/models/match.rb2
-rw-r--r--app/models/user.rb1
-rw-r--r--app/views/matches/show.html.erb77
4 files changed, 103 insertions, 18 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index 5c654dd..f196978 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -147,8 +147,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
@@ -157,17 +157,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 }
@@ -192,4 +216,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| %>
+ <ol>
+ <% team.users.collect{|u| u.user_name}.each do |k| %>
+ <li><%= k %></li>
+ <% end %>
+ </ol>
+ <% end %>
+
<!--
This is what the Players and the Hosts of the tournament will view when the Match Status is 0
-->
-<% 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 %>
+ <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 %>
+ <% 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 %>
-<% end %>
<!--
When Match Status is 2
Players see the Peer Review Page
Host see the Game Status
-->
-<% if (@match.status==0) %>
+<% elsif (@match.status==2) %>
<% if (@tournament.players.include?(current_user)) %>
<% @match.teams.each do |team| %>
- <ol id="boxes" class="sortable">
- <% team.users.collect{|u| u.user_name}.each do |k| %>
- <li><%= k %></li>
- <% end %>
- </ol>
-
+ <% if team.users.include?(current_user) %>
+ <ol id="boxes" class="sortable">
+ <% team.users.collect{|u| u.user_name}.each do |k| %>
+ <li><%= k %></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>
@@ -69,3 +104,23 @@
</p>
<% end %>
+<% if @tournament.hosts.include?(current_user) %>
+<br />
+<div id="host">
+ <%= 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="update_action" value="finish">
+ <%= submit_tag("End Match") %>
+ <% end %>
+ <% end %>
+
+
+</div>
+<% end %>