Merge branch 'dev_shixun_project' of https://git.trustie.net/jacknudt/trustieforge into dev_shixun_project

This commit is contained in:
daiao 2017-03-22 14:24:42 +08:00
commit 5f2a9869f9
12 changed files with 120 additions and 91 deletions

View File

@ -41,6 +41,11 @@ class ChallengesController < ApplicationController
end end
end end
end end
if params[:knowledge][:input].length > 0
params[:knowledge][:input].each do |input|
ChallengeTag.create(:name => input, :challenge_id => @challenge.id)
end
end
respond_to do |format| respond_to do |format|
format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun)} format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun)}
end end
@ -64,7 +69,9 @@ class ChallengesController < ApplicationController
end end
def show def show
@outputs = GameOutputs.all @challenge_samples = @challenge.challenge_samples
@test_sets = @challenge.test_sets
@challenge_tags = @challenge.challenge_tags
respond_to do |format| respond_to do |format|
format.html format.html
format.js format.js
@ -72,10 +79,13 @@ class ChallengesController < ApplicationController
end end
def edit def edit
@challenge_samples = @challenge.challenge_samples
@test_sets = @challenge.test_sets
@challenge_tags = @challenge.challenge_tags
end end
def update def update
@challenge = Challenge.new(params[:challenge])
end end

View File

@ -22,6 +22,7 @@ class MyshixunsController < ApplicationController
game.update_attribute(:status, 0) game.update_attribute(:status, 0)
end end
game_outputs = GameOutputs.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut) game_outputs = GameOutputs.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
render :json => {:data => "success"}
end end
def show def show

View File

@ -4,6 +4,7 @@ class Challenge < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :challenge_samples, :dependent => :destroy has_many :challenge_samples, :dependent => :destroy
has_many :test_sets, :dependent => :destroy has_many :test_sets, :dependent => :destroy
has_many :challenge_tags, :dependent => :destroy
validates_presence_of :subject validates_presence_of :subject
validates_presence_of :score validates_presence_of :score

View File

@ -0,0 +1,4 @@
class ChallengeTag < ActiveRecord::Base
attr_accessible :challenge_id, :name
belongs_to :challenge
end

View File

@ -42,7 +42,7 @@
</li> </li>
<li class="clearfix"> <li class="clearfix">
<% if params[:action] == "edit" && @challenge.challenge_samples.count > 0 %> <% if params[:action] == "edit" && @challenge.challenge_samples.count > 0 %>
<% @challenge.challenge_samples.each_with_index do |sample, index| %> <% @challenge.challenge_samples.each_with_index do |sample, index| %>
<label class="panel-form-label fl">样例设置:</label> <label class="panel-form-label fl">样例设置:</label>
<ul class="fl task-bg-grey"> <ul class="fl task-bg-grey">
<li class="clearfix"> <li class="clearfix">
@ -60,7 +60,7 @@
<input type="text" class="panel-form-width-670 panel-form-height-30" name="sample[output][]" id="textarea_sample_output_test" placeholder="样例输出" value="<%= sample.output %>" /> <input type="text" class="panel-form-width-670 panel-form-height-30" name="sample[output][]" id="textarea_sample_output_test" placeholder="样例输出" value="<%= sample.output %>" />
</li> </li>
</ul> </ul>
<% end %> <% end %>
<% else %> <% else %>
<label class="panel-form-label fl">样例设置:</label> <label class="panel-form-label fl">样例设置:</label>
<ul class="fl task-bg-grey"> <ul class="fl task-bg-grey">
@ -77,14 +77,15 @@
<% end %> <% end %>
</li> </li>
<li class="clearfix"> <li class="clearfix">
<% if params[:action] == "edit" && @challenge.test_sets.count > 0 %> <label class="panel-form-label fl">测试集设置:</label>
<% @challenge.test_sets.each_with_index do |test, index| %> <ul class="fl task-bg-grey">
<label class="panel-form-label fl">测试集设置:</label> <li class="clearfix">
<ul class="fl task-bg-grey">
<li class="clearfix"> <% if params[:action] == "edit" && @challenge.test_sets.count > 0 %>
<% @challenge.test_sets.each_with_index do |test, index| %>
<p class="clearfix"> <p class="clearfix">
<span class="color-green fb fl" name="inputs_label">测试<%= index + 1 %></span> <span class="color-green fb fl" name="inputs_label">测试<%= index + 1 %></span>
<% if index == 0%> <% if index == 0 %>
<span class="color-grey fr" style="font-size:12px;">温馨提示:在学员"提交评测"时进行自动检测。</span> <span class="color-grey fr" style="font-size:12px;">温馨提示:在学员"提交评测"时进行自动检测。</span>
<% end %> <% end %>
<a href="javascript:void(0);" title="增加" class="test_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt12"></i></a> <a href="javascript:void(0);" title="增加" class="test_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt12"></i></a>
@ -94,13 +95,9 @@
</p> </p>
<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" name="program[input][]" id="textarea_input_test" value="<%= test.input %>"/> <input type="text" class="panel-form-width-670 panel-form-height-30 mb10" name="program[input][]" id="textarea_input_test" value="<%= test.input %>"/>
<input type="text" class="panel-form-width-670 panel-form-height-30" name="program[output][]" id="textarea_output_test" value="<%= test.output %>" /> <input type="text" class="panel-form-width-670 panel-form-height-30" name="program[output][]" id="textarea_output_test" value="<%= test.output %>" />
</li>
</ul> <% end %>
<% end %> <% else %>
<% else %>
<label class="panel-form-label fl">测试集设置:</label>
<ul class="fl task-bg-grey">
<li class="clearfix">
<p class="clearfix"> <p class="clearfix">
<span class="color-green fb fl" name="inputs_label">测试1</span> <span class="color-green fb fl" name="inputs_label">测试1</span>
<span class="color-grey fr" style="font-size:12px;">温馨提示:在学员"提交评测"时进行自动检测。</span> <span class="color-grey fr" style="font-size:12px;">温馨提示:在学员"提交评测"时进行自动检测。</span>
@ -108,9 +105,9 @@
</p> </p>
<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" name="program[input][]" id="textarea_input_test" placeholder="测试输入" /> <input type="text" class="panel-form-width-670 panel-form-height-30 mb10" name="program[input][]" id="textarea_input_test" placeholder="测试输入" />
<input type="text" class="panel-form-width-670 panel-form-height-30" name="program[output][]" id="textarea_output_test" placeholder="测试输出" /> <input type="text" class="panel-form-width-670 panel-form-height-30" name="program[output][]" id="textarea_output_test" placeholder="测试输出" />
</li> <% end %>
</ul> </li>
<% end %> </ul>
</li> </li>
<li class="clearfix"> <li class="clearfix">
<label class=" panel-form-label fl"> 知识/技能点:</label> <label class=" panel-form-label fl"> 知识/技能点:</label>
@ -118,13 +115,19 @@
<button class="close fl mt3 mr10" type="button" onclick="$('#add_shixun_skill').slideToggle();" id="add_knowledge">+</button> <button class="close fl mt3 mr10" type="button" onclick="$('#add_shixun_skill').slideToggle();" id="add_knowledge">+</button>
<div class="task-tag tag-grey mb10 mr10 fl undis" id="add_shixun_skill"> <div class="task-tag tag-grey mb10 mr10 fl undis" id="add_shixun_skill">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button" onclick="$('#add_shixun_skill').slideToggle();">×</button> <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();" placeholder="请输入知识/技能点" /> <% if params[:action] == "edit" && @challenge_tags.count > 0 %>
<% @challenge_tags.each do |tag| %>
<input type="text" class="task-tag-input" onblur="add_tag();" placeholder="请输入知识/技能点" value="<%= tag.try(:name) %>" />
<% end %>
<% else %>
<input type="text" class="task-tag-input" onblur="add_tag();" placeholder="请输入知识/技能点" />
<% end %>
</div> </div>
</div> </div>
</li> </li>
<li class="clearfix"> <li class="clearfix" style="line-height:1.9;">
<label class=" panel-form-label fl"> 参考答案:</label> <label class=" panel-form-label fl"> 参考答案:</label>
<%= f.text_area :answer, :id => 'challenge-answer', :class => "panel-form-width-690 panel-form-height-150 fl task-textarea-pd", :no_label => true %> <%= f.text_area :answer, :id => 'challenge-answer', :class => "panel-form-width-690 panel-form-height-150 fl task-textarea-pd", :no_label => true, :style => "line-height:1.9;" %>
<script> <script>
var text = document.getElementById("challenge-answer"); var text = document.getElementById("challenge-answer");
</script> </script>
@ -137,7 +140,11 @@
<span style="display: none" class="c_red ml90" id="new_shixun_score">分值设定不能为空</span> <span style="display: none" class="c_red ml90" id="new_shixun_score">分值设定不能为空</span>
</li> </li>
<li class="clearfix"> <li class="clearfix">
<a href="javascript:void(0)" class="task-btn task-btn-green fr mr10" onclick="challenge_create()">保存</a> <% if params[:action] == "edit" %>
<a href="javascript:void(0)" class="task-btn task-btn-green fr mr10" onclick="challenge_update()">保存</a>
<% else %>
<a href="javascript:void(0)" class="task-btn task-btn-green fr mr10" onclick="challenge_create()">保存</a>
<% end %>
<a href="javascript:void(0)" class="task-btn fr mr10">取消</a> <a href="javascript:void(0)" class="task-btn fr mr10">取消</a>
</li> </li>
</div> </div>
@ -263,4 +270,16 @@
$('#new_challenge').submit(); $('#new_challenge').submit();
} }
} }
function challenge_update(){
if($('#challenge_subject').val().trim() == ""){
$("#new_shixun_name").show();
}else if($("#challenge_task_pass").val().trim() == ""){
$("#new_shixun_pass").show();
}else if($("#challenge_score").val().trim()==""){
$("#new_shixun_score").show();
}else{
$('#edit_challenge_48').submit();
}
}
</script> </script>

View File

@ -9,34 +9,35 @@
<div class="task-pm-box mt20"> <div class="task-pm-box mt20">
<div class="panel-header clearfix"> <div class="panel-header clearfix">
<h3 class="fl mt5">阶段详情</h3> <h3 class="fl mt5">阶段详情</h3>
<a href="<%= new_shixun_challenge_path(@shixun) %>" class=" task-btn task-btn-green fr">新建阶段</a>
</div> </div>
<div class="panel-form"> <div class="panel-form">
<div class="clearfix mb20"> <div class="clearfix mb20">
<h3 class="fl panel-inner-title"><span class="color-red mr10">第<%= @challenge.position %>关</span><%= @challenge.subject %></h3> <h3 class="fl panel-inner-title"><span class="color-red mr10">第<%= @challenge.position %>关</span><%= @challenge.subject %></h3>
<p class="fr"> <p class="fr">
<a href="#" title="编辑"><i class="fa fa-pencil-square-o color-grey font-16 mr5"></i></a> <a href="<%= edit_shixun_challenge_path(@challenge, :shixun_id => @shixun) %>" title="编辑"><i class="fa fa-pencil-square-o color-grey font-16 mr5"></i></a>
<a href="#" title="删除"><i class="fa fa-trash-o color-grey font-16 mr5"></i></a> <a href="#" title="删除"><i class="fa fa-trash-o color-grey font-16 mr5"></i></a>
<a href="#" title="复制"><i class="fa fa-files-o color-grey font-16 mr5"></i></a> <!--<a href="#" title="复制"><i class="fa fa-files-o color-grey font-16 mr5"></i></a>-->
</p> </p>
</div> </div>
<ul> <ul>
<li class="clearfix"> <li class="clearfix">
<label class="panel-form-label fl">预备知识:</label> <label class="panel-form-label fl">预备知识:</label>
<div class="fl task-bg-grey"> <div class="fl task-bg-grey">
<%= @challenge.ready_knowledge.blank? ? "无" : (h @challenge.ready_knowledge.html_safe) %> <%= @challenge.ready_knowledge.blank? ? "无" : (h @challenge.ready_knowledge) %>
</div> </div>
</li> </li>
<li class="clearfix"> <li class="clearfix">
<label class="panel-form-label fl"><span class="c_red mr5">*</span>过关任务:</label> <label class="panel-form-label fl"><span class="c_red mr5">*</span>过关任务:</label>
<div class="fl task-bg-grey"> <div class="fl task-bg-grey">
<%= h @challenge.task_pass.html_safe %> <%= h @challenge.task_pass %>
</div> </div>
</li> </li>
<li class="clearfix"> <li class="clearfix">
<label class="panel-form-label fl">样例设置:</label> <label class="panel-form-label fl">样例设置:</label>
<ul class="fl task-bg-grey"> <ul class="fl task-bg-grey">
<% if @challenge.challenge_samples.count > 0 %> <% if @challenge_samples.count > 0 %>
<% @challenge.challenge_samples.each_with_index do |sample, index| %> <% @challenge_samples.each_with_index do |sample, index| %>
<li class="clearfix"> <li class="clearfix">
<p class="clearfix"> <p class="clearfix">
<span class="color-green fb">样例<%= index + 1 %></span> <span class="color-green fb">样例<%= index + 1 %></span>
@ -53,8 +54,8 @@
<li class="clearfix"> <li class="clearfix">
<label class="panel-form-label fl">测试集设置:</label> <label class="panel-form-label fl">测试集设置:</label>
<ul class="fl task-bg-grey"> <ul class="fl task-bg-grey">
<% if @challenge.test_sets.count > 0 %> <% if @test_sets.count > 0 %>
<% @challenge.test_sets.each_with_index do |test, index| %> <% @test_sets.each_with_index do |test, index| %>
<li class="clearfix"> <li class="clearfix">
<p class="clearfix"> <p class="clearfix">
<span class="color-green fb">测试集<%= index + 1 %></span> <span class="color-green fb">测试集<%= index + 1 %></span>
@ -69,26 +70,21 @@
</ul> </ul>
</li> </li>
<li class="clearfix"> <li class="clearfix">
<label class="panel-form-label fl"> 知识/技能点:</label> <% unless @challenge_tags.blank? %>
<div class="fl task-bd-grey"> <label class="panel-form-label fl"> 知识/技能点:</label>
<div class="task-tag tag-grey mb10 mr10 fl"> <div class="fl task-bd-grey">
使用交互模式的 Python3 解释器 <% @challenge_tags.each do |tag| %>
</div> <div class="task-tag tag-grey mb10 mr10 fl">
<div class="task-tag tag-grey mb10 mr10 fl"> <%= tag.name %>
简单使用 vim 编写脚本文件并执行这个脚本文件 </div>
</div> <% end %>
<div class="task-tag tag-grey mb10 mr10 fl"> </div>
Python 语法:缩进 <% end %>
</div>
<div class="task-tag tag-grey mb10 mr10 fl">
规范代码风格和注释
</div>
</div>
</li> </li>
<li class="clearfix"> <li class="clearfix">
<label class=" panel-form-label fl"> 参考答案:</label> <label class=" panel-form-label fl"> 参考答案:</label>
<div class="fl task-bg-grey"> <div class="fl task-bg-grey">
<%= @challenge.answer.blank? ? "无" : (h @challenge.answer.html_safe) %> <%= @challenge.answer.blank? ? "无" : (h @challenge.answer) %>
</div> </div>
</li> </li>
<li class="clearfix"> <li class="clearfix">
@ -106,34 +102,4 @@
</div> </div>
</div> </div>
<% if false %>
<div class="mt10 mb10" id ="issue_show_total">
<div class="banner-big f16 fontGrey3">
任务详情
<a href="<%= new_shixun_challenge_path(@shixun) %>" class="sy_btn_green fr" >新建</a>
</div>
<div class="container-big mt10" style="float:left;">
<div class="pro_page_box">
<div class="problem_main borderBottomNone">
<div id="issue_detail_show">
<%= @challenge.subject %>
</div>
<div>
<%= link_to "提交评测", {:controller => 'challenges', :action => "challenge_build", :id => @challenge, :shixun_id => @shixun}, :class => "task-display-span bBlue mt10", :onclick => "training_task_submmit();", :remote => true %>
</div>
</div>
<% unless @outputs.nil? %>
<% @outputs.each do |output| %>
<%= output %>
<% end %>
<% end %>
<!--problem_main end-->
<div style="clear: both;"></div>
</div>
</div>
<div class="cl"></div>
</div>
<% end %>

View File

@ -1,9 +0,0 @@
class CreateShixunTags < ActiveRecord::Migration
def change
create_table :shixun_tags do |t|
t.string :name
t.integer :game_id
t.timestamps
end
end
end

View File

@ -0,0 +1,8 @@
class RenameShixunTags < ActiveRecord::Migration
def up
rename_column :shixun_tags, :game_id, :challenge_id
end
def down
end
end

View File

@ -0,0 +1,10 @@
class CreateChallengeTags < ActiveRecord::Migration
def change
create_table :challenge_tags do |t|
t.string :name
t.integer :challenge_id
t.timestamps
end
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20170321102722) do ActiveRecord::Schema.define(:version => 20170322033103) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -338,6 +338,13 @@ ActiveRecord::Schema.define(:version => 20170321102722) do
t.integer "game_id" t.integer "game_id"
end end
create_table "challenge_tags", :force => true do |t|
t.string "name"
t.integer "challenge_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "challenges", :force => true do |t| create_table "challenges", :force => true do |t|
t.integer "shixun_id" t.integer "shixun_id"
t.string "subject" t.string "subject"
@ -2130,9 +2137,9 @@ ActiveRecord::Schema.define(:version => 20170321102722) do
create_table "shixun_tags", :force => true do |t| create_table "shixun_tags", :force => true do |t|
t.string "name" t.string "name"
t.integer "game_id" t.integer "challenge_id"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
create_table "shixuns", :force => true do |t| create_table "shixuns", :force => true do |t|

View File

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :challenge_tag do
name "MyString"
challenge_id 1
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ChallengeTag, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end