新建相关关联

This commit is contained in:
huang 2017-03-14 17:10:32 +08:00
parent a894e6c932
commit df1b1484f8
15 changed files with 213 additions and 153 deletions

View File

@ -21,9 +21,10 @@ class ChallengesController < ApplicationController
end
def create
@challenge.subject = params[:challenge][:subject]
@challenge.description = params[:challenge][:description]
@challenge.position = params[:challenge][:position].to_i
challenge_count = @shixun.challenges.count
@challenge = Challenge.new(params[:challenge])
@challenge.position = challenge_count + 1
@challenge.shixun = @shixun
@challenge.user = User.current
if @challenge.save
respond_to do |format|

View File

@ -2,18 +2,12 @@ class Challenge < ActiveRecord::Base
belongs_to :shixun,:touch=> true
belongs_to :user
has_many :shixun_comments
# has_many :journals, :as => :journalized, :dependent => :destroy
# has_many :visible_journals,
# :class_name => 'Journal',
# :as => :journalized,
# :conditions => Proc.new {
# ["(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(User.current, :view_private_notes)}))", false]
# },
# :readonly => true
# has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
# has_one :praise_tread_cache, as: :object, dependent: :destroy
has_many :challenge_samples, :dependent => :destroy
has_many :test_sets, :dependent => :destroy
validates_presence_of :subject
validates_presence_of :score
validates_presence_of :task_pass
validates_length_of :subject, :maximum => 255
end

View File

@ -0,0 +1,4 @@
class ChallengeSample < ActiveRecord::Base
attr_accessible :challenge_id, :input, :output
belongs_to :challenge
end

4
app/models/test_set.rb Normal file
View File

@ -0,0 +1,4 @@
class TestSet < ActiveRecord::Base
attr_accessible :challenge_id, :input, :output
belongs_to :challenge
end

View File

@ -1,37 +1,103 @@
<ul>
<li class="clear">
<label class="label"><span class="c_red f12">*</span>&nbsp;序号&nbsp;&nbsp;:&nbsp;</label>
<%= f.text_field :position, :no_label => true, :placeholder => "请输入序号(整数)" %>
</li>
<li class="clear">
<label class="label"><span class="c_red f12">*</span>&nbsp;标题&nbsp;&nbsp;:&nbsp;</label>
<%= f.text_field :subject, :class => "input-big", :no_label => true, :id => "training_task_id", :placeholder => "请输入标题" %>
<span style="display: none">标题不能为空</span>
</li>
<li class="clear">
<label class="label fl">&nbsp;描述&nbsp;&nbsp;:&nbsp;</label>
<%= f.label_for_field :description, :no_label => true, :class => "fl" %>
<%= f.kindeditor :description,
:editor_id => "training_task_desc_editor",
:width=>'885px',
:height =>192,
:resizeType => 0,
:no_label => true,
:at_id => @shixun.id,
:at_type => @shixun.class.to_s %>
</li>
<li class="clear">
<% if params[:action] == "new" %>
<a href="<%= shixun_challenges_path(@shixun, :remote => true) %>" class="sy_btn_grey mr5 fr"> 取消</a>
<% else %>
<%= link_to "取消", challenge_path(@challenge), :class => "sy_btn_grey mr5 fr" %>
<% end %>
<input onclick="issue_create();" class="sy_btn_blue mr5 fr" onfocus="this.blur()" id="issue_confirm" style="width: 28px;color: #FFF" value="保存">
</li>
</ul>
<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 panel-form-height-30 fl", :no_label => true, :placeholder => "请输入当前任务的名称(此信息将提前泄露给学员)" %>
</li>
<li class="clearfix">
<label class=" panel-form-label fl">预备知识:</label>
<%= f.text_area :ready_knowledge, :class => "panel-form-width-690 panel-form-height-150 fl task-textarea-pd", :no_label => true, :placeholder => "请输入完成当前任务依赖的知识点或者其它相关信息,指导学员完成任务" %>
</li>
<li class="clearfix">
<label class=" panel-form-label fl"><span class="c_red mr5">*</span>过关任务:</label>
<%= f.text_area :task_pass, :class => "panel-form-width-690 panel-form-height-150 fl task-textarea-pd", :no_label => true %>
</li>
<li class="clearfix">
<label class=" panel-form-label fl">样例设置:</label>
<ul class="fl task-bg-grey ">
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl">样例1</span>
<span class="color-grey fr" style="font-size:12px;">温馨提示:输入样例供学员参考。</span>
</p>
<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" placeholder="样例输入" />
<input type="text" class="panel-form-width-670 panel-form-height-30 " placeholder="样例输出" />
</li>
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl">样例2</span>
<a href="#" title="增加"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt12"></i></a>
<a href="#" title="删除"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt12"></i></a>
</p>
<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" placeholder="样例输入" />
<input type="text" class="panel-form-width-670 panel-form-height-30 " placeholder="样例输出" />
</li>
</ul>
</li>
<li class="clearfix">
<label class=" panel-form-label fl">测试集设置:</label>
<ul class="fl task-bg-grey ">
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl">测试1</span>
<span class="color-grey fr" style="font-size:12px;">温馨提示:在学员"提交评测"时进行自动检测。</span>
</p>
<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" placeholder="测试输入" />
<input type="text" class="panel-form-width-670 panel-form-height-30 " placeholder="测试输出" />
</li>
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl">测试2</span>
<a href="#" title="增加"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt12"></i></a>
<a href="#" title="删除"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt12"></i></a>
</p>
<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" placeholder="测试输入" />
<input type="text" class="panel-form-width-670 panel-form-height-30 " placeholder="测试输出" />
</li>
</ul>
</li>
<li class="clearfix">
<label class=" panel-form-label fl"> 知识/技能点:</label>
<div class="fl task-bd-grey">
<div class="task-tag tag-grey mb10 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button">×</button>
使用交互模式的 Python3 解释器
</div>
<div class="task-tag tag-grey mb10 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button">×</button>
简单使用 vim 编写脚本文件并执行这个脚本文件
</div>
<div class="task-tag tag-grey mb10 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button">×</button>
Python 语法:缩进
</div>
<div class="task-tag tag-grey mb10 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button">×</button>
规范代码风格和注释
</div>
<div class="task-tag tag-grey mb10 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button">×</button>
<input type="text" class=" task-tag-input" placeholder="请输入完成本任务得到的技能1个" />
</div>
<button class="close fl mt3 " type="button">+</button>
</div>
</li>
<li class="clearfix">
<label class=" panel-form-label fl"> 参考答案:</label>
<%= f.text_area :answer, :class => "panel-form-width-690 panel-form-height-150 fl task-textarea-pd", :no_label => true %>
</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;" %>
<!--<input type="text" class=" panel-form-height-30 fl " placeholder="25" style="padding:5px;" />-->
<span class="fl ml5">分</span>
</li>
<li class="clearfix">
<a class=" task-btn task-btn-green fr mr10" onclick="challenge_create()">保存</a>
<a href="#" class=" task-btn fr mr10">取消</a>
</li>
<script type="text/javascript">
function issue_create(){
training_task_desc_editor.sync();
function challenge_create(){
$('#new_challenge').submit();
}
$(function(){

View File

@ -10,101 +10,7 @@
<div class=" panel-form ">
<ul>
<%= labelled_form_for @challenge, :url => shixun_challenges_path(@shixun) do |f| %>
<li class="clearfix">
<label class=" panel-form-label fl"><span class="c_red mr5">*</span>名称:</label>
<input type="text" class="panel-form-width-690 panel-form-height-30 fl" placeholder="请输入当前任务的名称(此信息将提前泄露给学员)" />
</li>
<li class="clearfix">
<label class=" panel-form-label fl">预备知识:</label>
<textarea class="panel-form-width-690 panel-form-height-150 fl task-textarea-pd" placeholder="请输入完成当前任务依赖的知识点或者其它相关信息,指导学员完成任务"></textarea>
</li>
<li class="clearfix">
<label class=" panel-form-label fl"><span class="c_red mr5">*</span>过关任务:</label>
<textarea class="panel-form-width-690 panel-form-height-150 fl task-textarea-pd"></textarea>
</li>
<li class="clearfix">
<label class=" panel-form-label fl">样例设置:</label>
<ul class="fl task-bg-grey ">
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl">样例1</span>
<span class="color-grey fr" style="font-size:12px;">温馨提示:输入样例供学员参考。</span>
</p>
<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" placeholder="样例输入" />
<input type="text" class="panel-form-width-670 panel-form-height-30 " placeholder="样例输出" />
</li>
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl">样例2</span>
<a href="#" title="增加"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt12"></i></a>
<a href="#" title="删除"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt12"></i></a>
</p>
<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" placeholder="样例输入" />
<input type="text" class="panel-form-width-670 panel-form-height-30 " placeholder="样例输出" />
</li>
</ul>
</li>
<li class="clearfix">
<label class=" panel-form-label fl">测试集设置:</label>
<ul class="fl task-bg-grey ">
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl">测试1</span>
<span class="color-grey fr" style="font-size:12px;">温馨提示:在学员"提交评测"时进行自动检测。</span>
</p>
<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" placeholder="测试输入" />
<input type="text" class="panel-form-width-670 panel-form-height-30 " placeholder="测试输出" />
</li>
<li class="clearfix">
<p class="clearfix">
<span class="color-green fb fl">测试2</span>
<a href="#" title="增加"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt12"></i></a>
<a href="#" title="删除"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt12"></i></a>
</p>
<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" placeholder="测试输入" />
<input type="text" class="panel-form-width-670 panel-form-height-30 " placeholder="测试输出" />
</li>
</ul>
</li>
<li class="clearfix">
<label class=" panel-form-label fl"> 知识/技能点:</label>
<div class="fl task-bd-grey">
<div class="task-tag tag-grey mb10 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button">×</button>
使用交互模式的 Python3 解释器
</div>
<div class="task-tag tag-grey mb10 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button">×</button>
简单使用 vim 编写脚本文件并执行这个脚本文件
</div>
<div class="task-tag tag-grey mb10 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button">×</button>
Python 语法:缩进
</div>
<div class="task-tag tag-grey mb10 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button">×</button>
规范代码风格和注释
</div>
<div class="task-tag tag-grey mb10 mr10 fl">
<button data-dismiss="alert" class="close fr mt3 ml5" type="button">×</button>
<input type="text" class=" task-tag-input" placeholder="请输入完成本任务得到的技能1个" />
</div>
<button class="close fl mt3 " type="button">+</button>
</div>
</li>
<li class="clearfix">
<label class=" panel-form-label fl"> 参考答案:</label>
<textarea class="panel-form-width-690 panel-form-height-150 fl task-textarea-pd"></textarea>
</li>
<li class="clearfix">
<label class=" panel-form-label fl"><span class="c_red mr5">*</span>分值设定:</label>
<input type="text" class=" panel-form-height-30 fl " placeholder="25" style="padding:5px;" />
<span class="fl ml5">分</span>
</li>
<li class="clearfix">
<a href="#" class=" task-btn task-btn-green fr mr10">保存</a>
<a href="#" class=" task-btn fr mr10">取消</a>
</li>
<%= render :partial => "form", :locals => {:f => f} %>
<% end %>
</ul>
</div>
@ -119,7 +25,6 @@
<%#= call_hook(:view_issues_new_top, {:training_task => @training_task}) %>
<%= labelled_form_for @challenge, :url => shixun_challenges_path(@shixun) do |f| %>
<%= error_messages_for 'training_task' %>
<%= hidden_field_tag 'copy_from', params[:copy_from] if params[:copy_from] %>
<div>
<%= render :partial => 'form', :locals => {:f => f} %>
</div>

View File

@ -0,0 +1,8 @@
class AddReadyKnowledgeToChallenges < ActiveRecord::Migration
def change
add_column :challenges, :ready_knowledge, :text
add_column :challenges, :task_pass, :text
add_column :challenges, :answer, :text
add_column :challenges, :score, :integer
end
end

View File

@ -0,0 +1,5 @@
class AddVisitsToChallenges < ActiveRecord::Migration
def change
add_column :challenges, :visits, :integer, :default => 0
end
end

View File

@ -0,0 +1,11 @@
class CreateChallengeSamples < ActiveRecord::Migration
def change
create_table :challenge_samples do |t|
t.string :input
t.string :output
t.integer :challenge_id
t.timestamps
end
end
end

View File

@ -0,0 +1,11 @@
class CreateTestSets < ActiveRecord::Migration
def change
create_table :test_sets do |t|
t.string :input
t.string :output
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.
ActiveRecord::Schema.define(:version => 20170310072101) do
ActiveRecord::Schema.define(:version => 20170314085929) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -329,15 +329,28 @@ ActiveRecord::Schema.define(:version => 20170310072101) do
t.datetime "updated_at", :null => false
end
create_table "challenge_samples", :force => true do |t|
t.string "input"
t.string "output"
t.integer "challenge_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "challenges", :force => true do |t|
t.integer "shixun_id"
t.string "subject"
t.text "description"
t.integer "user_id"
t.integer "status", :limit => 1, :default => 0
t.integer "position", :limit => 1, :default => 1
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "status", :limit => 1, :default => 0
t.integer "position", :limit => 1, :default => 1
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "ready_knowledge"
t.text "task_pass"
t.text "answer"
t.integer "score"
t.integer "visits", :default => 0
end
create_table "changes", :force => true do |t|
@ -2090,17 +2103,21 @@ ActiveRecord::Schema.define(:version => 20170310072101) do
t.string "name"
t.text "description"
t.text "script"
t.boolean "is_public", :default => true
t.boolean "is_public", :default => true
t.integer "parent_id"
t.integer "user_id"
t.integer "gpid"
t.integer "forked_count", :default => 0
t.integer "visits", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "forked_count", :default => 0
t.integer "visits", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "changeset_num"
t.integer "forked_form"
t.integer "status", :default => 0
t.integer "status", :default => 0
t.text "ready_knowledge"
t.text "task_pass"
t.text "answer"
t.integer "score"
end
create_table "softapplications", :force => true do |t|
@ -2339,6 +2356,14 @@ ActiveRecord::Schema.define(:version => 20170310072101) do
t.string "extra"
end
create_table "test_sets", :force => true do |t|
t.string "input"
t.string "output"
t.integer "challenge_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "time_entries", :force => true do |t|
t.integer "project_id", :null => false
t.integer "user_id", :null => false

View File

@ -0,0 +1,8 @@
FactoryGirl.define do
factory :challenge_sample do
input "MyString"
output "MyString"
challenge_id 1
end
end

View File

@ -0,0 +1,8 @@
FactoryGirl.define do
factory :test_set do
input "MyString"
output "MyString"
challenge_id 1
end
end

View File

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

View File

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