diff options
author | AndrewMurrell <amurrel@purdue.edu> | 2014-04-06 23:48:54 -0400 |
---|---|---|
committer | AndrewMurrell <amurrel@purdue.edu> | 2014-04-06 23:48:54 -0400 |
commit | 15eaa246ae30cc0050fd59a0864b445229464c31 (patch) | |
tree | 3b11caffa5e4fcb704ecc7d2c73719077cc9f5af /app/controllers | |
parent | 4ac5229d216bd6d18a2b6e39bf90f76cbdfbb7c3 (diff) | |
parent | 3602d46e95f9a13ec2a8ff0b0909059af64c55ba (diff) |
Merge branch 'master' of http://github.com/LukeShu/leaguer
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/matches_controller.rb | 41 |
1 files changed, 35 insertions, 6 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 |