项目实训的阶段内容划分5个tab进行编辑

This commit is contained in:
daiao 2017-07-20 16:25:44 +08:00
parent 3aa8f4344e
commit c1933b5608
17 changed files with 893 additions and 20 deletions

View File

@ -2,12 +2,12 @@
class ChallengesController < ApplicationController
layout "base_shixun"
before_filter :check_authentication
before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build]
before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy]
before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation]
before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation]
before_filter :build_challege_from_params, :only => [:new, :create]
before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :edit, :new, :create]
before_filter :allowed_view, :only => [:show]
before_filter :query_challeges, :only => [:show, :edit, :update]
before_filter :query_challeges, :only => [:show, :edit, :update, :update_evaluation]
before_filter :find_shixun_language, :only => [:show, :new, :edit]
include ApplicationHelper
@ -26,6 +26,13 @@ class ChallengesController < ApplicationController
@challenge.position = challenge_count + 1
@challenge.shixun = @shixun
@challenge.user = User.current
@challenge.save!
respond_to do |format|
format.html {redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)}
end
=begin
ActiveRecord::Base.transaction do
begin
@challenge.save!
@ -53,6 +60,7 @@ class ChallengesController < ApplicationController
raise ActiveRecord::Rollback
end
end
=end
end
# 处理新建challenge返回的pipeline片段
@ -84,6 +92,7 @@ class ChallengesController < ApplicationController
end
def edit
@tab = params[:tab].blank? ? 1 : params[:tab].to_i
end
def destroy
@ -94,6 +103,9 @@ class ChallengesController < ApplicationController
end
def update
@challenge.update_attributes(params[:challenge])
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
=begin
respond_to do |format|
ActiveRecord::Base.transaction do
@challenge.update_attributes(params[:challenge])
@ -123,6 +135,40 @@ class ChallengesController < ApplicationController
end
end
end
=end
end
def update_evaluation
ActiveRecord::Base.transaction do
@challenge.update_attributes(params[:challenge])
begin
if params[:tab].to_i == 2
@test_sets.delete_all unless @test_sets.blank?
if params[:test_set][:hidden].length > 0
params[:test_set][:input].each_with_index do |input, index|
unless (input[index] == params[:test_set][:output][index] && input[index].nil?)
params[:test_set][:hidden][index].to_i == 0 ? open = 1 : open = 0
TestSet.create(:challenge_id => @challenge.id, :input => input, :output => params[:test_set][:output][index], :is_public => open, :position => (index + 1))
end
end
end
elsif params[:tab].to_i == 5
@challenge_tags.delete_all unless @challenge_tags.blank?
unless params[:knowledge].blank?
params[:knowledge][:input].each do |input|
ChallengeTag.create(:name => input, :challenge_id => @challenge.id)
end
end
end
# 向jenkins端发送请求构建公共测试用例
add_shixun_modify_status(@shixun, 1)
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
rescue Exception => e
flash[:error] = "#{e.message}"
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
raise ActiveRecord::Rollback
end
end
end
def index_down

View File

@ -9,7 +9,7 @@ class Challenge < ActiveRecord::Base
has_many :games, :dependent => :destroy
validates_presence_of :subject
validates_presence_of :score
# validates_presence_of :score
validates_presence_of :task_pass
validates_length_of :subject, :maximum => 255

View File

@ -0,0 +1,31 @@
<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %>
<%= javascript_include_tag '/editormd/editormd.min.js','/editormd/examples/js/jquery.min.js' %>
<style>
.CodeMirror-scroll{
overflow: auto !important;
margin-bottom: -30px;
margin-right: -30px;
padding-bottom: 30px;
height: 100%;
outline: none;
position: relative;
}
</style>
<div id="shixun_form">
<li class="clearfix" style="line-height:1.9;">
<label class=" panel-form-label fl"> 参考答案:</label>
<div id="challenge_answer" class="new_li">
<textarea name="challenge[answer]"><%= @challenge.answer %></textarea>
</div>
</li>
<li class="clearfix">
<a href="javascript:void(0);" class="task-btn task-btn-green fr" onclick="$('#challenge_shixun_answer_update').submit();">保存</a>
<a href="javascript:void(0);" class="task-btn fr mr10" id="answer_cancel">取消</a>
</li>
</div>
<script>
$("#answer_cancel").click(function(){
$("#answer_edit").hide();
$("#edit_answer_show").show();
})
</script>

View File

@ -0,0 +1,88 @@
<div class="panel-form">
<div id="edit_answer_show">
<div class="clearfix mb20">
<p class="fr">
<% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %>
<a href="javascript:void(0);" class="shixun-task-btn task-btn-green fr" id="edit_answer">编辑</a>
<% end %>
</p>
</div>
<ul>
<li class="clearfix">
<label class=" panel-form-label fl"> 参考答案:</label>
<div class="fl task-bg-grey panel-box-sizing panel-form-width-690 new_li" id="tpm_answer_show" style="width: 90%">
<textarea style="display:none;"><%= @challenge.answer.blank? ? "无" : (@challenge.answer) %></textarea>
</div>
</li>
</ul>
</div>
<ul class="undis" id="answer_edit">
<%= labelled_form_for @challenge, :url => shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 3), :html => {:id => "challenge_shixun_answer_update"} do |f| %>
<%= render :partial => "answer_form", :locals => {:f => f} %>
<% end %>
</ul>
</div>
<script>
$(document).ready(function() {
editormd.loadKaTeX(function() {
var answerMD = editormd.markdownToHTML("tpm_answer_show", {
htmlDecode: "style,script,iframe", // you can filter tags decode
taskList: true,
tex: true, // 默认不解析
flowChart: true, // 默认不解析
sequenceDiagram: true // 默认不解析
});
});
});
$("#edit_answer").click(function(){
$("#edit_answer_show").hide();
$("#answer_edit").show();
answer_editormd = editormd("challenge_answer", {
width : "89.6%",
height : 600,
syncScrolling : "single",
//你的lib目录的路径我这边用JSP做测试的
path : "/editormd/lib/",
tex : true,
autoFocus: false,
toolbarIcons : function() {
// Or return editormd.toolbarModes[name]; // full, simple, mini
// Using "||" set icons align right.
return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear" ]
},
toolbarCustomIcons : {
testIcon : "<a type=\"inline\" class=\"latex\" ><div class='zbg'></div></a>",
testIcon1 : "<a type=\"latex\" class=\"latex\" ><div class='zbg_latex'></div></a>"
},
//这个配置在simple.html中并没有但是为了能够提交表单使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中方便post提交表单。
saveHTMLToTextarea : true,
// 用于增加自定义工具栏的功能可以直接插入HTML标签不使用默认的元素创建图标
dialogMaskOpacity : 0.6,
placeholder: "请输入完成当前任务依赖的知识点或者其它相关信息",
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"],
imageUploadURL : "<%= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>"//url
});
window.onload = function(){
$("#challenge_answer [type=\"latex\"]").bind("click", function(){
answer_editormd.cm.replaceSelection("```latex");
answer_editormd.cm.replaceSelection("\n");
answer_editormd.cm.replaceSelection("\n");
answer_editormd.cm.replaceSelection("```");
var __Cursor = answer_editormd.cm.getDoc().getCursor();
answer_editormd.cm.setCursor(__Cursor.line-1, 0);
});
$("#challenge_answer [type=\"inline\"]").bind("click", function(){
answer_editormd.cm.replaceSelection("$$$$");
var __Cursor = answer_editormd.cm.getDoc().getCursor();
answer_editormd.cm.setCursor(__Cursor.line, __Cursor.ch-2);
answer_editormd.cm.focus();
});
$("[type=\"inline\"]").attr("title", "行内公式");
$("[type=\"latex\"]").attr("title", "多行公式");
};
})
</script>

View File

@ -0,0 +1,66 @@
<div class="panel-form">
<div id="evaluating_show" class="<%= @challenge.evaluation_way == 0 ? "undis" : "" %>">
<div class="clearfix mb20">
<p class="fr">
<% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %>
<a href="javascript:void(0);" class="shixun-task-btn task-btn-green fr" id="edit_task_pass">编辑</a>
<% end %>
</p>
</div>
<ul>
<li class="clearfix">
<label class="panel-form-label fl">文件路径:</label>
<div class="fl task-bg-grey panel-box-sizing panel-form-width-690">
<%= @challenge.path.blank? ? "无" : (h @challenge.path.html_safe) %>
</div>
</li>
<li class="clearfix">
<label class="panel-form-label fl">执行文件:</label>
<div class="fl task-bg-grey panel-box-sizing panel-form-width-690">
<%= @challenge.exec_path.blank? ? "无" : (h @challenge.exec_path) %>
</div>
</li>
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>评测方式:</label>
<div class="fl task-bg-grey panel-box-sizing panel-form-width-690">
输入输出
</div>
</li>
<li class="clearfix">
<label class="panel-form-label fl">测试集设置:</label>
<ul class="fl task-bg-grey panel-box-sizing panel-form-width-690">
<% if @test_sets.count > 0 %>
<% @test_sets.each_with_index do |test, index| %>
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb">测试集<%= index + 1 %></span>
<% if test.is_public? %>
<i class="fa fa-unlock-alt font-grey ml5" ></i>
<% else %>
<i class="fa fa-lock font-grey ml5" ></i>
<% end %>
</p>
<div class="clearfix"><span class="fl fb">输入:</span><p class="fl"><%= test.input.gsub("\r\n", "<br />").html_safe unless test.input.blank? %></p></div>
<div class="clearfix"><span class="fl fb">输出:</span><p class="fl"><%= test.output.gsub("\r\n", "<br />").html_safe unless test.output.blank? %></div>
</li>
<% end %>
<% else %>
<% end %>
</ul>
</li>
</ul>
</div>
<ul class="<%= @challenge.evaluation_way == 1 ? "undis" : "" %>" id="evaluating_edit">
<%= labelled_form_for @challenge, :url => update_evaluation_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 2), :html => {:id => "challenge_evaluation_update"} do |f| %>
<%= render :partial => "evaluating_form", :locals => {:f => f} %>
<% end %>
</ul>
</div>
<script>
$("#edit_task_pass").click(function(){
$("#evaluating_edit").show();
$("#evaluating_show").hide();
})
</script>

View File

@ -0,0 +1,37 @@
<div class="panel-form">
<div id="scroe_show" class="<%= @challenge.score.blank? ? "undis" : "" %>">
<div class="clearfix mb20">
<p class="fr">
<% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %>
<a href="javascript:void(0);" class="shixun-task-btn task-btn-green fr" id="edit_score">编辑</a>
<% end %>
</p>
</div>
<ul>
<li class="clearfix">
<label class="panel-form-label fl">难易度:</label>
<div class="fl task-bg-grey panel-box-sizing panel-form-width-690">
<%= @challenge.game_difficulty %>
</div>
</li>
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>奖励经验值:</label>
<div class="fl task-bg-grey panel-box-sizing panel-form-width-690">
<%= @challenge.score %>分
</div>
</li>
</ul>
</div>
<ul class="<%= @challenge.score.blank? ? "" : "undis" %>" id="scoring_edit">
<%= labelled_form_for @challenge, :url => shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 4), :html => {:id => "challenge_score_update"} do |f| %>
<%= render :partial => "score_form", :locals => {:f => f} %>
<% end %>
</ul>
</div>
<script>
$("#edit_score").click(function(){
$("#scoring_edit").show();
$("#scroe_show").hide();
})
</script>

View File

@ -0,0 +1,36 @@
<div class="panel-form">
<div id="edit_skill_show" class="<%= @challenge_tags.blank? ? "undis" : "" %>">
<div class="clearfix mb20">
<p class="fr">
<% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %>
<a href="javascript:void(0);" class="shixun-task-btn task-btn-green fr" id="edit_skill">编辑</a>
<% end %>
</p>
</div>
<ul>
<li class="clearfix">
<% unless @challenge_tags.blank? %>
<label class="panel-form-label fl"> 知识/技能点:</label>
<div class="fl task-bd-grey panel-box-sizing panel-form-width-690">
<% @challenge_tags.each do |tag| %>
<div class="task-tag tag-grey mb10 mr10 fl">
<%= tag.name %>
</div>
<% end %>
</div>
<% end %>
</li>
</ul>
</div>
<ul class="<%= @challenge_tags.blank? ? "" : "undis" %>" id="skill_edit">
<%= labelled_form_for @challenge, :url => update_evaluation_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 5), :html => {:id => "challenge_skill_update"} do |f| %>
<%= render :partial => "skill_form", :locals => {:f => f} %>
<% end %>
</ul>
</div>
<script>
$("#edit_skill").click(function(){
$("#edit_skill_show").hide();
$("#skill_edit").show();
});
</script>

View File

@ -0,0 +1,95 @@
<div class="panel-form">
<div id="task_pass_show">
<div class="clearfix mb20">
<p class="fr">
<% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %>
<a href="javascript:void(0);" class="shixun-task-btn task-btn-green fr" id="edit_task_pass">编辑</a>
<% end %>
</p>
</div>
<ul>
<li class="clearfix">
<label class="panel-form-label fl">名称:</label>
<div class="fl task-bg-grey panel-box-sizing panel-form-width-690">
<%= @challenge.subject %>
</div>
</li>
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>过关任务:</label>
<div class="fl task-bg-grey panel-box-sizing panel-form-width-690 new_li" id="challenge_task_pass_show" style="width: 90%">
<textarea style="display:none;"><%= @challenge.task_pass %></textarea>
</div>
</li>
</ul>
</div>
<ul class="undis" id="task_pass_edit">
<%= labelled_form_for @challenge, :url => shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 1), :html => {:id => "challenge_shixun_update"} do |f| %>
<%= render :partial => "task_pass_form", :locals => {:f => f} %>
<% end %>
</ul>
</div>
<script>
$(document).ready(function() {
editormd.loadKaTeX(function() {
var taskPassMD = editormd.markdownToHTML("challenge_task_pass_show", {
htmlDecode: "style,script,iframe", // you can filter tags decode
taskList: true,
tex: true, // 默认不解析
flowChart: true, // 默认不解析
sequenceDiagram: true // 默认不解析
});
});
});
$("#edit_task_pass").click(function(){
$("#task_pass_show").hide();
$("#task_pass_edit").show();
taskpass_editormd = editormd("challenge_task_pass", {
width : "89.6%",
height : 600,
syncScrolling : "single",
//你的lib目录的路径我这边用JSP做测试的
path : "/editormd/lib/",
tex : true,
autoFocus: false,
toolbarIcons : function() {
// Or return editormd.toolbarModes[name]; // full, simple, mini
// Using "||" set icons align right.
return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear" ]
},
toolbarCustomIcons : {
testIcon : "<a type=\"inline\" class=\"latex\" ><div class='zbg'></div></a>",
testIcon1 : "<a type=\"latex\" class=\"latex\" ><div class='zbg_latex'></div></a>"
},
//这个配置在simple.html中并没有但是为了能够提交表单使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中方便post提交表单。
saveHTMLToTextarea : true,
// 用于增加自定义工具栏的功能可以直接插入HTML标签不使用默认的元素创建图标
dialogMaskOpacity : 0.6,
placeholder: "请输入完成当前任务依赖的知识点或者其它相关信息",
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"],
imageUploadURL : "<%= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>"//url
});
window.onload = function(){
$("#challenge_task_pass [type=\"latex\"]").bind("click", function(){
taskpass_editormd.cm.replaceSelection("```latex");
taskpass_editormd.cm.replaceSelection("\n");
taskpass_editormd.cm.replaceSelection("\n");
taskpass_editormd.cm.replaceSelection("```");
var __Cursor = taskpass_editormd.cm.getDoc().getCursor();
taskpass_editormd.cm.setCursor(__Cursor.line-1, 0);
});
$("#challenge_task_pass [type=\"inline\"]").bind("click", function(){
taskpass_editormd.cm.replaceSelection("$$$$");
var __Cursor = taskpass_editormd.cm.getDoc().getCursor();
taskpass_editormd.cm.setCursor(__Cursor.line, __Cursor.ch-2);
taskpass_editormd.cm.focus();
});
$("[type=\"inline\"]").attr("title", "行内公式");
$("[type=\"latex\"]").attr("title", "多行公式");
};
})
</script>

View File

@ -0,0 +1,167 @@
<script id="t:sample-answer-list" type="text/html">
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl" name="sample_inputs_label"></span>
<input type="checkbox" name="test_set[lock][]" class="fl ml5 mr5 mt8" value=""><span class="fl mr5">锁定</span>
<input type="hidden" name="test_set[hidden][]"/>
<a href="javascript:void(0)" title="增加" class="sample_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
<a href="javascript:void(0)" title="删除" class="sample_icon_remove"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt7"></i></a>
</p>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="test_set[input][]" placeholder="输入" ></textarea>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="test_set[output][]" placeholder="希望输出" ></textarea>
</li>
</script>
<div id="shixun_form">
<li class="clearfix">
<label class="panel-form-label fl">文件路径:</label>
<%= f.text_field :path, :class => "panel-form-width-690 panel-box-sizing fl", :no_label => true, :placeholder => "进入实训后将默认打开该文件src/test/welcome.java", :maxlength => "256" %>
</li>
<li class="clearfix">
<label class="panel-form-label fl">执行文件:</label>
<%= f.text_field :exec_path, :class => "panel-form-width-690 panel-box-sizing fl", :no_label => true, :placeholder => "输入关卡需要执行的文件路径src/test/main.java", :maxlength => "256" %>
</li>
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>评测方式:</label>
<%= select_tag :evaluation_way, options_for_select([["输入输出", 1]]), :name => 'challenge[evaluation_way]', :class => " fl", :style => "height: 40px; width:200px;" %>
<span class="fl ml15 mt8">请选择自动检测学员是否完成本任务的评测标准</span>
</li>
<li class="clearfix">
<% if params[:action] == "edit" && @challenge.test_sets.count > 0 %>
<label class="panel-form-label fl">测试集设置:</label>
<ul class="fl task-bg-grey panel-box-sizing" >
<% @challenge.test_sets.each_with_index do |test_set, index| %>
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl" name="sample_inputs_label">组<%= index + 1 %></span>
<% if test_set.is_public? %>
<input type="checkbox" name="test_set[lock][]" class="fl ml5 mr5 mt8"><span class="fl mr5">锁定</span>
<% else %>
<input type="checkbox" name="test_set[lock][]" class="fl ml5 mr5 mt8" checked="checked"><span class="fl mr5">锁定</span>
<% end %>
<input type="hidden" name="test_set[hidden][]"/>
<% if index == 0 %>
<span class="color-grey fr" style="font-size:12px;">温馨提示:选中“锁定”,则对学员隐藏该条测试集,但在“提交评测”时也将被自动检测。</span>
<% end %>
<a href="javascript:void(0)" title="增加" class="sample_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
<% if index > 0 %>
<a href="javascript:void(0)" title="删除" class="sample_icon_remove"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt7"></i></a>
<% end %>
</p>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="test_set[input][]" placeholder="输入"><%= test_set.input %></textarea>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="test_set[output][]" placeholder="希望输出"><%= test_set.output %></textarea>
</li>
<% end %>
</ul>
<% else %>
<label class="panel-form-label fl">测试集设置:</label>
<ul class="fl task-bg-grey panel-box-sizing">
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl" name="sample_inputs_label">组1</span>
<span class="color-grey fr" style="font-size:12px;">温馨提示:选中“锁定”,在“提交评测”时它也将被自动检测,但学员暂不可查看内容。</span>
<input type="checkbox" name="test_set[lock][]" class="fl ml5 mr5 mt8" value=""><span class="fl mr5">锁定</span>
<input type="hidden" name="test_set[hidden][]"/>
<a href="javascript:void(0)" title="增加" class="sample_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
</p>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="test_set[input][]" placeholder="输入" ></textarea>
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="test_set[output][]" placeholder="希望输出" ></textarea>
</li>
</ul>
<% end %>
</li>
<li class="clearfix">
<a href="javascript:void(0);" class="task-btn task-btn-green fr" onclick="submit_shixun_evaluating();">保存</a>
<a href="javascript:void(0);" class="task-btn fr mr10" id="evaluating_cancel">取消</a>
</li>
</div>
<script type="text/javascript">
$(function () {
var bt = baidu.template;
bt.LEFT_DELIMITER = '<!';
bt.RIGHT_DELIMITER = '!>';
$("#shixun_form").on('click', 'a.test_icon_add', function () {
var html = bt('t:test-answer-list', null);
$(this).parent().parent('.clearfix').after(html);
var inputs = document.getElementsByName("program[input][]");
var outputs = document.getElementsByName("program[output][]");
var inputs_labels = document.getElementsByName("inputs_label");
for (var j = 0; j < inputs_labels.length; j++) {
$(inputs_labels[j]).html("测试集"+ (j + 1));
}
if (inputs.length == outputs.length) {
for (var i = 0; i < inputs.length; i++) {
// autoTextarea2(inputs[i], outputs[i], 0, 140);
// autoTextarea2(outputs[i], inputs[i], 0, 140);
}
}
$(inputs[inputs.length - 1]).focus();
});
$("#shixun_form").on('click', 'a.test_icon_remove', function () {
$(this).parent().parent('.clearfix').remove();
var inputs_labels = document.getElementsByName("inputs_label");
for (var j = 0; j < inputs_labels.length; j++) {
$(inputs_labels[j]).html("测试集" + (j + 1));
}
});
$("#shixun_form").on('click', 'a.sample_icon_add', function () {
var html = bt('t:sample-answer-list', null);
$(this).parent().parent('.clearfix').after(html);
var inputs = document.getElementsByName("test_set[input][]");
var outputs = document.getElementsByName("test_set[output][]");
var inputs_labels = document.getElementsByName("sample_inputs_label");
for (var j = 0; j < inputs_labels.length; j++) {
$(inputs_labels[j]).html("组" + (j + 1));
}
// 设置测试集的的输入与输出的回车自动调整宽度
if (inputs.length == outputs.length) {
for (var i = 0; i < inputs.length; i++) {
autoTextarea(inputs[i], 0, 140);
autoTextarea(outputs[i], 0, 140);
}
}
$(inputs[inputs.length - 1]).focus();
});
$("#shixun_form").on('click', 'a.sample_icon_remove', function () {
$(this).parent().parent('.clearfix').remove();
var inputs_labels = document.getElementsByName("sample_inputs_label");
for (var j = 0; j < inputs_labels.length; j++) {
$(inputs_labels[j]).html("组" + (j + 1));
}
});
});
// 设置textarea的宽度到140以后出现滚动条
var test_set_inputs = document.getElementsByName("test_set[input][]");
var test_set_outputs = document.getElementsByName("test_set[output][]");
if (test_set_inputs.length == test_set_outputs.length) {
for (var i = 0; i < test_set_inputs.length; i++) {
autoTextarea(test_set_inputs[i], 0, 140);
autoTextarea(test_set_outputs[i], 0, 140);
}
}
// 判断测试集是否锁定, 0未锁定1锁定
function test_set_whether_lock(){
var lock = document.getElementsByName("test_set[lock][]");
var hid = document.getElementsByName("test_set[hidden][]");
for(var o = 0; o < lock.length; o++){
if($(lock[o]).prop("checked")){
$(hid[o]).val(1);
}else{
$(hid[o]).val(0);
}
}
}
// 提交表单
function submit_shixun_evaluating(){
test_set_whether_lock();
$('#challenge_evaluation_update').submit();
}
$("#evaluating_cancel").click(function(){
$("#evaluating_edit").hide();
$("#evaluating_show").show();
})
</script>

View File

@ -0,0 +1,81 @@
<div id="shixun_form">
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>难易度:</label>
<span class="mt10 fl"><%= radio_button_tag("challenge[difficulty]", 1, checked = (@challenge.difficulty ==1 ? true : false)) %></span><span class="ml5 fl mt8 mr15">简单</span>
<span class="mt10 fl"><%= radio_button_tag("challenge[difficulty]", 2, checked = (@challenge.difficulty ==2 ? true : false)) %></span><span class="ml5 fl mt8 mr15">中等</span>
<span class="mt10 fl"><%= radio_button_tag("challenge[difficulty]", 3, checked = (@challenge.difficulty ==3 ? true : false)) %></span><span class="ml5 fl mt8 mr15">困难 </span>
<!-- <span class="fl color-orange ml30 mt8"><i class="fa fa-exclamation-circle mr5"></i>请选择难易度并设定通过本关后,学员得到的经验值</span>-->
</li>
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>奖励经验值:</label>
<%#= f.text_field :score, :class => "panel-form-height-30 fl", :no_label => true, :style => "padding:5px;", :placeholder => "请输入分值(只能是数字)" %>
<%= select_tag :challenge_score, options_for_select([100, 200]), :name => 'challenge[score]', :class => " fl", :style => "height: 40px; width:170px;" %>
<div class="clear"></div>
<span style="display: none" class="c_red ml90" id="new_shixun_score">分值设定不能为空</span>
</li>
<div class="prop-notice-info mb10 ml95 w850">
<ol>
<li>如果学员查看了参考答案,则不能得到相应的经验值</li>
<li>如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+100经验值、+100金币</li>
</ol>
</div>
<li class="clearfix">
<a href="javascript:void(0);" class="task-btn task-btn-green fr" onclick="challenge_score_update();">保存</a>
<a href="javascript:void(0);" class="task-btn fr mr10" id="score_cancel">取消</a>
</li>
</div>
<script type="text/javascript">
// 根据难易程度设置不同的奖励经验值(适用新建与编辑模式)
var list= $('input:radio[name="challenge[difficulty]"]:checked').val(); // 获取select的索引值
if(list == 1){
$("#challenge_score").empty();
for(var i= 100; i <= 200; i += 100){
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
}
}else if(list == 2){
$("#challenge_score").empty();
for(var i= 300; i <= 600; i += 100){
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
}
}else if(list == 3){
$("#challenge_score").empty();
for(var i= 700; i <= 1000; i += 100){
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
}
}
$("#challenge_score").find("option[value='<%= @challenge.score %>']").attr("selected",true); // 设置option默认值
$("#challenge_difficulty_1").click(function(){
$("#challenge_score").empty();
for(var i= 100; i <= 200; i += 100){
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
}
});
$("#challenge_difficulty_2").click(function(){
$("#challenge_score").empty();
for(var i= 300; i <= 600; i += 100){
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
}
});
$("#challenge_difficulty_3").click(function(){
$("#challenge_score").empty();
for(var i= 700; i <= 1000; i += 100){
$("#challenge_score").append("<option value="+ i + ">"+ i +"</option>");
}
})
function challenge_score_update(){
if($("#challenge_score").val().trim()==""){
$("#challenge_score").focus();
$("#new_shixun_score").show();
}else{
$('#challenge_score_update').submit();
}
}
$("#score_cancel").click(function(){
$("#scoring_edit").hide();
$("#scroe_show").show();
})
</script>

View File

@ -0,0 +1,63 @@
<div id="shixun_form">
<li class="clearfix" style="margin-bottom: 0;">
<label class=" panel-form-label fl"> 技能标签:</label>
<div class="fl task-bd-grey">
<% if params[:action] == "edit" && @challenge_tags.count > 0 %>
<% @challenge_tags.each do |tag| %>
<div class="task-tag tag-grey mt5 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button" onclick="close_tag(this)">×</button>
<input class='knowledge_frame' name='knowledge[input][]' value="<%= tag.try(:name)%>" />
</div>
<% end %>
<% end %>
<div class="task-tag tag-grey mt5 mr10 fl" id="add_shixun_skill">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button" onclick="$('#add_shixun_skill').slideToggle();">×</button>
<input type="text" class="task-tag-input" onblur="add_tag();" id="shixun_skill_input" placeholder="请输入知识/技能点" />
</div>
<a href="javascript:void(0);" onclick="$('#add_shixun_skill').slideToggle();" id="add_knowledge" style="color: #627bfd;float: left;margin-top: 5px">+添加</a>
</div>
</li>
<p class="color-red ml95" style="height: 25px;"><span id="stage_name_notice" style="display: none;"><i class="fa fa-exclamation-circle color-red mr5"></i>知识/技能点不能为空</span></p>
<div class="prop-notice-info mb10 ml95 w850">
<ol>
<li>学员为参考答案通过了本阶段的评测时将获得技能,否则不能获得技能</li>
</ol>
</div>
<li class="clearfix">
<a href="javascript:void(0);" class="task-btn task-btn-green fr" onclick="challenge_skill_update();">保存</a>
<a href="<%= edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 5) %>" class="task-btn fr mr10" id="skill_cancel">取消</a>
</li>
</div>
<script type="text/javascript">
function add_tag(){
var num = $(".task-bd-grey").children('div').length;
var val = $(".task-tag-input").val().trim();
if (val != ""){
testLength = $(".task-tag-input").val().trim().length;
$("#add_knowledge").before("<div class='task-tag tag-grey mt5 mr10 fl' id='knowledge_" + num + "'>" +
"<button data-dismiss='alert' class='close fr mt3 ml5' type='button' onclick='close_tag(this)'>×</button>" +
"<input style='width:"+ testLength*12 +"px' class='knowledge_frame' name='knowledge[input][]' value='" + val +"'>" +
" </div>");
$(".task-tag-input").attr("value","");
}
$("#shixun_skill_input").val("");
}
function close_tag(thisObj){
// 获取父节点的id
var obj = thisObj.parentNode.id;
$("#"+obj).remove();
}
function challenge_skill_update(){
var nSkill = $(".knowledge_frame");
if (nSkill.length > 0){
$("#challenge_skill_update").submit();
}else{
$("#stage_name_notice").show();
}
}
</script>

View File

@ -0,0 +1,107 @@
<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %>
<%= javascript_include_tag '/editormd/editormd.min.js','/editormd/examples/js/jquery.min.js' %>
<style>
.CodeMirror-scroll{
overflow: auto !important;
margin-bottom: -30px;
margin-right: -30px;
padding-bottom: 30px;
height: 100%;
outline: none;
position: relative;
}
</style>
<div id="shixun_form">
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>名称:</label>
<%= f.text_field :subject, :class => "panel-form-width-690 fl panel-box-sizing", :no_label => true, :placeholder => "请输入当前任务的名称(此信息将提前泄露给学员)" %>
<span style="display: none" class="c_red ml95" id="new_shixun_name">任务名称不能为空</span>
</li>
<li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>过关任务:</label>
<div id="challenge_task_pass" class="new_li">
<textarea name="challenge[task_pass]"><%= @challenge.task_pass %></textarea>
</div>
<span style="display: none" class="c_red ml95" id="new_shixun_pass">过关任务不能为空</span>
</li>
<li class="clearfix">
<a href="javascript:void(0);" class="task-btn task-btn-green fr" onclick="challenge_update()">保存</a>
<a href="javascript:void(0);" class="task-btn fr mr10" id="task_pass_cancel">取消</a>
</li>
</div>
<script type="text/javascript">
$(function() {
taskpass_editormd = editormd("challenge_task_pass", {
width : "89.6%",
height : 600,
syncScrolling : "single",
//你的lib目录的路径我这边用JSP做测试的
path : "/editormd/lib/",
tex : true,
autoFocus: false,
toolbarIcons : function() {
// Or return editormd.toolbarModes[name]; // full, simple, mini
// Using "||" set icons align right.
return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear" ]
},
toolbarCustomIcons : {
testIcon : "<a type=\"inline\" class=\"latex\" ><div class='zbg'></div></a>",
testIcon1 : "<a type=\"latex\" class=\"latex\" ><div class='zbg_latex'></div></a>"
},
//这个配置在simple.html中并没有但是为了能够提交表单使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中方便post提交表单。
saveHTMLToTextarea : true,
// 用于增加自定义工具栏的功能可以直接插入HTML标签不使用默认的元素创建图标
dialogMaskOpacity : 0.6,
placeholder: "请输入完成当前任务依赖的知识点或者其它相关信息",
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"],
imageUploadURL : "<%= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>"//url
});
});
window.onload = function(){
$("#challenge_task_pass [type=\"latex\"]").bind("click", function(){
taskpass_editormd.cm.replaceSelection("```latex");
taskpass_editormd.cm.replaceSelection("\n");
taskpass_editormd.cm.replaceSelection("\n");
taskpass_editormd.cm.replaceSelection("```");
var __Cursor = taskpass_editormd.cm.getDoc().getCursor();
taskpass_editormd.cm.setCursor(__Cursor.line-1, 0);
});
$("#challenge_task_pass [type=\"inline\"]").bind("click", function(){
taskpass_editormd.cm.replaceSelection("$$$$");
var __Cursor = taskpass_editormd.cm.getDoc().getCursor();
taskpass_editormd.cm.setCursor(__Cursor.line, __Cursor.ch-2);
taskpass_editormd.cm.focus();
});
$("[type=\"inline\"]").attr("title", "行内公式");
$("[type=\"latex\"]").attr("title", "多行公式");
};
$("#challenge_subject").keydown(function(){
$("#new_shixun_name").hide();
});
$("#challenge_subject").keydown(function(){
$("#new_shixun_pass").hide();
});
$("#task_pass_cancel").click(function(){
$("#task_pass_show").show();
$("#task_pass_edit").hide();
});
function challenge_update(){
if($('#challenge_subject').val().trim() == ""){
$("#challenge_subject").focus();
$("#new_shixun_name").show();
}else if($("#challenge_task_pass textarea").val().trim() == ""){
$("#challenge_task_pass textarea").focus();
$("#new_shixun_pass").show();
}else{
$('#challenge_shixun_update').submit();
}
}
</script>

View File

@ -1,22 +1,54 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: true, prettify: false, init_activity: false) %>
<%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %>
<%= stylesheet_link_tag "/assets/codemirror/codemirror" %>
<% end %>
<%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %>
<%= stylesheet_link_tag "/assets/codemirror/codemirror" %>
<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %>
<%= javascript_include_tag '/editormd/lib/marked.min.js','/editormd/lib/prettify.min.js','/editormd/lib/raphael.min.js','/editormd/lib/underscore.min.js','/editormd/lib/sequence-diagram.min.js',
'/editormd/lib/flowchart.min.js','/editormd/lib/jquery.flowchart.min.js','/editormd/editormd.js' %>
<style>
.editormd-preview-container, .editormd-html-preview{
text-align: left;
font-size: 16px;
line-height: 1.8;
}
.-task-ml80 .CodeMirror pre{
font-size: 16px;
}
</style>
<div class="task-pm-content mb20">
<div class="task-pm-box mt20">
<div class="panel-header clearfix">
<h3 class="fl mt5">编辑阶段(第<%= @challenge.position %>关)</h3>
<h3 class="fl mt5">阶段编辑(第<%= @challenge.position %>关)</h3>
</div>
<div class=" panel-form ">
<ul>
<%= labelled_form_for @challenge, :url => shixun_challenge_path(@challenge, :shixun_id => @shixun) do |f| %>
<%= render :partial => "form", :locals => {:f => f} %>
<% end %>
</ul>
</div>
</div>
<ul class="nav_check_item clearfix mt20" style="margin-bottom: 0;">
<li class="fl <%= @tab == 1 ? "check_nav" : "" %>">
<a href="<%= edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 1) %>">本关任务</a>
</li>
<li class="fl <%= @tab == 2 ? "check_nav" : "" %>">
<a href="<%= edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 2) %>">评测设置</a>
</li>
<li class="fl <%= @tab == 3 ? "check_nav" : "" %>">
<a href="<%= edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 3) %>">参考答案</a>
</li>
<li class="fl <%= @tab == 4 ? "check_nav" : "" %>">
<a href="<%= edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 4) %>">评分设置</a>
</li>
<li class="fl <%= @tab == 5 ? "check_nav" : "" %>">
<a href="<%= edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 5) %>">技能勋章</a>
</li>
</ul>
<div class="task-pm-box">
<% if @tab == 1 || @tab.blank? %>
<%= render :partial => "edit_task_pass" %>
<% elsif @tab == 2 %>
<%= render :partial => "edit_evaluating" %>
<% elsif @tab == 3 %>
<%= render :partial => "edit_answer" %>
<% elsif @tab == 4 %>
<%= render :partial => "edit_scoring" %>
<% elsif @tab == 5 %>
<%= render :partial => "edit_skill" %>
<% end %>
</div>
</div>

View File

@ -1,5 +1,24 @@
<%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %>
<%= stylesheet_link_tag "/assets/codemirror/codemirror" %>
<div class="task-pm-box mt20">
<div class="panel-header clearfix">
<h3 class="fl mt5">新建阶段</h3>
</div>
<div class=" panel-form ">
<ul>
<%= labelled_form_for @challenge, :url => shixun_challenges_path(@shixun), :html => { :id => "challenge_shixun_update"} do |f| %>
<%= render :partial => "task_pass_form", :locals => {:f => f} %>
<% end %>
</ul>
</div>
</div>
<% if false %>
<div class="task-pm-box mt20">
<div class="panel-header clearfix">
<h3 class="fl mt5">新建阶段</h3>
@ -12,6 +31,6 @@
</ul>
</div>
</div>
<% end %>

View File

@ -92,6 +92,7 @@ RedmineApp::Application.routes.draw do
match 'game_build_result', :via => [:get, :post]
get 'index_up'
get 'index_down'
match 'update_evaluation', :via => [:get, :post, :put]
end
end

View File

@ -161,6 +161,7 @@ a.course-bth-blue{cursor: pointer;background-color:#199ed8 ;color: #ffffff;displ
.pr {position:relative;}
.w100{width: 100px;}
.w150{width: 150px;}
.w850{width: 850px;}
.with10{ width: 10%;}.with15{ width: 15%;}
.with20{ width: 20%;}.with25{ width: 25%;}
.with30{ width: 30%;}.with35{ width: 35%;}

View File

@ -269,3 +269,6 @@ a:hover.task-btn-line{ border:1px solid #3498db;background:#3498db;color: #fff;}
/*新增的公用样式*/
.box-boxshadow{box-shadow: 3px 3px 10px rgba(146, 153, 169, 0.2);}
.prop-notice-info{padding: 10px;border:1px solid #F3DDB3;background-color: #FFFEF4;}
.prop-notice-info ol{list-style-type: disc;list-style-position:inside}
.prop-notice-info ol li{list-style-type: disc;color: #ff6532;margin-bottom:0!important;}