summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-29 10:53:28 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-29 10:53:28 -0400
commit8aefe73872571ac54738bde71d4da5611659a0cc (patch)
treeadec3a6e180b9baa5e70bc8245056ac2a3e1df37
parent3750da581ea0422bdf3f0d05c373398da5828b12 (diff)
fix match lifecycle
-rw-r--r--app/controllers/matches_controller.rb44
1 files changed, 22 insertions, 22 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index f713dff..dbd3e68 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -18,6 +18,7 @@ class MatchesController < ApplicationController
# PATCH/PUT /tournaments/1/matches/1
# PATCH/PUT /tournaments/1/matches/1.json
def update
+ notice = nil
case @match.status
when 0
# Created, waiting to be scheduled
@@ -26,46 +27,45 @@ class MatchesController < ApplicationController
if (@tournament.hosts.include? current_user) and (params[:update_action] == "start")
@match.status = 2
@match.start_sampling
- respond_to do |format|
- if @match.save
- format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match has started.' }
- format.json { head :no_content }
- else
- format.html { render action: 'show' }
- format.json { render json: @match.errors, status: :unprocessable_entity }
- end
+ if @match.save
+ notice = 'Match has started.'
+ else
+ respond_to do |format|
+ format.html { render action: 'show' }
+ format.json { render json: @match.errors, status: :unprocessable_entity }
+ end
+ return
end
- return
end
when 2
# Started, waiting to finish
@match.handle_sampling(@current_user, params)
# The @match.status will be updated by Statistic's after_save hook
- respond_to do |format|
- format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match has finished.' }
- format.json { head :no_content }
+ if @match.status == 3
+ notice = 'Match has finished'
end
when 3
if (@tournament.hosts.include? current_user) and (params[:update_action] == "start")
ok = true
ActiveRecord::Base.transaction do
- ok &= @match.statitistics.destroy_all
- @match.status = 1
+ ok &= @match.statistics.destroy_all
+ ok &- @match.status = 1
ok &= @match.save
end
- respond_to do |format|
- if @match.save
- format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match has finished.' }
- format.json { head :no_content }
- else
+ if ok
+ notice = "Match has been reset"
+ else
+ respond_to do |format|
format.html { render action: 'show' }
format.json { render json: @match.errors, status: :unprocessable_entity }
end
+ return
end
- return
end
- else
- redirect_to tournament_match_path(@tournament, @match)
+ end
+ respond_to do |format|
+ format.html { redirect_to match_path(@match), notice: notice }
+ format.json { head :no_content }
end
end