基础数据加上“专业”、“课程”,实训的适用专业和课程

This commit is contained in:
cxt 2017-07-06 17:52:59 +08:00
parent fc9b20cc61
commit 7b9c59d6e8
31 changed files with 510 additions and 128 deletions

View File

@ -4,7 +4,7 @@ class ShixunsController < ApplicationController
layout 'base_shixun' layout 'base_shixun'
before_filter :require_login before_filter :require_login
before_filter :check_authentication before_filter :check_authentication
before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search ] before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search, :shixun_courses]
before_filter :shixun_view_allow, :only => [:show] before_filter :shixun_view_allow, :only => [:show]
before_filter :require_manager, :only => [ :settings, :add_script, :publish, :collaborators_delete, :shixun_members_added, :add_collaborators] before_filter :require_manager, :only => [ :settings, :add_script, :publish, :collaborators_delete, :shixun_members_added, :add_collaborators]
#skip_before_filter :verify_authenticity_token, :only => :update_propaedeutics #skip_before_filter :verify_authenticity_token, :only => :update_propaedeutics
@ -288,6 +288,28 @@ class ShixunsController < ApplicationController
end end
end end
def shixun_courses
data = {result:0,options:[]}
if params[:major_id] != 0
major = Major.find params[:major_id]
if major
data[:result] = 1
major_courses = major.major_courses
CourseList.where(:id => major_courses.map(&:course_list_id)).each do |course|
option = []
option << course.name.to_s
option << course.id
data[:options] << option
end
else
data[:result] = 0
end
else
data[:result] = 0
end
render :json =>data
end
def new def new
@shixun = Shixun.new @shixun = Shixun.new
@ -303,7 +325,14 @@ class ShixunsController < ApplicationController
@shixun = Shixun.new(params[:shixun]) @shixun = Shixun.new(params[:shixun])
@shixun.user_id = User.current.id @shixun.user_id = User.current.id
@shixun.language = params[:language] @shixun.language = params[:language]
@shixun.major_id = params[:major_id]
@shixun.trainee = params[:trainee]
@shixun.identifier = identifier @shixun.identifier = identifier
if params[:course_id]
params[:course_id].each do |course_id|
@shixun.shixun_major_courses << ShixunMajorCourse.new(:major_id => params[:major_id], :course_list_id => course_id)
end
end
(params[:shixun][:is_public] == "1" ? @shixun.is_public = true : @shixun.is_public = false) (params[:shixun][:is_public] == "1" ? @shixun.is_public = true : @shixun.is_public = false)
respond_to do |format| respond_to do |format|
if @shixun.save if @shixun.save
@ -359,6 +388,13 @@ class ShixunsController < ApplicationController
language = @shixun.language language = @shixun.language
@shixun.attributes = params[:shixun] @shixun.attributes = params[:shixun]
@shixun.language = params[:language] @shixun.language = params[:language]
@shixun.trainee = params[:trainee]
if params[:course_id]
params[:course_id].each do |course_id|
@shixun.shixun_major_courses << ShixunMajorCourse.new(:major_id => params[:major_id], :course_list_id => course_id)
end
end
@shixun.major_id = params[:major_id]
params[:shixun][:is_public] == "on" ? @shixun.is_public = 1 : @shixun.is_public = 0 params[:shixun][:is_public] == "on" ? @shixun.is_public = 1 : @shixun.is_public = 0
if @shixun.save if @shixun.save
# 实训语言更改了会影响后续的评测所以需要更新is_updated # 实训语言更改了会影响后续的评测所以需要更新is_updated

View File

@ -157,6 +157,28 @@ module ApplicationHelper
["Java", "C", "C++", "Python", "MySQL/Java"] ["Java", "C", "C++", "Python", "MySQL/Java"]
end end
# 实训试用专业
def shixun_major_option
content = []
content << ["选择实训适用的专业", 0]
content << ["计算机科学与技术", 635]
content << ["软件工程", 636]
content << ["网络工程", 637]
content << ["信息安全", 638]
content << ["物联网工程", 639]
content << ["信息工程", 622]
content << ["通信工程", 619]
end
# 实训面向学员
def shixun_trainee
content = []
content << ["初级学员", 1]
content << ["中级学员", 2]
content << ["高级学员", 3]
content << ["顶级学员", 4]
end
# 班级设置排序中文 # 班级设置排序中文
def switch_to_chinese word def switch_to_chinese word
case word case word

View File

@ -0,0 +1,5 @@
class CourseList < ActiveRecord::Base
has_many :major_courses
has_many :shixun_major_courses
attr_accessible :name
end

View File

@ -2,4 +2,5 @@ class DisciplineCategory < ActiveRecord::Base
attr_accessible :major_level, :name attr_accessible :major_level, :name
has_many :first_level_disciplines has_many :first_level_disciplines
has_many :majors
end end

View File

@ -2,4 +2,5 @@ class FirstLevelDiscipline < ActiveRecord::Base
belongs_to :discipline_category belongs_to :discipline_category
attr_accessible :name attr_accessible :name
has_many :syllabuses has_many :syllabuses
has_many :majors
end end

7
app/models/major.rb Normal file
View File

@ -0,0 +1,7 @@
class Major < ActiveRecord::Base
belongs_to :first_level_discipline
belongs_to :discipline_category
has_many :major_courses
has_many :shixun_major_courses
attr_accessible :major_code, :major_level, :name, :first_level_discipline_id, :discipline_category_id
end

View File

@ -0,0 +1,5 @@
class MajorCourse < ActiveRecord::Base
belongs_to :course_list
belongs_to :major
attr_accessible :course_list_id, :major_id
end

View File

@ -1,3 +1,4 @@
# encoding: utf-8
# status 控制实训的状态0编辑1: 申请发布; 2正式发布 3关闭 # status 控制实训的状态0编辑1: 申请发布; 2正式发布 3关闭
# is_updated 字段为1表示实训的更改可能会影响到后续的评测0表示更改不会影响后续的评测 # is_updated 字段为1表示实训的更改可能会影响到后续的评测0表示更改不会影响后续的评测
# 繁忙等级参数80发布实训失败返回code为-181实训开启的时候fork失败;83开启实训的时候openGameInstance返回非0值84jenkins系统异常post数据不成功 # 繁忙等级参数80发布实训失败返回code为-181实训开启的时候fork失败;83开启实训的时候openGameInstance返回非0值84jenkins系统异常post数据不成功
@ -15,6 +16,9 @@ class Shixun < ActiveRecord::Base
has_many :homework_commons_shixunses has_many :homework_commons_shixunses
has_many :challenges, :dependent => :destroy, :order => "challenges.id ASC" has_many :challenges, :dependent => :destroy, :order => "challenges.id ASC"
has_many :myshixuns has_many :myshixuns
belongs_to :major
belongs_to :major_course
has_many :shixun_major_courses
has_and_belongs_to_many :homework_commons has_and_belongs_to_many :homework_commons
# 获取特定格式的实训测试用例 # 获取特定格式的实训测试用例
@ -48,6 +52,21 @@ class Shixun < ActiveRecord::Base
identifier identifier
end end
def shixun_trainee
trainee = ""
case self.trainee
when 1
trainee = "初级学员"
when 2
trainee = "中级学员"
when 3
trainee = "高级学员"
when 4
trainee = "顶级学员"
end
trainee
end
def owner def owner
User.find(self.user_id) User.find(self.user_id)
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound

View File

@ -0,0 +1,6 @@
class ShixunMajorCourse < ActiveRecord::Base
belongs_to :shixun
belongs_to :major
belongs_to :course_list
#attr_accessible :course_list
end

View File

@ -13,6 +13,22 @@
<%= javascript_include_tag "edu/application",'edu/base_edu','baiduTemplate','jquery.datetimepicker.js','edu/course','attachments' %> <%= javascript_include_tag "edu/application",'edu/base_edu','baiduTemplate','jquery.datetimepicker.js','edu/course','attachments' %>
<%= call_hook :view_layouts_base_html_head %> <%= call_hook :view_layouts_base_html_head %>
<%= yield :header_tags -%> <%= yield :header_tags -%>
<script type="text/javascript"
src="/javascripts/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!--<script type="text/javascript"-->
<!--src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">-->
<!--</script>-->
<!-- 配置 在生成的公式图片上去掉Math定义的右键菜单$$ $$ \( \) \[ \] 中的公式给予显示-->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showMathMenu: false,
showMathMenuMSIE: false,
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
</head> </head>
<body onload="prettyPrint();"> <body onload="prettyPrint();">
<div class="newContainer"> <!-- 页面全部内容 --> <div class="newContainer"> <!-- 页面全部内容 -->

View File

@ -1,5 +1,5 @@
<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %> <%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %>
<%= javascript_include_tag '/editormd/editormd.min.js','/editormd/examples/js/jquery.min.js' %> <%= javascript_include_tag '/editormd/editormd.min.js' %>
<div class="edu-con-bg01 " style="padding:30px 0;"> <div class="edu-con-bg01 " style="padding:30px 0;">
<div class="ml30 mr30"> <div class="ml30 mr30">
<div> <div>
@ -34,34 +34,32 @@
<div class="cl"></div> <div class="cl"></div>
</li> </li>
<li class="clearfix mb15"> <li class="clearfix mb15">
<label class="panel-form-label fl">适用专业&nbsp;&nbsp;&nbsp;</label> <label class="panel-form-label fl"><span class="color-orange mr5">*</span>适用专业&nbsp;&nbsp;&nbsp;</label>
<%= select_tag :major, options_for_select(shixun_language, "Java"), :id => 'shixun[major]', :class => "fl task-form-30 task-height-40"%> <%= select_tag :major_id, options_for_select(shixun_major_option, 0), :id => 'shixun_major', :class => "fl task-form-30 task-height-40"%>
<div class="cl"></div>
<p class="-text-danger ml115" id="shixun_major_notice" style="display: none;">请选择适用专业</p>
</li> </li>
<li class="clearfix mb15 pr"> <li class="clearfix mb15 pr">
<label class="panel-form-label fl">适用课程&nbsp;&nbsp;&nbsp;</label> <label class="panel-form-label fl"><span class="color-orange mr5">*</span>适用课程&nbsp;&nbsp;&nbsp;</label>
<div id="shixun[lesson]" class="fl task-form-28 task-height-40 lesson pr" onclick="checkLesson(this);"> <div id="shixun[lesson]" class="fl task-form-28 task-height-40 lesson pr" onclick="checkLesson(this);">
<input type="text" class="lesson_content" placeholder="选择实训适用的课程"> <input type="text" class="lesson_content" placeholder="选择实训适用的课程">
<img src="../images/textarea.png" class="lesson_img"/> <i class="fa fa-sort-desc lesson_img"></i>
<ul class="lesson_checkbox" showul="0"> <ul class="lesson_checkbox" showul="0">
<li><input type="checkbox" name="role[]" value="离散数学" id="join_course_role_0" class="ml-3 mr5 magic-checkbox"><label for="join_course_role_0">离散数学</label></li>
<li><input type="checkbox" name="role[]" value="数据结构" id="join_course_role_1" class="ml-3 mr5 magic-checkbox"><label for="join_course_role_1">数据结构</label></li>
<li><input type="checkbox" name="role[]" value="计算机思维导论" id="join_course_role_2" class="ml-3 mr5 magic-checkbox"><label for="join_course_role_2">计算机思维导论</label></li>
<li><input type="checkbox" name="role[]" value="算法分析" id="join_course_role_3" class="ml-3 mr5 magic-checkbox"><label for="join_course_role_3">算法分析</label></li>
<li><input type="checkbox" name="role[]" value="数字逻辑" id="join_course_role_4" class="ml-3 mr5 magic-checkbox"><label for="join_course_role_4">数字逻辑</label></li>
<li><input type="checkbox" name="role[]" value="自然语言处理" id="join_course_role_5" class="ml-3 mr5 magic-checkbox"><label for="join_course_role_5">自然语言处理</label></li>
</ul> </ul>
</div> </div>
<div class="cl"></div>
<p class="-text-danger ml115" id="shixun_major_course_notice" style="display: none;">请选择适用课程</p>
</li> </li>
<li class="clearfix mb15"> <li class="clearfix mb15">
<label class="panel-form-label fl">面向学员&nbsp;&nbsp;&nbsp;</label> <label class="panel-form-label fl"><span class="color-orange mr5">*</span>面向学员&nbsp;&nbsp;&nbsp;</label>
<%= select_tag :student, options_for_select(shixun_language, "Java"), :id => 'shixun[student]', :class => "fl task-form-10 task-height-40" %> <%= select_tag :trainee, options_for_select(shixun_trainee, 0), :id => 'shixun_trainee', :class => "fl task-form-10 task-height-40" %>
</li> </li>
<li class="clearfix mb15"> <li class="clearfix mb15">
<label class="panel-form-label fl">语言&nbsp;&nbsp;&nbsp;</label> <label class="panel-form-label fl"><span class="color-orange mr5">*</span>技术平台&nbsp;&nbsp;&nbsp;</label>
<%= select_tag :language, options_for_select(shixun_language, "Java"), :id => 'shixun[language]', :class => "fl task-form-10 task-height-40" %> <%= select_tag :language, options_for_select(shixun_language, "Java"), :id => 'shixun_language', :class => "fl task-form-10 task-height-40" %>
</li> </li>
<li class="clearfix"> <li class="clearfix">
<a href="javascript:void(0)" class="task-btn task-btn-blue fr" onclick="submit_new_project();" >提交</a> <a href="javascript:void(0)" class="task-btn task-btn-blue fr" onclick="submit_new_project();">提交</a>
<%= link_to "取消",user_activities_path(User.current.id),:class => "task-btn fr mr10" %> <%= link_to "取消",user_activities_path(User.current.id),:class => "task-btn fr mr10" %>
</li> </li>
<% end %> <% end %>
@ -69,15 +67,6 @@
</div> </div>
</div> </div>
</div> </div>
<style>
.task-form-28{width: 28%;padding:0px 10px}
.lesson{border:1px solid #EEEEEE;line-height:40px;}
.lesson_img{position: absolute;right: 5px;top:15px;}
.lesson_checkbox{display: none;position: absolute;top:40px;left: -1px;width: 100%;border:1px solid #eeeeee;background: #FFFFFF;padding-bottom: 5px;height: 150px;}
.lesson_checkbox li{height:20px;padding:5px 10px;clear:both;line-height:28px;}
.lesson_checkbox li input{float: left;margin: 3px 5px 0px 0px;}
.lesson_content{height: 100%;border:none;width:96%;outline: none;}
</style>
<script> <script>
/* ------------------------------- 简介md ------------------------------*/ /* ------------------------------- 简介md ------------------------------*/
var shixun_editormd = editormd("shixun_introduction", { var shixun_editormd = editormd("shixun_introduction", {
@ -136,113 +125,106 @@
imageUploadURL : "<%= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>" //url imageUploadURL : "<%= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>" //url
}); });
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
//新建项目
//验证项目名称
function regex_project_name()
{
var name = $.trim($("#shixun_name").val());
if(name.length == 0)
{
$("#project_name_notice").show();
return false;
}
else
{
$("#project_name_notice").hide();
return true;
}
}
//提交新建项目 //提交新建项目
function submit_new_project() function submit_new_project()
{ {
if(regex_project_name()) if(regex_shixun_name() && regex_major() && regex_major_course())
{ {
$("#new_shixun").submit(); $("#new_shixun").submit();
} }
} }
window.onload = function(){
$("#shixun_introduction [type=\"latex\"]").bind("click", function(){
shixun_editormd.cm.replaceSelection("```latex");
shixun_editormd.cm.replaceSelection("\n");
shixun_editormd.cm.replaceSelection("\n");
shixun_editormd.cm.replaceSelection("```");
var __Cursor = shixun_editormd.cm.getDoc().getCursor();
shixun_editormd.cm.setCursor(__Cursor.line-1, 0);
});
function checkLesson(item){ $("#shixun_propaedeutics [type=\"latex\"]").bind("click", function(){
var showul=$(item).find("ul").attr("showul"); shixun_propaedeutics.cm.replaceSelection("```latex");
if(showul=="0"){ shixun_propaedeutics.cm.replaceSelection("\n");
$(item).find("ul").show(); shixun_propaedeutics.cm.replaceSelection("\n");
$(item).find("ul").attr("showul","1"); shixun_propaedeutics.cm.replaceSelection("```");
if($(item).find("ul input").length>5){ var __Cursor = shixun_propaedeutics.cm.getDoc().getCursor();
$(item).find("ul").css("overflow-y","scroll"); shixun_propaedeutics.cm.setCursor(__Cursor.line-1, 0);
} });
event.stopPropagation();
}else{ $("#shixun_introduction [type=\"inline\"]").bind("click", function(){
$(item).find("ul").hide(); shixun_editormd.cm.replaceSelection("$$$$");
$(item).find("ul").attr("showul","0"); var __Cursor = shixun_editormd.cm.getDoc().getCursor();
event.stopPropagation(); shixun_editormd.cm.setCursor(__Cursor.line, __Cursor.ch-2);
} shixun_editormd.cm.focus();
} });
$("#shixun_propaedeutics [type=\"inline\"]").bind("click", function(){
shixun_propaedeutics.cm.replaceSelection("$$$$");
var __Cursor = shixun_propaedeutics.cm.getDoc().getCursor();
shixun_propaedeutics.cm.setCursor(__Cursor.line, __Cursor.ch-2);
shixun_propaedeutics.cm.focus();
});
$("[type=\"inline\"]").attr("title", "行内公式");
$("[type=\"latex\"]").attr("title", "多行公式");
};
$(function(){ $(function(){
//多选适用课程 //多选适用课程
$("body").click(function(event){ $("body").click(function(event){
$(".lesson_checkbox").hide(); $(".lesson_checkbox").hide();
$(".lesson_checkbox").attr("showul","0"); $(".lesson_checkbox").attr("showul","0");
event.stopPropagation(); event.stopPropagation();
}) });
$(".lesson_checkbox label").click(function(event){ $(".lesson_checkbox").on('click', 'label', function(event) {
event.stopPropagation(); event.stopPropagation();
}) });
$(".lesson_checkbox input").click(function(event){ $(".lesson_checkbox").on('click', 'input',function(event) {
if($(this).is(':checked')){ if ($(this).is(':checked')) {
if($(".lesson_content").val()==""){ if ($(".lesson_content").val() == "") {
$(".lesson_content").val($(this).attr("value")); $(".lesson_content").val($(this).attr("data-val"));
}else{ } else {
$(".lesson_content").val($(".lesson_content").val()+","+$(this).attr("value")); $(".lesson_content").val($(".lesson_content").val() + "," + $(this).attr("data-val"));
} }
event.stopPropagation(); event.stopPropagation();
}else{ } else {
var valueCon=$(".lesson_content").val().split(","); var valueCon = $(".lesson_content").val().split(",");
var list=[]; var list = [];
for(var i=0;i<valueCon.length;i++){ for (var i = 0; i < valueCon.length; i++) {
if(valueCon[i]!=$(this).attr("value")){ if (valueCon[i] != $(this).attr("data-val")) {
list.push(valueCon[i]); list.push(valueCon[i]);
} }
} }
$(".lesson_content").val(list); $(".lesson_content").val(list);
event.stopPropagation(); event.stopPropagation();
} }
})
})
window.onload = function(){
$("#shixun_introduction [type=\"latex\"]").bind("click", function(){
shixun_editormd.cm.replaceSelection("```latex");
shixun_editormd.cm.replaceSelection("\n");
shixun_editormd.cm.replaceSelection("\n");
shixun_editormd.cm.replaceSelection("```");
var __Cursor = shixun_editormd.cm.getDoc().getCursor();
shixun_editormd.cm.setCursor(__Cursor.line-1, 0);
}); });
});
$("#shixun_propaedeutics [type=\"latex\"]").bind("click", function(){ $("#shixun_major").on("change", function(){
shixun_propaedeutics.cm.replaceSelection("```latex"); if($("#shixun_major").val() != "0"){
shixun_propaedeutics.cm.replaceSelection("\n"); $.ajax({
shixun_propaedeutics.cm.replaceSelection("\n"); url: '/shixuns/shixun_courses',
shixun_propaedeutics.cm.replaceSelection("```"); type: 'get',
var __Cursor = shixun_propaedeutics.cm.getDoc().getCursor(); data: {major_id:$("#shixun_major").val()},
shixun_propaedeutics.cm.setCursor(__Cursor.line-1, 0); success: function(data){
}); if (data.result == 1){
$(".lesson_content").val("");
$("#shixun_introduction [type=\"inline\"]").bind("click", function(){ $(".lesson_checkbox").html("");
shixun_editormd.cm.replaceSelection("$$$$"); for(var i=0; i<data.options.length; i++){
var __Cursor = shixun_editormd.cm.getDoc().getCursor(); $(".lesson_checkbox").append('<li><input type="checkbox" name="course_id[]" data-val="'+ data.options[i][0] +'" value="'+ data.options[i][1] +'" id="join_course_role_'+ i +'" class="ml-3 mr5 magic-checkbox"><label for="join_course_role_'+ i +'">'+ data.options[i][0] +'</label></li>');
shixun_editormd.cm.setCursor(__Cursor.line, __Cursor.ch-2); }
shixun_editormd.cm.focus(); $("#shixun_major_notice").hide();
}); }
else{
$("#shixun_propaedeutics [type=\"inline\"]").bind("click", function(){ $(".lesson_content").val("");
shixun_propaedeutics.cm.replaceSelection("$$$$"); $(".lesson_checkbox").html("");
var __Cursor = shixun_propaedeutics.cm.getDoc().getCursor(); }
shixun_propaedeutics.cm.setCursor(__Cursor.line, __Cursor.ch-2); }
shixun_propaedeutics.cm.focus(); });
}); } else{
$("[type=\"inline\"]").attr("title", "行内公式"); $(".lesson_content").val("");
$("[type=\"latex\"]").attr("title", "多行公式"); $(".lesson_checkbox").html("");
}
} });
</script> </script>

View File

@ -18,8 +18,29 @@
<textarea name="shixun[propaedeutics]"><%#= @shixun.propaedeutics %></textarea> <textarea name="shixun[propaedeutics]"><%#= @shixun.propaedeutics %></textarea>
</div> </div>
</li>--> </li>-->
<li class="clearfix mb15">
<label class="panel-form-label fl"><span class="color-orange mr5">*</span>适用专业&nbsp;&nbsp;&nbsp;</label>
<%= select_tag :major_id, options_for_select(shixun_major_option, @shixun.major_id ? @shixun.major_id : 0), :id => 'shixun_major', :class => "fl task-form-30 task-height-40"%>
<div class="cl"></div>
<p class="-text-danger ml95" id="shixun_major_notice" style="display: none;">请选择适用专业</p>
</li>
<li class="clearfix pr">
<label class="panel-form-label fl"><span class="color-orange mr5">*</span>适用课程&nbsp;&nbsp;&nbsp;</label>
<div id="shixun[lesson]" class="fl task-form-28 task-height-40 lesson pr" onclick="checkLesson(this);">
<input type="text" class="lesson_content" placeholder="选择实训适用的课程">
<i class="fa fa-sort-desc lesson_img"></i>
<ul class="lesson_checkbox" showul="0">
</ul>
</div>
<div class="cl"></div>
<p class="-text-danger ml95" id="shixun_major_course_notice" style="display: none;">请选择适用课程</p>
</li>
<li class="clearfix"> <li class="clearfix">
<label class="panel-form-label fl">语言:</label> <label class="panel-form-label fl"><span class="color-orange mr5">*</span>面向学员&nbsp;&nbsp;&nbsp;</label>
<%= select_tag :trainee, options_for_select(shixun_trainee, @shixun.trainee), :id => 'shixun_trainee', :class => "fl task-form-10 task-height-40" %>
</li>
<li class="clearfix">
<label class="panel-form-label fl"><span class="color-orange mr5">*</span>技术平台:</label>
<%= select_tag :language, options_for_select(shixun_language, @shixun.language), :id => 'shixun[language]', :class => "fl task-form-10 task-height-40" %> <%= select_tag :language, options_for_select(shixun_language, @shixun.language), :id => 'shixun[language]', :class => "fl task-form-10 task-height-40" %>
</li> </li>
<!-- <li class="clearfix"> <!-- <li class="clearfix">
@ -28,32 +49,89 @@
<span class="fl" style="line-height: 40px;">(选中为公开实训,不选中为私有实训;私有实训仅自己可见。)</span> <span class="fl" style="line-height: 40px;">(选中为公开实训,不选中为私有实训;私有实训仅自己可见。)</span>
</li>--> </li>-->
<li class="clearfix"> <li class="clearfix">
<a href="javascript:void(0)" class="task-btn task-btn-green fr " onclick="submit_edit_shixun(<%= @shixun.id %>);" >保存</a> <a href="javascript:void(0)" class="task-btn task-btn-green fr " onclick="submit_edit_shixun(<%= @shixun.id %>);">保存</a>
</li> </li>
<% end %> <% end %>
</ul> </ul>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
function regex_shixun_name() {
var name = $.trim($("#shixun_name").val());
if (name.length == 0) {
$("#project_name_notice").show();
return false;
}
else {
$("#project_name_notice").hide();
return true;
}
}
//配置-信息提交 //配置-信息提交
function submit_edit_shixun(id) { function submit_edit_shixun(id) {
if (regex_shixun_name()) { if (regex_shixun_name() && regex_major() && regex_major_course()) {
$("#edit_shixun_" + id).submit(); $("#edit_shixun_" + id).submit();
} }
} }
$(function(){
<% if @shixun.major_id %>
<% major_courses = @shixun.major.major_courses %>
<% CourseList.where(:id => major_courses.map(&:course_list_id)).each_with_index do |course, index| %>
$(".lesson_checkbox").append('<li><input type="checkbox" name="course_id[]" data-val="<%= course.name %>" value="<%= course.id %>" id="join_course_role_<%= index %>" class="ml-3 mr5 magic-checkbox"><label for="join_course_role_<%= index %>"><%= course.name %></label></li>');
<% end %>
<% @shixun.shixun_major_courses.each_with_index do |shixun_course, index| %>
$(".lesson_content").val($(".lesson_content").val() + "<%= index == 0 ? '' : ',' %>" + "<%= shixun_course.course_list.name %>");
$("input[value='<%= shixun_course.course_list_id %>']").attr("checked", true);
<% end %>
<% end %>
//多选适用课程
$("body").click(function(event){
$(".lesson_checkbox").hide();
$(".lesson_checkbox").attr("showul","0");
event.stopPropagation();
});
$(".lesson_checkbox").on('click', 'label', function(event) {
event.stopPropagation();
});
$(".lesson_checkbox").on('click', 'input',function(event) {
if ($(this).is(':checked')) {
if ($(".lesson_content").val() == "") {
$(".lesson_content").val($(this).attr("data-val"));
} else {
$(".lesson_content").val($(".lesson_content").val() + "," + $(this).attr("data-val"));
}
event.stopPropagation();
} else {
var valueCon = $(".lesson_content").val().split(",");
var list = [];
for (var i = 0; i < valueCon.length; i++) {
if (valueCon[i] != $(this).attr("data-val")) {
list.push(valueCon[i]);
}
}
$(".lesson_content").val(list);
event.stopPropagation();
}
});
});
$("#shixun_major").on("change", function(){
if($("#shixun_major").val() != "0"){
$.ajax({
url: '/shixuns/shixun_courses',
type: 'get',
data: {major_id:$("#shixun_major").val()},
success: function(data){
if (data.result == 1){
$(".lesson_content").val("");
$(".lesson_checkbox").html("");
for(var i=0; i<data.options.length; i++){
$(".lesson_checkbox").append('<li><input type="checkbox" name="course_id[]" data-val="'+ data.options[i][0] +'" value="'+ data.options[i][1] +'" id="join_course_role_'+ i +'" class="ml-3 mr5 magic-checkbox"><label for="join_course_role_'+ i +'">'+ data.options[i][0] +'</label></li>');
}
$("#shixun_major_notice").hide();
}
else{
$(".lesson_content").val("");
$(".lesson_checkbox").html("");
}
}
});
} else{
$(".lesson_content").val("");
$(".lesson_checkbox").html("");
}
});
/* ----------------------------------- 预备知识Md ----------------------------------------- */ /* ----------------------------------- 预备知识Md ----------------------------------------- */
/* var p_editormd = editormd("setting_propaedeutics", { /* var p_editormd = editormd("setting_propaedeutics", {
width : "89.7%", width : "89.7%",

View File

@ -22,7 +22,25 @@
</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 panel-box-sizing panel-form-width-690">
<%= @shixun.major ? @shixun.major.try(:name) : "" %>
</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">
<%= @shixun.shixun_major_courses.blank? ? "" : CourseList.where(:id => @shixun.shixun_major_courses.map(&:course_list_id)).map(&:name).join(",") %>
</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">
<%= @shixun.shixun_trainee %>
</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"> <div class="fl task-bg-grey panel-box-sizing panel-form-width-690">
<%= @shixun.language %> <%= @shixun.language %>
</div> </div>

View File

@ -58,6 +58,7 @@ RedmineApp::Application.routes.draw do
get 'operation' get 'operation'
end end
collection do collection do
get 'shixun_courses'
match 'search', :via => [:get, :post] match 'search', :via => [:get, :post]
end end

View File

@ -0,0 +1,13 @@
class CreateMajors < ActiveRecord::Migration
def change
create_table :majors do |t|
t.string :major_code
t.string :name
t.references :first_level_discipline
t.references :discipline_category
t.integer :major_level
end
add_index :majors, :first_level_discipline_id
add_index :majors, :discipline_category_id
end
end

View File

@ -0,0 +1,16 @@
class MigrateMajor < ActiveRecord::Migration
def up
count = Major.all.count / 30 + 2
transaction do
for i in 1 .. count do
Major.page(i).per(30).each do |major|
dis = major.first_level_discipline.discipline_category
major.update_attributes(:discipline_category_id => dis.id, :major_level => dis.major_level) if dis
end
end
end
end
def down
end
end

View File

@ -0,0 +1,7 @@
class CreateCourseLists < ActiveRecord::Migration
def change
create_table :course_lists do |t|
t.string :name
end
end
end

View File

@ -0,0 +1,11 @@
class CreateMajorCourses < ActiveRecord::Migration
def change
create_table :major_courses do |t|
t.references :course_list
t.references :major
end
add_index :major_courses, :course_list_id
add_index :major_courses, :major_id
end
end

View File

@ -0,0 +1,6 @@
class AddColumnsToShixuns < ActiveRecord::Migration
def change
add_column :shixuns, :trainee, :integer
add_column :shixuns, :major_id, :integer
end
end

View File

@ -0,0 +1,13 @@
class CreateShixunMajorCourses < ActiveRecord::Migration
def change
create_table :shixun_major_courses do |t|
t.references :shixun
t.references :course_list
t.references :major
t.timestamps
end
add_index :shixun_major_courses, :shixun_id
add_index :shixun_major_courses, :major_id
end
end

View File

@ -945,3 +945,63 @@ function submit_send_res_to_course(){
$("#search_course_notice_h").html("请先选择一个班级").show(); $("#search_course_notice_h").html("请先选择一个班级").show();
} }
} }
//验证实训名称
function regex_shixun_name()
{
var name = $.trim($("#shixun_name").val());
if(name.length == 0)
{
$("#project_name_notice").show();
return false;
}
else
{
$("#project_name_notice").hide();
return true;
}
}
function regex_major()
{
if($("#shixun_major").val() == "0")
{
$("#shixun_major_notice").show();
return false;
}
else
{
$("#shixun_major_notice").hide();
return true;
}
}
function regex_major_course()
{
if($("input[name='course_id[]']:checked").length == 0){
$("#shixun_major_course_notice").html("请先选择适用的课程").show();
return false;
} else{
$("#shixun_major_course_notice").hide();
return true;
}
}
function checkLesson(item){
if($("#shixun_major").val() == "0") {
$("#shixun_major_course_notice").html("请先选择适用专业").show();
} else{
var showul=$(item).find("ul").attr("showul");
if(showul=="0"){
$(item).find("ul").show();
$(item).find("ul").attr("showul","1");
if($(item).find("ul input").length>5){
$(item).find("ul").css("overflow-y","scroll");
}
event.stopPropagation();
}else{
$(item).find("ul").hide();
$(item).find("ul").attr("showul","0");
event.stopPropagation();
}
}
}

View File

@ -71,7 +71,7 @@ a:hover.link-color-grey03{color:#3498db!important;}
/*通用内外边距*/ /*通用内外边距*/
.mt-10{ margin-top:-10px;}.mt3{ margin-top:3px;}.mt5{ margin-top:5px;}.mt6{ margin-top:6px;}.mt7{ margin-top:7px;}.mt8{ margin-top:8px;}.mt10{ margin-top:10px;}.mt12{ margin-top:12px;}.mt15{ margin-top:15px;}.mt20{ margin-top:20px;}.mt25{ margin-top:25px;}.mt30{ margin-top:30px;}.mt50{ margin-top:50px;} .mt-10{ margin-top:-10px;}.mt3{ margin-top:3px;}.mt5{ margin-top:5px;}.mt6{ margin-top:6px;}.mt7{ margin-top:7px;}.mt8{ margin-top:8px;}.mt10{ margin-top:10px;}.mt12{ margin-top:12px;}.mt15{ margin-top:15px;}.mt20{ margin-top:20px;}.mt25{ margin-top:25px;}.mt30{ margin-top:30px;}.mt50{ margin-top:50px;}
.mb5{ margin-bottom: 5px;}.mb10{ margin-bottom: 10px;}.mb15{ margin-bottom: 15px;}.mb20{ margin-bottom: 20px;}.mb25{ margin-bottom: 25px;}.mb30{ margin-bottom: 30px;}.mb50{ margin-bottom: 50px;} .mb5{ margin-bottom: 5px;}.mb10{ margin-bottom: 10px;}.mb15{ margin-bottom: 15px;}.mb20{ margin-bottom: 20px;}.mb25{ margin-bottom: 25px;}.mb30{ margin-bottom: 30px;}.mb50{ margin-bottom: 50px;}
.ml-3{ margin-left: -3px;}.ml5{ margin-left: 5px;}.ml6{ margin-left: 6px;}.ml10{ margin-left: 10px;}.ml15{ margin-left: 15px;}.ml20{ margin-left: 20px;}.ml25{ margin-left: 25px;}.ml30{ margin-left: 30px;}.ml35{ margin-left:35px;}.ml40{margin-left:40px;}.ml50{ margin-left: 50px;}.ml75{ margin-left: 75px;}.ml115{margin-left: 115px}.ml230{ margin-left: 230px;} .ml-3{ margin-left: -3px;}.ml5{ margin-left: 5px;}.ml6{ margin-left: 6px;}.ml10{ margin-left: 10px;}.ml15{ margin-left: 15px;}.ml20{ margin-left: 20px;}.ml25{ margin-left: 25px;}.ml30{ margin-left: 30px;}.ml35{ margin-left:35px;}.ml40{margin-left:40px;}.ml50{ margin-left: 50px;}.ml75{ margin-left: 75px;}.ml95{ margin-left: 95px;}.ml115{margin-left: 115px}.ml230{ margin-left: 230px;}
.mr5{ margin-right: 5px;}.mr10{ margin-right: 10px;}.mr15{ margin-right: 15px;}.mr18{ margin-right: 18px;}.mr20{ margin-right: 20px;}.mr25{ margin-right: 25px;}.mr30{ margin-right:30px;}.mr50{ margin-right: 50px;}.mr60{ margin-right:60px;} .mr5{ margin-right: 5px;}.mr10{ margin-right: 10px;}.mr15{ margin-right: 15px;}.mr18{ margin-right: 18px;}.mr20{ margin-right: 20px;}.mr25{ margin-right: 25px;}.mr30{ margin-right:30px;}.mr50{ margin-right: 50px;}.mr60{ margin-right:60px;}
.pt5{ padding-top:5px;}.pt10{ padding-top:10px;}.pt15{ padding-top:15px;}.pt20{ padding-top:20px;} .pt5{ padding-top:5px;}.pt10{ padding-top:10px;}.pt15{ padding-top:15px;}.pt20{ padding-top:20px;}
.pb5{ padding-bottom:5px;}.pb10{ padding-bottom:10px;}.pb15{ padding-bottom:15px;}.pb20{ padding-bottom:20px;} .pb5{ padding-bottom:5px;}.pb10{ padding-bottom:10px;}.pb15{ padding-bottom:15px;}.pb20{ padding-bottom:20px;}

View File

@ -279,3 +279,11 @@ a.shixun-task-ban-btn{background-color: #c2c4c6;display: inline-block;font-weigh
.task-width33{ width:33.3%;} .task-width33{ width:33.3%;}
.read_only{ -moz-user-select: none; -webkit-user-select: none; } .read_only{ -moz-user-select: none; -webkit-user-select: none; }
.task-form-28{width: 28%;padding:0px 10px}
.lesson{border:1px solid #EEEEEE;line-height:40px;}
.lesson_img{position: absolute;right: 5px;top:10px;}
.lesson_checkbox{display: none;position: absolute;top:40px;left: -1px;width: 100%;border:1px solid #eeeeee;background: #FFFFFF;padding-bottom: 5px;height: 150px;}
.lesson_checkbox li{height:20px;padding:5px 10px;clear:both;line-height:28px;margin-bottom: 0;}
.lesson_checkbox li input{float: left;margin: 3px 5px 0px 0px;}
.lesson_content{height: 100%;border:none !important;width:96%;outline: none;padding-left: 0;}

View File

@ -0,0 +1,6 @@
FactoryGirl.define do
factory :course_list do
name "MyString"
end
end

View File

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :major_course do
course_list nil
major nil
end
end

10
spec/factories/majors.rb Normal file
View File

@ -0,0 +1,10 @@
FactoryGirl.define do
factory :major do
major_code "MyString"
name "MyString"
first_level_discipline nil
discipline_category nil
major_level 1
end
end

View File

@ -0,0 +1,8 @@
FactoryGirl.define do
factory :shixun_major_course do
shixun nil
course_list ""
major nil
end
end

View File

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

View File

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

View File

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

View File

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