Merge branch 'dev_shixun_project' of https://git.trustie.net/jacknudt/trustieforge into dev_shixun_project
This commit is contained in:
commit
6a9d635572
|
@ -6,6 +6,7 @@ class ChallengesController < ApplicationController
|
|||
before_filter :build_challege_from_params, :only => [:new, :create]
|
||||
before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :show, :edit, :new, :create]
|
||||
before_filter :query_challeges, :only => [:show, :edit, :update]
|
||||
before_filter :find_language, :only => [:show, :new, :edit]
|
||||
|
||||
include ApplicationHelper
|
||||
|
||||
|
@ -204,4 +205,9 @@ class ChallengesController < ApplicationController
|
|||
render_404
|
||||
end
|
||||
|
||||
def find_language
|
||||
language = @shixun.language
|
||||
@language = language_switch language
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ class GamesController < ApplicationController
|
|||
before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, :game_status, :change_status]
|
||||
before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update]
|
||||
before_filter :allowd_manager
|
||||
before_filter :allowd_view, :only => [:show, :game_build, :next_step, :change_status, :file_update]
|
||||
include ApplicationHelper
|
||||
|
||||
def index
|
||||
|
@ -26,6 +27,8 @@ class GamesController < ApplicationController
|
|||
@rev = @rev.nil? ? "master" : @rev
|
||||
@git_url = git_repository_url(@myshixun, "Myshixun")
|
||||
@type = params[:type]
|
||||
language = @shixun.myshixuns.try(:language)
|
||||
@language = language_switch(language)
|
||||
# 默认打开文件
|
||||
if @path == "" && !game_path.nil? && !@repository.cat(game_path, @rev).blank? && @type != "root"
|
||||
@path = game_path
|
||||
|
@ -209,6 +212,11 @@ class GamesController < ApplicationController
|
|||
render_403 unless (User.current.manager_of_myshixun?(@myshixun) || User.current.admin? || User.current.id == @myshixun.shixun.try(:user_id))
|
||||
end
|
||||
|
||||
# 判断成员是否允许查看
|
||||
def allowd_view
|
||||
render_403 if @game.status == 3
|
||||
end
|
||||
|
||||
# Find myshixun of id params[:id]
|
||||
def find_myshixun
|
||||
myshixun_id = params[:myshixun_id] || (params[:game] && params[:game][:myshixun_id])
|
||||
|
|
|
@ -33,6 +33,21 @@ module ApplicationHelper
|
|||
extend Forwardable
|
||||
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
|
||||
|
||||
# codeMirror语言转换
|
||||
def language_switch language
|
||||
case language
|
||||
when "Java"
|
||||
"text/c-java"
|
||||
when "C"
|
||||
"text/x-csrc"
|
||||
when "C++"
|
||||
"text/x-c++src"
|
||||
when "Python"
|
||||
"text/x-python"
|
||||
when "Ruby"
|
||||
"text/x-ruby"
|
||||
end
|
||||
end
|
||||
|
||||
# 定义实训相关方法
|
||||
# myshixun 最高分
|
||||
|
@ -94,7 +109,11 @@ module ApplicationHelper
|
|||
min = time % (24*60*60) % (60*60) / 60
|
||||
if day < 1
|
||||
if hour < 1
|
||||
time = "#{min} 分钟"
|
||||
if time < 1
|
||||
time = time == 0 ? "--" : "小于1分钟"
|
||||
else
|
||||
time = "#{min} 分钟"
|
||||
end
|
||||
else
|
||||
time = "#{hour}小时 : #{min}分"
|
||||
end
|
||||
|
@ -104,9 +123,13 @@ module ApplicationHelper
|
|||
return time
|
||||
end
|
||||
|
||||
def avg_spend_time shixun_id, position
|
||||
Game.find_by_sql("SELECT avg(g.updated_at - g.created_at) as avg_time FROM `games` g, `challenges` c where c.id=g.challenge_id and g.status =2 and c.position = #{position} and g.myshixun_id in (SELECT id FROM `myshixuns` where shixun_id= #{shixun_id});").first.try(:avg_time).to_i
|
||||
end
|
||||
|
||||
# 已闯关
|
||||
def had_pass myshixun
|
||||
Game.find_by_sql("SELECT * FROM `games` where status =2 and myshixun_id in (SELECT id FROM `myshixuns` where parent_id=#{myshixun.parent_id});").count
|
||||
def had_pass shixun_id, position
|
||||
Game.find_by_sql("SELECT count(*) as count FROM `games` g, `challenges` c where c.id=g.challenge_id and g.status =2 and c.position =#{position} and g.myshixun_id in (SELECT id FROM `myshixuns` where shixun_id=#{shixun_id});").first.try(:count)
|
||||
end
|
||||
|
||||
# 单个game测评次数
|
||||
|
|
|
@ -272,7 +272,7 @@
|
|||
}
|
||||
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("challenge_answer"), {
|
||||
mode: {name: 'text/x-java',
|
||||
mode: {name: 'text/x-<%= @language %>',
|
||||
version: 2,
|
||||
singleLineStringErrors: false},
|
||||
lineNumbers: true,
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
var editor_CodeMirror = CodeMirror.fromTextArea(document.getElementById("challenge-answer-edit-small"), {
|
||||
mode: {name: 'text/x-ruby',
|
||||
mode: {name: 'text/x-<%= @language %>',
|
||||
version: 2,
|
||||
singleLineStringErrors: false},
|
||||
lineNumbers: true,
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
var myMirror = $("#game_answer_show")[0];
|
||||
var myCodeMirror = CodeMirror(myMirror, {
|
||||
value: $("#hidden_game_answer").text(),
|
||||
mode: "text/x-java",
|
||||
mode: "text/x-<%= @language %>",
|
||||
readOnly: "nocursor", //只读
|
||||
//cursorBlinkRate: -1, //隐藏光标
|
||||
autofocus: true,
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
<h4 class=" panel-inner-title "><i class="fa fa-dot-circle-o font-18 color-green mr5"></i><span class="color-red">第<%= game.challenge.try(:position) %>关</span>
|
||||
<%= link_to game.challenge.try(:subject), myshixun_game_path(game, :myshixun_id => @myshixun), :remote => true %></h4>
|
||||
<p class="ml15 mt15 color-grey">
|
||||
<span class=" mr10">已闯关:<%= had_pass(@myshixun) %>人</span>
|
||||
<span class=" mr10">平均耗时:0小时28分</span>
|
||||
<span class=" mr10">已闯关:<%= had_pass(@myshixun.shixun_id, game.challenge.try(:position)) %>人</span>
|
||||
<span class=" mr10">平均耗时:<%= game_spend_time(avg_spend_time(@myshixun.shixun_id, game.challenge.try(:position)), 0) %></span>
|
||||
</p>
|
||||
</div>
|
||||
<a href="#" class=" task-btn task-btn-green fr">马上开启</a>
|
||||
|
@ -22,8 +22,8 @@
|
|||
<h4 class=" panel-inner-title "><i class="fa fa-dot-circle-o font-18 color-green mr5"></i><span class="color-red">第<%= game.challenge.try(:position) %>关</span>
|
||||
<%= game.challenge.try(:subject) %></h4>
|
||||
<p class="ml15 mt15 color-grey">
|
||||
<span class=" mr10">已闯关:<%#= had_pass(@myshixun) %>人</span>
|
||||
<span class=" mr10">平均耗时:0小时28分</span>
|
||||
<span class=" mr10">已闯关:<%= had_pass(@myshixun.shixun_id, game.challenge.try(:position)) %>人</span>
|
||||
<span class=" mr10">平均耗时:<%= game_spend_time(avg_spend_time(@myshixun.shixun_id, game.challenge.try(:position)), 0) %></span>
|
||||
</p>
|
||||
</div>
|
||||
<a href="#" class=" fr link-color-green">正在解决中</a>
|
||||
|
@ -31,22 +31,22 @@
|
|||
<% elsif game.status == 2 %>
|
||||
<h4 class="fl panel-inner-title "><i class="fa fa-check-circle font-18 color-green mr5"></i><span class="color-red">第<%= game.challenge.try(:position) %>关</span>
|
||||
<%= link_to game.challenge.try(:subject), myshixun_game_path(game, :myshixun_id => @myshixun), :remote => true %></h4>
|
||||
<p class="fr "><i class="fa fa-trophy color-yellow font-16 mr5 "></i><span class=" color-grey">NO.120</span></p>
|
||||
<!--<p class="fr "><i class="fa fa-trophy color-yellow font-16 mr5 "></i><span class=" color-grey">NO.120</span></p>-->
|
||||
<div class="cl"></div>
|
||||
<p class="ml15 mt15 color-grey">
|
||||
<span class=" mr10">开始时间:<%= format_time(game.created_at) %></span>
|
||||
<span class=" mr10">完成时间:<%= format_time(game.updated_at) %></span>
|
||||
<span class=" mr10">耗时:<%#= game_avg_hour(game.created_at, game.updated_at) %>小时<%= game_avg_min(game.created_at, game.updated_at) %>分</span>
|
||||
<span class=" mr10">测评次数:<%#= avg_my_pass game %>次</span>
|
||||
<span class=" mr10">得分:<%#= game.final_score %>分</span>
|
||||
<span class=" mr10">耗时:<%= game_spend_time(game.created_at, game.updated_at) %>分</span>
|
||||
<span class=" mr10">已闯关:<%= had_pass(@myshixun.shixun_id, game.challenge.try(:position)) %>人</span>
|
||||
<span class=" mr10">得分:<%= game.final_score %>分</span>
|
||||
</p>
|
||||
<% elsif game.status == 3 %>
|
||||
<div class="fl">
|
||||
<h4 class=" panel-inner-title "><i class="fa fa-lock font-18 color-grey mr5"></i><span class="color-red">第<%= game.challenge.try(:position) %>关</span>
|
||||
<%= game.challenge.try(:subject) %></h4>
|
||||
<p class="ml15 mt15 color-grey">
|
||||
<span class=" mr10">已闯关:<%#= had_pass(@myshixun) %>人</span>
|
||||
<span class=" mr10">平均耗时:0小时28分</span>
|
||||
<span class=" mr10">已闯关:<%= had_pass(@myshixun.shixun_id, game.challenge.try(:position)) %>人</span>
|
||||
<span class=" mr10">平均耗时:<%= game_spend_time(avg_spend_time(@myshixun.shixun_id, game.challenge.try(:position)), 0) %></span>
|
||||
</p>
|
||||
</div>
|
||||
<a href="#" class=" task-btn fr"> 已锁定 </a>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<!--<li><i class="fa fa-signal font-14 mr5"></i>排名:<a href="#" class="">123</a></li>-->
|
||||
<li><i class="fa fa-trophy font-14 mr5"></i>积分:<%= shixun_final_score(@myshixun) %></li>
|
||||
<% if (Time.now - @game.created_at) > 60 %>
|
||||
<li><i class="fa fa-clock-o font-14 mr5"></i>耗时:<%= @game.status == 2 ? game_spend_time(@game.created_at, Time.now) : game_spend_time(@game.created_at, @game.updated_at) %></li>
|
||||
<li><i class="fa fa-clock-o font-14 mr5"></i>耗时:<%= @game.status != 2 ? game_spend_time(@game.created_at, Time.now) : game_spend_time(@game.created_at, @game.updated_at) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue