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 ++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'app/controllers/matches_controller.rb') 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 -- cgit v1.2.3