From 328e7236a9c49de54eb830aef8abe491720e88bc Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 30 Aug 2017 17:30:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=B7=B3=E5=85=B3=E6=89=93?= =?UTF-8?q?=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 4 +- app/helpers/application_helper.rb | 12 +++ app/models/game.rb | 5 + app/views/games/_code_actions.html.erb | 23 ++-- app/views/games/_game_results.html.erb | 143 +------------------------ 5 files changed, 33 insertions(+), 154 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index d6b9d3c7f..941806f25 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -359,7 +359,9 @@ class GamesController < ApplicationController # 自动推送下一个任务 def next_step - render_403 if @game.status != 2 + unless show_next_stage?(@game, @myshixun.shixun.try(:status)) + render_403 + end next_game = @game.next_game next_game.update_attributes(:status => 0, :open_time => Time.now) if next_game.status == 3 respond_to do |format| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index eae04490a..25fa1425b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,18 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + # 定义当前关卡是否有权开启下一关 + # :实训若发布了,必须通过当前关卡才能查看下一关 + # :未发布的实训,除了最后一关,其它的关卡都可以进入下一关 + def show_next_stage?(game, shixun_status) + if game.is_final_game? || ([2,3].include?(shixun_status.to_i) && game.try(:statu) != 2) + false + else + true + end + end + + # 适用与已经用url_safe编码后,回调字符串形式 def tran_base64_decode64 str if str.blank? diff --git a/app/models/game.rb b/app/models/game.rb index 4b97fbbde..03d1d58ae 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -52,4 +52,9 @@ class Game < ActiveRecord::Base output = outputs.blank? ? nil : outputs.first return output end + + def is_final_game? + challenge = self.challenge + challenge.try(:position).to_i == challenge.shixun.challenges.count ? true : false + end end diff --git a/app/views/games/_code_actions.html.erb b/app/views/games/_code_actions.html.erb index 8a259de90..7588fb86a 100644 --- a/app/views/games/_code_actions.html.erb +++ b/app/views/games/_code_actions.html.erb @@ -14,23 +14,20 @@
<% if @game.status == 1 %> 评测中.. - <% elsif @game.status == 2 %> + <% end %> + <% if show_next_stage?(@game, @myshixun.shixun.try(:status)) %> <% if @had_done == 0 %> - <%= link_to "下一关 ", {:controller => 'games', - :action => "next_step", :id => @game, - :myshixun_id => @myshixun}, - :class => "shixun-task-btn task-btn-blue mr15 mt8", - :id => "next_step", - :remote => true %> + <%= link_to "下一关 ", {:controller => 'games', :action => "next_step", :id => @game, :myshixun_id => @myshixun}, + :class => "shixun-task-btn task-btn-blue mr15 mt8", :id => "next_step", :remote => true %> <% else %> - 退出实训 + 退出实训 <% end %> <% end %>
- \ No newline at end of file