单选多选题
This commit is contained in:
parent
32eaaef9fc
commit
f79a40ca65
|
|
@ -49,7 +49,7 @@ class GamesController < ApplicationController
|
|||
@type = params[:type]
|
||||
challenge_path = @game_challenge.path
|
||||
# 用户选项
|
||||
@user_answer = @game.outputs.first.actual_output.split("") unless @st == 0 || @game.outputs.blank?
|
||||
#@user_answer = @game.outputs.first.actual_output.split("") unless @st == 0 || @game.outputs.blank?
|
||||
# 默认打开文件
|
||||
logger.info("repository id is #{@repository.try(:id)}, repository's shixun_id =#{@repository.try(:myshixun_id)} shixun_id =#{@repository.try(:shixun_id)}, project_id => #{@repository.try(:project_id)}")
|
||||
# 验证challenge文件名的合法性
|
||||
|
|
@ -297,52 +297,55 @@ class GamesController < ApplicationController
|
|||
|
||||
# 选择题评测(选择题不需要重新评测)
|
||||
def evaluating_choice
|
||||
@game_challenge = @game.challenge
|
||||
user_answer = params[:answer]
|
||||
correct = true
|
||||
score = 0
|
||||
tag_count = 0
|
||||
if !user_answer.blank?
|
||||
if user_answer.split("").count != @game_challenge.challenge_questions.where(:right_key => true).count
|
||||
correct = false
|
||||
else
|
||||
user_answer.split("").each do |answer|
|
||||
question = @game_challenge.challenge_questions.where(:position => answer.to_i).first
|
||||
unless question.right_key
|
||||
correct = false
|
||||
break
|
||||
|
||||
if false
|
||||
@game_challenge = @game.challenge
|
||||
user_answer = params[:answer]
|
||||
correct = true
|
||||
score = 0
|
||||
tag_count = 0
|
||||
if !user_answer.blank?
|
||||
if user_answer.split("").count != @game_challenge.challenge_questions.where(:right_key => true).count
|
||||
correct = false
|
||||
else
|
||||
user_answer.split("").each do |answer|
|
||||
question = @game_challenge.challenge_questions.where(:position => answer.to_i).first
|
||||
unless question.right_key
|
||||
correct = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
correct = false
|
||||
end
|
||||
else
|
||||
correct = false
|
||||
end
|
||||
@game.update_attributes(:status => 2, :end_time => Time.now)
|
||||
had_done = @game.had_done
|
||||
shixun = @myshixun.shixun
|
||||
if shixun.status > 1 && !@game.answer_open
|
||||
if correct
|
||||
#User.current.update_attributes(:grade => (User.current.grade + @game.challenge.score), :experience => (User.current.experience + @game.challenge.score))
|
||||
reward_grade(@game.user, @game.id, 'Game', @game_challenge.score)
|
||||
reward_experience(@game.user, @game.id, 'Game', @game_challenge.score)
|
||||
@game.update_attribute(:final_score, @game_challenge.score)
|
||||
score = @game_challenge.score
|
||||
tag_count = @game_challenge.challenge_tags.count
|
||||
@game.update_attributes(:status => 2, :end_time => Time.now)
|
||||
had_done = @game.had_done
|
||||
shixun = @myshixun.shixun
|
||||
if shixun.status > 1 && !@game.answer_open
|
||||
if correct
|
||||
#User.current.update_attributes(:grade => (User.current.grade + @game.challenge.score), :experience => (User.current.experience + @game.challenge.score))
|
||||
reward_grade(@game.user, @game.id, 'Game', @game_challenge.score)
|
||||
reward_experience(@game.user, @game.id, 'Game', @game_challenge.score)
|
||||
@game.update_attribute(:final_score, @game_challenge.score)
|
||||
score = @game_challenge.score
|
||||
tag_count = @game_challenge.challenge_tags.count
|
||||
else
|
||||
score = "+0"
|
||||
tag_count = 0
|
||||
end
|
||||
elsif shixun.status > 1 && @game.answer_open
|
||||
score = -@game_challenge.score.to_i
|
||||
tag_count = 0
|
||||
else
|
||||
score = "+0"
|
||||
tag_count = 0
|
||||
end
|
||||
elsif shixun.status > 1 && @game.answer_open
|
||||
score = -@game_challenge.score.to_i
|
||||
tag_count = 0
|
||||
else
|
||||
score = "+0"
|
||||
tag_count = 0
|
||||
if @game.outputs.blank?
|
||||
Output.create(:game_id => @game.id, :actual_output => user_answer, :result => correct)
|
||||
end
|
||||
render :json => {correct: correct, had_done: had_done, :grade => User.where(:id => User.current.id).first.grade, score: score, tag_count: tag_count}
|
||||
end
|
||||
if @game.outputs.blank?
|
||||
Output.create(:game_id => @game.id, :actual_output => user_answer, :result => correct)
|
||||
end
|
||||
render :json => {correct: correct, had_done: had_done, :grade => User.where(:id => User.current.id).first.grade, score: score, tag_count: tag_count}
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class ChallengeChoose < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
# type 1 单选, 2,多选
|
||||
# category 1 单选, 2,多选
|
||||
# standard_answer 正确答案 answer: 答题的思路
|
||||
default_scope :order => 'position'
|
||||
belongs_to :challenge
|
||||
|
|
|
|||
|
|
@ -1,37 +1,106 @@
|
|||
<!-- 编程题 -->
|
||||
<div class="-layout -stretch -fit -vertical centerH">
|
||||
<div class="-layout -vertical -flex -relative -bg-black -flex-basic70" id="games_repository_contents" style="overflow:hidden;">
|
||||
<ul id="blacktab_nav">
|
||||
<li id="codetab_nav_1" class="blacktab_hover" onclick="HoverLi_new(1);">
|
||||
<a href="javascript:void(0);" class="tab_type tab_color" >答题</a>
|
||||
</li>
|
||||
<div class="fr mt5 -horizontal mr15">
|
||||
<a href="javascript:void(0);" onclick="repository_extend_and_zoom();" id="extend_and_zoom"><i class="fa fa-expand font-16"></i></a>
|
||||
</div>
|
||||
</ul>
|
||||
<div class="cl"></div>
|
||||
<div id="codotab_con_1" class="white_bg" style="overflow-y: auto;height: 100%">
|
||||
<div class="panel-header clearfix" id="top_repository" style="border-bottom:0;padding:15px;">
|
||||
<% @game_challenge.challenge_chooses.each_with_index do |choose, index| %>
|
||||
<p class="font-bd font-18 color-grey3"><%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %></p>
|
||||
<div class="font-15 color-grey3 mb10 new_li read_only" unselectable="on" id="choose_subject_<%= index + 1 %>">
|
||||
<textarea style="display:none;"><%= choose.subject %></textarea>
|
||||
</div>
|
||||
<% choose.challenge_questions.each_with_index do |question, i| %>
|
||||
<pre class="mb10 back-f6-grey"></pre>
|
||||
<div class="pl5 pr5 pt10 pb10 bor-grey-e">
|
||||
<div for="result_<%= question.position %>" class="card -elevation-1 mt10 mb5 <%= (@user_answer.nil? || @user_answer.index(i.to_s).nil?) ? "" : "card-check color_white" %>" onclick="">
|
||||
<!--单选-->
|
||||
<% if choose.category == 1 %>
|
||||
<input type="radio" name="answer[]" value="<%= (question.position + 65).chr %>" id="result_<%= question.position %>" class="ml-3 mr5 magic-radio ml5">
|
||||
<% else %>
|
||||
<!--多选-->
|
||||
<input type="checkbox" name="answer[]" value="<%= (question.position + 65).chr %>" id="result_<%= question.position %>" class="ml-3 mr5 magic-checkbox ml5">
|
||||
<% end %>
|
||||
<div class="-layout-h -center break_word">
|
||||
<span class="mr10"><%= (question.position + 65).chr %>.</span>
|
||||
<div class="markdown">
|
||||
<p><code class="font-16"><%= question.option_name %></code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<h3 id="save_status" class="ml15 fl" style="font-weight: normal"></h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--拖拽增加结构---------------------------------------->
|
||||
<div class="h-center">
|
||||
<div class="-changebg -bg-black" id="-bg-change-color"></div>
|
||||
</div>
|
||||
<!------------------------------------------------------>
|
||||
<div class="split-panel--second -layout -vertical -flex -relative -bg-black -flex-basic60" id="games_valuation_contents">
|
||||
<%= render :partial => 'games/game_choose_results' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
editormd.loadKaTeX(function() {
|
||||
var lens = $("#top_repository .read_only").length;
|
||||
for(i = 1; i <= lens; i++){
|
||||
editormd.markdownToHTML("choose_subject_" + i, {
|
||||
htmlDecode: "style,script,iframe", // you can filter tags decode
|
||||
taskList: true,
|
||||
tex: true, // 数学公式
|
||||
flowChart: true, // 默认不解析
|
||||
sequenceDiagram: true // 默认不解析
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<% if false %>
|
||||
<div class="-layout -stretch -fit -vertical centerH">
|
||||
<div class="split-panel--second -layout -vertical -flex -relative -bg-black" id="answer">
|
||||
<ul id="blacktab_nav">
|
||||
<li id="codetab_nav_1" class="blacktab_hover" onclick="HoverLi_new(1);">
|
||||
<a href="javascript:void(0);" class="tab_type tab_color" >答题选项</a>
|
||||
<a href="javascript:void(0);" class="tab_type tab_color" >答题</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="cl"></div>
|
||||
<div id="codotab_con_1" class="white_bg" style="overflow-y: auto;height: 100%">
|
||||
<div class="panel-header clearfix" id="top_repository" style="border-bottom:0;padding:15px;">
|
||||
<p class="mb10 color-light-green font-16 <%= @game.outputs.blank? || !@game.outputs.first.result ? "undis" : "" %>" id="correct_tip">
|
||||
<i class="fa fa-check-circle font-16"></i> 正确
|
||||
</p>
|
||||
<p class="mb10 color-red font-16 <%= @game.outputs.blank? || @game.outputs.first.result ? "undis" : "" %>" id="error_tip">
|
||||
<i class="fa fa-exclamation-circle font-16"></i> 错误
|
||||
</p>
|
||||
<p class="font-bd font-18 color-grey3">1.单选题</p>
|
||||
<p class="font-15 color-grey3 mb10">应在下列程序划线处填入的语句是()</p>
|
||||
<pre class="mb10 back-f6-grey"></pre>
|
||||
<div class="pl5 pr5 pt10 pb10 bor-grey-e">
|
||||
<% @game_challenge.challenge_questions.each_with_index do |question, i| %>
|
||||
<div for="result_<%= question.position %>" class="card -elevation-1 mt10 mb5 <%= (@user_answer.nil? || @user_answer.index(i.to_s).nil?) ? "" : "card-check color_white" %>" onclick="choice_answer('<%= @st %>', this)">
|
||||
<!--单选-->
|
||||
<input type="radio" name="answer[]" value="<%= question.position %>" id="result_<%= question.position %>" class="ml-3 mr5 magic-radio ml5">
|
||||
<!--多选-->
|
||||
<input type="checkbox" name="answer[]" value="<%= question.position %>" id="result_<%= question.position %>" class="ml-3 mr5 magic-checkbox ml5">
|
||||
<input type="hidden" name="answer" value="<%= question.position %>">
|
||||
<div class="-layout-h -center break_word">
|
||||
<span class="mr10"><%= (question.position + 65).chr %>.</span>
|
||||
<div class="markdown">
|
||||
<p><code class="font-16"><%= question.option_name %></code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% @game_challenge.challenge_chooses.each do |choose| %>
|
||||
<% choose.challenge_questions.each_with_index do |question, i| %>
|
||||
<div for="result_<%= question.position %>" class="card -elevation-1 mt10 mb5 <%= (@user_answer.nil? || @user_answer.index(i.to_s).nil?) ? "" : "card-check color_white" %>" onclick="choice_answer('<%= @st %>', this)">
|
||||
<!--单选-->
|
||||
<input type="radio" name="answer[]" value="<%= question.position %>" id="result_<%= question.position %>" class="ml-3 mr5 magic-radio ml5">
|
||||
<!--多选-->
|
||||
<input type="checkbox" name="answer[]" value="<%= question.position %>" id="result_<%= question.position %>" class="ml-3 mr5 magic-checkbox ml5">
|
||||
<input type="hidden" name="answer" value="<%= question.position %>">
|
||||
<div class="-layout-h -center break_word">
|
||||
<span class="mr10"><%= (question.position + 65).chr %>.</span>
|
||||
<div class="markdown">
|
||||
<p><code class="font-16"><%= question.option_name %></code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
<h3 id="save_status" class="ml15 fl" style="font-weight: normal"></h3>
|
||||
|
|
@ -39,3 +108,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<%= content_for(:header_tags) do %>
|
||||
<%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %>
|
||||
<% end %>
|
||||
<ul id="blacktab_nav">
|
||||
<li class="blacktab_con blacktab_hover">
|
||||
<a href="javascript:void(0);" class="tab_type tab_color">测试结果</a>
|
||||
</li>
|
||||
<a href="javascript:void(0);" onclick="valuation_extend_and_zoom();" id="valuation_extend_and_zoom"><i class="fa fa-expand font-16 color-grey fr mt10 mr15 fa-arrows-alt" ></i></a>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
<div class="cl"></div>
|
||||
<div id="game_test_set_results" class="-flex -relative blacktab-inner">
|
||||
<div id="blacktab_con_1" class="" >
|
||||
<div class="fit -scroll">
|
||||
<div class="-layout-v -fit">
|
||||
<div class="-flex -scroll task-padding16">
|
||||
<p class="-text-danger mb10">
|
||||
<i class="fa fa-exclamation-circle font-16" ></i><span class="ml5 mr5 -text-danger">3/5</span>
|
||||
</p>
|
||||
<p class="color-light-green mb10">
|
||||
<i class="fa fa-check-circle font-16" ></i><span class="ml5 mr5">5/5</span> 全部通过
|
||||
</p>
|
||||
<% @game_challenge.challenge_chooses.each_with_index do |choose, index| %>
|
||||
<div class="-task-ces-box mb15 clearfix">
|
||||
<div class="-task-ces-top" onclick="toggle_test_case('0', '<%= index %>')" style="cursor:pointer">
|
||||
<i class="fa fa-caret-right mr5 font-16" ></i>
|
||||
<span class="font-14">题目<%= index + 1 %></span>
|
||||
<i class="fa fa-exclamation-circle -text-danger fr mt8 ml5" ></i>
|
||||
<i class="fa fa-check-circle color-light-green fr mt8 ml5 f14" ></i>
|
||||
<i class="fa fa-lock fr mt8" ></i>
|
||||
</div>
|
||||
<div class="-task-ces-info undis" id="test_case_<%= index %>">
|
||||
<ul class=" font-14">
|
||||
<li><span class="-task-ces-info-left color-blue">正确选项:</span><span><%= choose.standard_answer %></span></li>
|
||||
<li><span class="-task-ces-info-left color-blue">你的选项:</span><span class="color-orange">789</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -92,7 +92,7 @@
|
|||
<% if @st != 0 %>
|
||||
<!-- 单选多选题 -->
|
||||
<%= render :partial => "games/choice_question" %>
|
||||
<% else %>
|
||||
<% else %>
|
||||
<!-- 编程题 -->
|
||||
<div class="-layout -stretch -fit -vertical centerH">
|
||||
<div class="-layout -vertical -flex -relative -bg-black -flex-basic70" id="games_repository_contents" style="overflow:hidden;">
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<%= favicon %>
|
||||
<%= javascript_heads %>
|
||||
<%= heads_for_theme %>
|
||||
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/font-awesome','css/taskstyle', 'css/project','css/popup','repository','css/gantt','css/cssPlus-v.0.2-build', 'css/edu-common','css/edu-public', 'css/edu-popup', 'css/edu-tooltipster' %>
|
||||
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/font-awesome','css/taskstyle', 'css/project','css/popup','repository','css/gantt','css/cssPlus-v.0.2-build', 'css/edu-common','css/edu-public', 'css/edu-popup', 'css/edu-tooltipster', 'css/magic-check' %>
|
||||
<%= javascript_include_tag 'edu/application', 'edu/edu_tpi' %>
|
||||
<%= call_hook :view_layouts_base_html_head %>
|
||||
<!-- page specific tags -->
|
||||
|
|
|
|||
|
|
@ -143,11 +143,11 @@ function open_answer(game, myshixun){
|
|||
|
||||
// 选择题选择答案
|
||||
function choice_answer(st, nThis){
|
||||
if(st == "1"){
|
||||
if(st == "2"){
|
||||
//$(nThis).hasClass("card-check") ? $(nThis).removeClass("card-check") : $(nThis).addClass("card-check");
|
||||
$(nThis).toggleClass("card-check");
|
||||
$(nThis).toggleClass("color_white");
|
||||
} else if (st == "2"){
|
||||
} else if (st == "1"){
|
||||
var choice = $(".color_white");
|
||||
choice.removeClass("card-check");
|
||||
choice.removeClass("color_white");
|
||||
|
|
|
|||
Loading…
Reference in New Issue