实训作业

This commit is contained in:
huang 2017-05-22 21:31:28 +08:00
parent 65e85e7bdc
commit c9593f7d17
8 changed files with 81 additions and 41 deletions

View File

@ -75,13 +75,16 @@ class HomeworkCommonController < ApplicationController
# 新建实训作业
def shixuns
@shixus = Shixun.where(:authentication => 1)
@shixus_count = shixuns.count
@limit = 2
search = params[:search]
@course = Course.find(params[:course])
@homework = HomeworkCommon.new
@shixuns = Shixun.where(:authentication => 1).where("name like ?", "%#{search}%")
@shixuns_count = @shixuns.count
@limit = 10
@is_remote = true
@shixun_pages = Paginator.new @shixus_count, @limit, params['page'] || 1
@shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
@offset ||= @shixun_pages.offset
@shixus = paginateHelper @shixus, @limit
@shixuns = paginateHelper @shixuns, @limit
respond_to do |format|
format.js
end
@ -89,20 +92,26 @@ class HomeworkCommonController < ApplicationController
#新建作业,在个人作业列表创建作业
def create
if params[:homework_common]
if params[:homework_common] || params[:shixun_homework]
homework = HomeworkCommon.new
homework.name = params[:homework_common][:name]
homework.description = params[:homework_common][:description]
if params[:shixun_homework]
shixun = Shixun.find(params[:shixun_homework])
homework.name = shixun.name
homework.description = shixun.description
else
homework.name = params[:homework_common][:name]
homework.description = params[:homework_common][:description]
homework.reference_answer = params[:homework_common][:reference_answer]
homework.save_attachments(params[:attachments])
render_attachment_warning_if_needed(homework)
end
homework.anonymous_comment = 1
homework.homework_type = params[:homework_type].to_i || 1
homework.homework_type = params[:shixun_homework] ? 4 : (params[:homework_type].to_i || 1)
homework.late_penalty = 0
homework.teacher_priority = 1
homework.user_id = User.current.id
homework.course_id = params[:course]
homework.reference_answer = params[:homework_common][:reference_answer]
homework.save_attachments(params[:attachments])
render_attachment_warning_if_needed(homework)
homework_detail_manual = HomeworkDetailManual.new
homework_detail_manual.te_proportion = 1.0
@ -155,7 +164,7 @@ class HomeworkCommonController < ApplicationController
homework_detail_programing.save if homework_detail_programing
homework_detail_group.save if homework_detail_group
if homework.homework_type != 3 && homework_detail_manual.comment_status == 1
if homework.homework_type != 4 && homework_detail_manual.comment_status == 1
create_works_list homework
end

View File

@ -24,6 +24,7 @@ class HomeworkCommon < ActiveRecord::Base
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动
has_and_belongs_to_many :shixuns
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
# 课程消息

View File

@ -0,0 +1,3 @@
class HomeworkCommonsShixuns < ActiveRecord::Base
attr_accessible :homework_common_id, :shixun_id
end

View File

@ -7,6 +7,7 @@ class Shixun < ActiveRecord::Base
has_one :repository
has_many :challenges, :dependent => :destroy, :order => "challenges.id ASC"
has_many :myshixuns
has_and_belongs_to_many :homework_commons
# id 转换成 identifier
def to_param

View File

@ -4,41 +4,46 @@
<a href="#" class="pop_close"><i class="fa fa-times-circle font-18 link-color-grey fr mt5"></i></a>
</div>
<div class="task_popup_con ">
<div class=" clearfix mb10">
<div class="task-form-50 edu-position fr " style="padding:0;">
<input class="task-form-100 panel-box-sizing " placeholder="输入实训名称的关键字搜索" type="text">
<a href="javascript:void(0);" class="edu-btn-search font-16 color-grey mt10"><i class="fa fa-search"></i></a>
</div>
</div>
<table class="edu-pop-table color-grey edu-txt-center table-pa5" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th>实训名称</th>
<th>导师姓名</th>
<th>学员数</th>
</tr>
</thead>
<tbody>
<% @shixus.each do |shixun| %>
<%= labelled_form_for @homework, :url =>{:controller=> 'homework_common', :action => 'shixuns', :course => @course.id}, :method => "post", :remote => true do |f| %>
<div class=" clearfix mb10">
<div class="task-form-50 edu-position fr" style="padding:0;">
<input class="task-form-100 panel-box-sizing" placeholder="输入实训名称的关键字搜索" type="text" name="search">
<a href="javascript:void(0);" class="edu-btn-search font-16 color-grey mt10"><i class="fa fa-search"></i></a>
</div>
</div>
<% end %>
<%= labelled_form_for @homework, :url =>{:controller=> 'homework_common', :action => 'create', :course => @course.id}, :method => "post" do |f| %>
<table class="edu-pop-table color-grey edu-txt-center table-pa5" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td class="clearfix">
<input type="radio" class="mr5 fl mt15">
<%= link_to shixun.name, shixun_path(shixun), :class => "edu-info-dark task-hide fl" %>
</td>
<td><%= link_to shixun.owner.try(:show_name), user_path(shixun.owner), :class => "edu-txt-w140 task-hide" %></td>
<td><%= shixun.myshixuns.count %></td>
<th>实训名称</th>
<th>导师姓名</th>
<th>学员数</th>
</tr>
<% end %>
</tbody>
</table>
</thead>
<span id="homework_type_notice" class="c_red none">请至少选中一个实训</span>
<tbody>
<% @shixuns.each do |shixun| %>
<tr>
<td class="clearfix">
<input name="shixun_homework" type="radio" class="mr5 fl mt15" value="<%= shixun.id %>">
<%= link_to shixun.name, shixun_path(shixun), :class => "edu-info-dark task-hide fl" %>
</td>
<td><%= link_to shixun.owner.try(:show_name), user_path(shixun.owner), :class => "edu-txt-w140 task-hide" %></td>
<td><%= shixun.myshixuns.count %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<div class="clearfix">
<div class="clearfix fl mt10">
<a href="#" class="task-btn fr pop_close">取消</a>
<a href="#" class=" task-btn task-btn-blue fr mr10">选择</a>
<a href="javascript:void(0);" class=" task-btn task-btn-blue fr mr10" onclick="new_shixun_homework();">选择</a>
</div>
<div class="fr pages_right_min">
<ul>
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %>
<%= pagination_links_full @shixun_pages, @shixuns_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %>
</ul>
<div class="cl"></div>
</div>

View File

@ -409,7 +409,7 @@ RedmineApp::Application.routes.draw do
end
collection do
get 'shixuns'
match 'shixuns'
post 'next_step'
post 'programing_test'
end

View File

@ -0,0 +1,10 @@
class CreateHomeworkCommonsShixuns < ActiveRecord::Migration
def change
create_table :homework_commons_shixuns do |t|
t.integer :shixun_id
t.integer :homework_common_id
t.timestamps
end
end
end

View File

@ -63,3 +63,14 @@ function new_homework_type(id){
}
}
}
function new_shixun_homework(id){
if($("input[name='shixun_homework']:checked").length == 0){
$("#homework_type_notice").show();
} else{
var type=$("input[name='shixun_homework']:checked").val();
console.log(type);
$("#new_homework_common").submit();
}
}