summaryrefslogtreecommitdiff
path: root/app/controllers/matches_controller.rb
diff options
context:
space:
mode:
authorguntasgrewal <guntasgrewal@gmail.com>2014-04-06 23:29:40 -0400
committerguntasgrewal <guntasgrewal@gmail.com>2014-04-06 23:29:40 -0400
commit2d097c71a32646fce3b90608cbffde9992c979ef (patch)
tree83c8fd34674d789a14f0ce5dc92655deeaaacf4a /app/controllers/matches_controller.rb
parent628173fce3de8f5d3e31109b3aa7c964fdab38ca (diff)
holy shit matches actually move forward
Diffstat (limited to 'app/controllers/matches_controller.rb')
-rw-r--r--app/controllers/matches_controller.rb41
1 files changed, 35 insertions, 6 deletions
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